Linux-unix Advanced Programming (third edition) source code compilation (that is, header file apue.h How to use the problem) "Go"

Source: Internet
Author: User

This article was reproduced from: http://blog.csdn.net/hadas_wang/article/details/43203795

1. Download code:http://www.apuebook.com/code3e.html

2. Install dependent libraries:sudo apt-get install Libbsd-dev

3. Go to the download directory make

4. Copying header files and dynamic link libraries

[Plain]View Plaincopy
    1. sudo cp./include/apue.h/usr/include/
    2. sudo cp./lib/libapue.a/usr/local/lib/
    3. sudo cp./lib/libapue.a/usr/lib/

5. Setting the error file Error.h

[CPP]View Plaincopy
  1. #include "apue.h"
  2. #include <errno.h> * for definition of errno */
  3. #include <stdarg.h>/* ISO C variable aruments */
  4. static void Err_doit (int, int, const char *, va_list);
  5. /*
  6. * Nonfatal error related to a system call.
  7. * Print a message and return.
  8. */
  9. void Err_ret (const char *fmt, ...)
  10. {
  11. va_list ap;
  12. Va_start (AP, FMT);
  13. Err_doit (1, errno, FMT, AP);
  14. Va_end (AP);
  15. }
  16. /*
  17. * Fatal error related to a system call.
  18. * Print a message and terminate.
  19. */
  20. void Err_sys (const char *fmt, ...)
  21. {
  22. va_list ap;
  23. Va_start (AP, FMT);
  24. Err_doit (1, errno, FMT, AP);
  25. Va_end (AP);
  26. Exit (1);
  27. }
  28. /*
  29. * Fatal error unrelated to a system call.
  30. * Error code passed as explict parameter.
  31. * Print a message and terminate.
  32. */
  33. void Err_exit (int error, const char *fmt, ...)
  34. {
  35. va_list ap;
  36. Va_start (AP, FMT);
  37. Err_doit (1, error, FMT, AP);
  38. Va_end (AP);
  39. Exit (1);
  40. }
  41. /*
  42. * Fatal error related to a system call.
  43. * Print a message, dump core, and terminate.
  44. */
  45. void Err_dump (const char *fmt, ...)
  46. {
  47. va_list ap;
  48. Va_start (AP, FMT);
  49. Err_doit (1, errno, FMT, AP);
  50. Va_end (AP);
  51. Abort (); / * Dump core and Terminate * /
  52. Exit (1); / * shouldn ' t get here * /
  53. }
  54. /*
  55. * Nonfatal error unrelated to a system call.
  56. * Print a message and return.
  57. */
  58. void Err_msg (const char *fmt, ...)
  59. {
  60. va_list ap;
  61. Va_start (AP, FMT);
  62. Err_doit (0, 0, FMT, AP);
  63. Va_end (AP);
  64. }
  65. /*
  66. * Fatal error unrelated to a system call.
  67. * Print a message and terminate.
  68. */
  69. void Err_quit (const char *fmt, ...)
  70. {
  71. va_list ap;
  72. Va_start (AP, FMT);
  73. Err_doit (0, 0, FMT, AP);
  74. Va_end (AP);
  75. Exit (1);
  76. }
  77. /*
  78. * Print a message and return to caller.
  79. * Caller Specifies "Errnoflag".
  80. */
  81. static void Err_doit (int errnoflag, int error, const char *fmt, va_list ap) /c2>
  82. {
  83. Char Buf[maxline];
  84. vsnprintf (buf, MAXLINE, FMT, AP);
  85. if (errnoflag)
  86. snprintf (Buf+strlen (BUF), Maxline-strlen (BUF), ":%s",
  87. Strerror (Error));
  88. strcat (buf, "\ n");
  89. Fflush (stdout); /* In case stdout and stderr is the same * /
  90. Fputs (buf, stderr);
  91. Fflush (NULL); / * Flushes all stdio output streams * /
  92. }


6. Logout, restart

7. Code files

[CPP]View Plaincopy
      1. #include "apue.h"
      2. #include "Error.h"

Linux-unix Advanced Programming (third edition) source code compilation (that is, header file apue.h How to use the problem) "Go"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.