-
Notifications
You must be signed in to change notification settings - Fork 0
/
ez_libc.h
666 lines (600 loc) · 15.9 KB
/
ez_libc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
/***************************************************************************
* Copyright (C) 2018 by John D. Robertson *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
/***************************************************************************
ez_libc.h - description
glibc calls with boilerplate error handling.
-------------------
begin : Tue Nov 13 19:42:23 EST 2018
email : [email protected]
***************************************************************************/
#ifndef EZ_LIBC_H
#define EZ_LIBC_H
#ifndef _GNU_SOURCE
# define _GNU_SOURCE
#endif
#include <dirent.h>
#ifdef __MINGW32__
# include <winsock2.h>
#else
# include <grp.h>
# include <netdb.h>
# include <sys/socket.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include "ez.h"
#ifdef __cplusplus
extern "C" {
#endif
ez_proto (int, access,
const char *pathname,
int mode);
#ifdef DEBUG
# define ez_access(...) \
_ez_access(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_access(...) \
_ez_access(__VA_ARGS__)
#endif
ez_proto (int, atexit,
void(*function)(void));
#ifdef DEBUG
# define ez_atexit(...) \
_ez_atexit(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_atexit(...) \
_ez_atexit(__VA_ARGS__)
#endif
ez_proto (int, chdir,
const char *path);
#ifdef DEBUG
# define ez_chdir(...) \
_ez_chdir(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_chdir(...) \
_ez_chdir(__VA_ARGS__)
#endif
#ifndef __MINGW32__
ez_proto (int, chown,
const char *pathname,
uid_t owner,
gid_t group);
#ifdef DEBUG
# define ez_chown(...) \
_ez_chown(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_chown(...) \
_ez_chown(__VA_ARGS__)
#endif
#endif // __MINGW32__
ez_proto (int, close,
int fd);
#ifdef DEBUG
# define ez_close(...) \
_ez_close(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_close(...) \
_ez_close(__VA_ARGS__)
#endif
ez_proto (int, closedir,
DIR *dirp);
#ifdef DEBUG
# define ez_closedir(...) \
_ez_closedir(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_closedir(...) \
_ez_closedir(__VA_ARGS__)
#endif
ez_proto (int, dup2, int oldfd, int newfd);
#ifdef DEBUG
# define ez_dup2(...) \
_ez_dup2(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_dup2(...) \
_ez_dup2(__VA_ARGS__)
#endif
ez_proto (int, execve,
const char *filename,
char *const argv[],
char *const envp[]);
#ifdef DEBUG
# define ez_execve(...) \
_ez_execve(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_execve(...) \
_ez_execve(__VA_ARGS__)
#endif
ez_proto (int, fchmod,
int fd,
mode_t mode);
#ifdef DEBUG
# define ez_fchmod(...) \
_ez_fchmod(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_fchmod(...) \
_ez_fchmod(__VA_ARGS__)
#endif
#ifndef __MINGW32__
ez_proto (int, fchown,
int fd,
uid_t owner,
gid_t group);
#ifdef DEBUG
# define ez_fchown(...) \
_ez_fchown(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_fchown(...) \
_ez_fchown(__VA_ARGS__)
#endif
#endif // __MINGW32__
ez_proto (int, fclose,
FILE *stream);
#ifdef DEBUG
# define ez_fclose(...) \
_ez_fclose(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_fclose(...) \
_ez_fclose(__VA_ARGS__)
#endif
ez_proto (int, fflush,
FILE *stream);
#ifdef DEBUG
# define ez_fflush(...) \
_ez_fflush(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_fflush(...) \
_ez_fflush(__VA_ARGS__)
#endif
ez_proto (int, fgetc, FILE *stream);
#ifdef DEBUG
# define ez_fgetc(...) \
_ez_fgetc(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_fgetc(...) \
_ez_fgetc(__VA_ARGS__)
#endif
ez_proto (char*, fgets,
char *s,
int size,
FILE *stream);
#ifdef DEBUG
# define ez_fgets(...) \
_ez_fgets(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_fgets(...) \
_ez_fgets(__VA_ARGS__)
#endif
ez_proto (FILE*, fdopen,
int fd,
const char *mode);
#ifdef DEBUG
# define ez_fdopen(...) \
_ez_fdopen(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_fdopen(...) \
_ez_fdopen(__VA_ARGS__)
#endif
ez_proto (int, flock,
int fd,
int operation);
#ifdef DEBUG
# define ez_flock(...) \
_ez_flock(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_flock(...) \
_ez_flock(__VA_ARGS__)
#endif
ez_proto (FILE*, fopen,
const char *pathname,
const char *mode);
#ifdef DEBUG
# define ez_fopen(...) \
_ez_fopen(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_fopen(...) \
_ez_fopen(__VA_ARGS__)
#endif
#ifndef __MINGW32__
ez_proto (pid_t, fork);
#ifdef DEBUG
# define ez_fork(...) \
_ez_fork(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_fork(...) \
_ez_fork(__VA_ARGS__)
#endif
#endif // __MINGW32__
ez_proto (int, fprintf,
FILE *stream,
const char *fmt,
...);
#ifdef DEBUG
# define ez_fprintf(...) \
_ez_fprintf(__FILE__, __LINE__, __func__, __VA_ARGS__)
#else
# define ez_fprintf(...) \
_ez_fprintf(__VA_ARGS__)
#endif
ez_proto (int, fputc,
int c,
FILE *stream);
#ifdef DEBUG
# define ez_fputc(...) \
_ez_fputc(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_fputc(...) \
_ez_fputc(__VA_ARGS__)
#endif
ez_proto (int, fputs,
const char *s,
FILE *stream);
#ifdef DEBUG
# define ez_fputs(...) \
_ez_fputs(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_fputs(...) \
_ez_fputs(__VA_ARGS__)
#endif
ez_proto (size_t, fread,
void *ptr,
size_t size,
size_t nmemb,
FILE *stream);
#ifdef DEBUG
# define ez_fread(...) \
_ez_fread(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_fread(...) \
_ez_fread(__VA_ARGS__)
#endif
ez_proto (size_t, fscanf,
FILE *stream,
const char *format,
...);
#ifdef DEBUG
# define ez_fscanf(...) \
_ez_fscanf(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_fscanf(...) \
_ez_fscanf(__VA_ARGS__)
#endif
ez_proto (int, fstat,
int fd,
struct stat *statbuf);
#ifdef DEBUG
# define ez_fstat(...) \
_ez_fstat(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_fstat(...) \
_ez_fstat(__VA_ARGS__)
#endif
ez_proto (size_t, fwrite,
const void *ptr,
size_t size,
size_t nmemb,
FILE *stream);
#ifdef DEBUG
# define ez_fwrite(...) \
_ez_fwrite(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_fwrite(...) \
_ez_fwrite(__VA_ARGS__)
#endif
#ifndef __MINGW32__
ez_proto (int, getaddrinfo,
const char *node,
const char *service,
const struct addrinfo *hints,
struct addrinfo **res);
#ifdef DEBUG
# define ez_getaddrinfo(...) \
_ez_getaddrinfo(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_getaddrinfo(...) \
_ez_getaddrinfo(__VA_ARGS__)
#endif
ez_proto (int, getnameinfo,
const struct sockaddr *addr,
socklen_t addrlen,
char *host,
socklen_t hostlen,
char *serv,
socklen_t servlen,
int flags);
#ifdef DEBUG
# define ez_getnameinfo(...) \
_ez_getnameinfo(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_getnameinfo(...) \
_ez_getnameinfo(__VA_ARGS__)
#endif
#endif // __MINGW32__
ez_proto (char*, getcwd,
char *buf,
size_t size);
#ifdef DEBUG
# define ez_getcwd(...) \
_ez_getcwd(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_getcwd(...) \
_ez_getcwd(__VA_ARGS__)
#endif
ez_proto (struct group*, getgrnam,
const char *name);
#ifdef DEBUG
# define ez_getgrnam(...) \
_ez_getgrnam(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_getgrnam(...) \
_ez_getgrnam(__VA_ARGS__)
#endif
ez_proto (void*, malloc, size_t size);
#ifdef DEBUG
# define ez_malloc(...) \
_ez_malloc(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_malloc(...) \
_ez_malloc(__VA_ARGS__)
#endif
ez_proto (int, mkdir,
const char *pathname,
mode_t mode);
#ifdef DEBUG
# define ez_mkdir(...) \
_ez_mkdir(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_mkdir(...) \
_ez_mkdir(__VA_ARGS__)
#endif
ez_proto (int, mkstemp,
char *tmpl);
#ifdef DEBUG
# define ez_mkstemp(...) \
_ez_mkstemp(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_mkstemp(...) \
_ez_mkstemp(__VA_ARGS__)
#endif
ez_proto (int, mkstemps, char *tmpl, int suffixlen);
#ifdef DEBUG
# define ez_mkstemps(...) \
_ez_mkstemps(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_mkstemps(...) \
_ez_mkstemps(__VA_ARGS__)
#endif
ez_proto (int, open,
const char *pathname,
int flags,
mode_t mode);
#ifdef DEBUG
# define ez_open(...) \
_ez_open(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_open(...) \
_ez_open(__VA_ARGS__)
#endif
ez_proto (DIR*, opendir,
const char *name);
#ifdef DEBUG
# define ez_opendir(...) \
_ez_opendir(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_opendir(...) \
_ez_opendir(__VA_ARGS__)
#endif
ez_proto (int, pclose,
FILE *stream);
#ifdef DEBUG
# define ez_pclose(...) \
_ez_pclose(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_pclose(...) \
_ez_pclose(__VA_ARGS__)
#endif
ez_proto (int, pipe, int pipefd[2]);
#ifdef DEBUG
# define ez_pipe(...) \
_ez_pipe(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_pipe(...) \
_ez_pipe(__VA_ARGS__)
#endif
ez_proto (FILE*, popen,
const char *command,
const char *type);
#ifdef DEBUG
# define ez_popen(...) \
_ez_popen(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_popen(...) \
_ez_popen(__VA_ARGS__)
#endif
ez_proto (struct dirent*, readdir,
DIR *dirp);
#ifdef DEBUG
# define ez_readdir(...) \
_ez_readdir(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_readdir(...) \
_ez_readdir(__VA_ARGS__)
#endif
ez_proto (int, remove,
const char *pathname);
#ifdef DEBUG
# define ez_remove(...) \
_ez_remove(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_remove(...) \
_ez_remove(__VA_ARGS__)
#endif
ez_proto (int, rename,
const char *oldpath,
const char *newpath);
#ifdef DEBUG
# define ez_rename(...) \
_ez_rename(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_rename(...) \
_ez_rename(__VA_ARGS__)
#endif
ez_proto (int, rmdir,
const char *pathname);
#ifdef DEBUG
# define ez_rmdir(...) \
_ez_rmdir(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_rmdir(...) \
_ez_rmdir(__VA_ARGS__)
#endif
#ifndef __MINGW32__
ez_proto (int, setegid,
gid_t egid);
#ifdef DEBUG
# define ez_setegid(...) \
_ez_setegid(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_setegid(...) \
_ez_setegid(__VA_ARGS__)
#endif
ez_proto (int, seteuid,
uid_t euid);
#ifdef DEBUG
# define ez_seteuid(...) \
_ez_seteuid(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_seteuid(...) \
_ez_seteuid(__VA_ARGS__)
#endif
ez_proto (int, setgid,
gid_t gid);
#ifdef DEBUG
# define ez_setgid(...) \
_ez_setgid(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_setgid(...) \
_ez_setgid(__VA_ARGS__)
#endif
ez_proto (int, setuid,
uid_t uid);
#ifdef DEBUG
# define ez_setuid(...) \
_ez_setuid(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_setuid(...) \
_ez_setuid(__VA_ARGS__)
#endif
#endif // __MINGW32__
ez_proto (int, stat,
const char *pathname,
struct stat *statbuf);
#ifdef DEBUG
# define ez_stat(...) \
_ez_stat(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_stat(...) \
_ez_stat(__VA_ARGS__)
#endif
ez_proto (char*, strptime,
const char *s,
const char *format,
struct tm *tm);
#ifdef DEBUG
# define ez_strptime(...) \
_ez_strptime(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_strptime(...) \
_ez_strptime(__VA_ARGS__)
#endif
ez_proto (int, unlink,
const char *pathname);
#ifdef DEBUG
# define ez_unlink(...) \
_ez_unlink(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_unlink(...) \
_ez_unlink(__VA_ARGS__)
#endif
ez_proto (int, vfprintf,
FILE *stream,
const char *fmt,
va_list ap);
#ifdef DEBUG
# define ez_vfprintf(...) \
_ez_vfprintf(__FILE__, __LINE__, __func__, __VA_ARGS__)
#else
# define ez_vfprintf(...) \
_ez_vfprintf(__VA_ARGS__)
#endif
ez_proto (ssize_t, write,
int fd,
const void *buf,
size_t count);
#ifdef DEBUG
# define ez_write(...) \
_ez_write(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_write(...) \
_ez_write(__VA_ARGS__)
#endif
ez_proto (ssize_t, send,
int fd,
const void *buf,
size_t count,
int flags);
#ifdef DEBUG
# define ez_send(...) \
_ez_send(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_send(...) \
_ez_send(__VA_ARGS__)
#endif
ez_proto (ssize_t, recv,
int fd,
void *buf,
size_t count,
int flags);
#ifdef DEBUG
# define ez_recv(...) \
_ez_recv(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_recv(...) \
_ez_recv(__VA_ARGS__)
#endif
#if 0
// FIXME: this needs to be implemented and tested
ez_proto (ssize_t read,
int fd,
void *buf,
size_t count);
#ifdef DEBUG
# define ez_read(...) \
_ez_read(__FILE__, __LINE__, __func__, ##__VA_ARGS__)
#else
# define ez_read(...) \
_ez_read(__VA_ARGS__)
#endif
#endif
#ifdef __cplusplus
}
#endif
#endif