00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "defs.h"
00022 #include <netdb.h>
00023 #include <errno.h>
00024
00025 static bool fcn(void)
00026 {
00027 char buf[100], filein[20], fileout[20];
00028
00029 char *p = NULL;
00030 int fdin = -1, fdout = -1;
00031
00032 ec_null( p = malloc(sizeof(buf)) )
00033 ec_neg1( fdin = open(filein, O_RDONLY) )
00034 ec_neg1( fdout = open(fileout, O_WRONLY) )
00035
00036 return true;
00037
00038 EC_CLEANUP_BGN
00039 free(p);
00040 if (fdin != -1)
00041 (void)close(fdin);
00042 if (fdout != -1)
00043 (void)close(fdout);
00044 return false;
00045 EC_CLEANUP_END
00046
00047 }
00048
00049 int main(void)
00050 {
00051
00052 {
00053 int amt, fd = -1, numbyte = 10, r;
00054 char buf[100], filein[20], fileout[20];
00055 char *p = NULL;
00056 int fdin = -1, fdout = -1;
00057
00058
00059 if ((amt = read(fd, buf, numbyte)) == -1) {
00060 fprintf(stderr, "%s\n", syserrmsg(buf, sizeof(buf),
00061 "Call to read function failed", errno));
00062 exit(EXIT_FAILURE);
00063 }
00064
00065
00066 ec_false( fcn() )
00067
00068
00069
00070 exit(EXIT_SUCCESS);
00071
00072 EC_CLEANUP_BGN
00073 exit(EXIT_FAILURE);
00074 EC_CLEANUP_END
00075
00076 {
00077
00078 char *p = NULL;
00079 int fdin = -1, fdout = -1;
00080
00081 if ((p = malloc(sizeof(buf))) == NULL) {
00082 fprintf(stderr, "%s\n", syserrmsg(buf, sizeof(buf),
00083 "malloc failed", errno));
00084 goto cleanup;
00085 }
00086 if ((fdin = open(filein, O_RDONLY)) == -1) {
00087 fprintf(stderr, "%s\n", syserrmsg(buf, sizeof(buf),
00088 "open (input) failed", errno));
00089 goto cleanup;
00090 }
00091 if ((fdout = open(fileout, O_WRONLY)) == -1) {
00092 fprintf(stderr, "%s\n", syserrmsg(buf, sizeof(buf),
00093 "open (output) failed", errno));
00094 goto cleanup;
00095 }
00096 return true;
00097
00098 cleanup:
00099 free(p);
00100 if (fdin != -1)
00101 (void)close(fdin);
00102 if (fdout != -1)
00103 (void)close(fdout);
00104 return false;
00105
00106 }
00107 if ((p = malloc(sizeof(buf))) == NULL) {
00108 fprintf(stderr, "%s\n", syserrmsg(buf, sizeof(buf),
00109 "malloc failed", errno));
00110 return false;
00111 }
00112 if ((fdin = open(filein, O_RDONLY)) == -1) {
00113 fprintf(stderr, "%s\n", syserrmsg(buf, sizeof(buf),
00114 "open (input) failed", errno));
00115 free(p);
00116 return false;
00117 }
00118 if ((fdout = open(fileout, O_WRONLY)) == -1) {
00119 fprintf(stderr, "%s\n", syserrmsg(buf, sizeof(buf),
00120 "open (output) failed", errno));
00121 (void)close(fdin);
00122 free(p);
00123 return false;
00124 }
00125
00126 {
00127
00128 struct addrinfo *infop;
00129
00130 if ((r = getaddrinfo("localhost", "80", NULL, &infop)) != 0) {
00131 fprintf(stderr, "Got error code %d from getaddrinfo\n", r);
00132 exit(EXIT_FAILURE);
00133 }
00134
00135 }
00136 amt = read(fd, buf, numbyte);
00137 if (errno != 0) {
00138 fprintf(stderr, "Read failed! errno = %d\n", errno);
00139 exit(EXIT_FAILURE);
00140 }
00141
00142
00143 errno = 0;
00144 amt = read(fd, buf, numbyte);
00145 if (errno != 0) {
00146 fprintf(stderr, "Read failed! errno = %d\n", errno);
00147 exit(EXIT_FAILURE);
00148 }
00149
00150
00151 if ((amt = read(fd, buf, numbyte)) == -1) {
00152 fprintf(stderr, "Read failed!: %s (errno = %d; %s)\n",
00153 strerror(errno), errno, errsymbol(errno));
00154 exit(EXIT_FAILURE);
00155 }
00156
00157
00158 if ((amt = read(fd, buf, numbyte)) == -1) {
00159 perror("Read failed!");
00160 exit(EXIT_FAILURE);
00161 }
00162
00163 #if 0
00164
00165 #include <errno.h>
00166
00167 if ((amt = read(fd, buf, numbyte)) == -1) {
00168 fprintf(stderr, "Read failed! errno = %d\n", errno);
00169 exit(EXIT_FAILURE);
00170 }
00171
00172 #endif
00173
00174 if ((amt = read(fd, buf, numbyte)) == -1) {
00175 fprintf(stderr, "Read failed!\n");
00176 exit(EXIT_FAILURE);
00177 }
00178
00179 }
00180 exit(EXIT_SUCCESS);
00181
00182 }