d48abbeeb1b2ca13e7387cfbd568fc44d5ef0add
1 /* @(#)schily.h 1.122 16/12/18 Copyright 1985-2016 J. Schilling */
3 * Definitions for libschily
5 * This file should be included past:
7 * schily/mconfig.h / config.h
10 * stdlib.h (better use schily/stdlib.h)
11 * unistd.h (better use schily/unistd.h) needed f. LARGEFILE support
15 * If you need stdio.h, you must include it before schily/schily.h
17 * NOTE: If you need ctype.h and did not include stdio.h you need to
18 * include ctype.h past schily/schily.h as OpenBSD does not follow POSIX
19 * and defines EOF in ctype.h
21 * Copyright (c) 1985-2016 J. Schilling
24 * The contents of this file are subject to the terms of the
25 * Common Development and Distribution License, Version 1.0 only
26 * (the "License"). You may not use this file except in compliance
29 * See the file CDDL.Schily.txt in this distribution for details.
30 * A copy of the CDDL is also available via the Internet at
31 * http://www.opensource.org/licenses/cddl1.txt
33 * When distributing Covered Code, include this CDDL HEADER in each
34 * file and include the License file CDDL.Schily.txt from this distribution.
37 #ifndef _SCHILY_SCHILY_H
38 #define _SCHILY_SCHILY_H
40 #ifndef _SCHILY_MCONFIG_H
41 #include <schily/mconfig.h>
44 #ifndef _SCHILY_STANDARD_H
45 #include <schily/standard.h>
47 #ifndef _SCHILY_CCOMDEFS_H
48 #include <schily/ccomdefs.h>
55 #if defined(_INCL_SYS_TYPES_H) || defined(_INCL_TYPES_H) || defined(off_t)
60 #if defined(_INCL_SYS_TYPES_H) || defined(_INCL_TYPES_H) || defined(size_t)
65 #if defined(_MSC_VER) && !defined(_SIZE_T_DEFINED)
71 * It turns out that we cannot use the folloginw definition because there are
72 * some platforms that do not behave application friendly. These are mainly
73 * BSD-4.4 based systems (which #undef a definition when size_t is available.
74 * We actually removed this code because of a problem with QNX Neutrino.
75 * For this reason, it is important not to include <sys/types.h> directly but
76 * via the Schily SING include files so we know whether it has been included
77 * before we come here.
79 #if defined(_SIZE_T) || defined(_T_SIZE_) || defined(_T_SIZE) || \
80 defined(__SIZE_T) || defined(_SIZE_T_) || \
81 defined(_GCC_SIZE_T) || defined(_SIZET_) || \
82 defined(__sys_stdtypes_h) || defined(___int_size_t_h) || defined(size_t)
85 # define FOUND_SIZE_T /* We already included a size_t definition */
88 #endif /* __never_def__ */
90 #if defined(HAVE_LARGEFILES)
91 # define _fcons _fcons64
93 # define fileluopen fileluopen64
94 # define fileopen fileopen64
95 # define filemopen filemopen64
96 # define filepos filepos64
97 # define filereopen filereopen64
98 # define fileseek fileseek64
99 # define filesize filesize64
100 # define filestat filestat64
101 # define _openfd _openfd64
105 * The official POSIX rule is not to define "new" interfaces that
106 * are in conflict with older interfaces of the same name.
107 * Our interfaces fexec*() have been defined and published in 1982.
108 * The new POSIX interfaces define a different interface and the
109 * new POSIX interfaces even use names that are not compatible with
110 * POSIX rules. The new POSIX interfaces in question should be called
111 * fdexec*() to follow the rules of other similar POSIX functions.
112 * Simiar problems exist with getline()/fgetline().
114 #if defined(HAVE_RAW_FEXECL) || defined(HAVE_RAW_FEXECLE) || \
115 defined(HAVE_RAW_FEXECV) || defined(HAVE_RAW_FEXECVE)
118 #if defined(HAVE_RAW_FSPAWNV) || defined(HAVE_RAW_FSPAWNL) || \
119 defined(HAVE_RAW_FSPAWNV_NOWAIT)
120 #define RENAME_FSPAWN
122 #if defined(HAVE_RAW_GETLINE) || defined(HAVE_RAW_FGETLINE)
123 #define RENAME_GETLINE
128 #define RENAME_FSPAWN
129 #define RENAME_GETLINE
132 #if defined(RENAME_FEXEC) || defined(RENAME_FSPAWN)
133 #ifndef _SCHILY_UNISTD_H
134 #include <schily/unistd.h> /* Need to incl. before fexec*() protoypes */
138 #if defined(RENAME_GETLINE)
139 #ifndef _SCHILY_STDIO_H
140 #include <schily/stdio.h> /* Need to incl. before *getline() protoypes */
145 #ifdef EOF /* stdio.h has been included */
147 extern int _cvmod
__PR((const char *, int *, int *));
148 extern FILE *_fcons
__PR((FILE *, int, int));
149 extern FILE *fdup
__PR((FILE *));
150 #if !defined(fdown) || defined(PROTOTYPES)
152 * We cannot declare fdown() with K&R in case that fdown() has been #define'd
154 extern int fdown
__PR((FILE *));
156 extern int js_fexecl
__PR((const char *, FILE *, FILE *, FILE *,
158 extern int js_fexecle
__PR((const char *, FILE *, FILE *, FILE *,
160 /* 6th arg not const, fexecv forces av[ac] = NULL */
161 extern int js_fexecv
__PR((const char *, FILE *, FILE *, FILE *, int,
163 extern int js_fexecve
__PR((const char *, FILE *, FILE *, FILE *,
164 char * const *, char * const *));
165 extern int js_fspawnv
__PR((FILE *, FILE *, FILE *, int, char * const *));
166 extern int js_fspawnl
__PR((FILE *, FILE *, FILE *, const char *, ...));
167 extern int js_fspawnv_nowait
__PR((FILE *, FILE *, FILE *,
168 const char *, int, char *const*));
169 extern int js_fgetline
__PR((FILE *, char *, int));
171 extern ssize_t fgetaline
__PR((FILE *, char **, size_t *));
172 extern ssize_t getaline
__PR((char **, size_t *));
174 extern int fgetstr
__PR((FILE *, char *, int));
175 extern int file_getraise
__PR((FILE *));
176 extern void file_raise
__PR((FILE *, int));
177 extern int fileclose
__PR((FILE *));
178 extern FILE *fileluopen
__PR((int, const char *));
179 extern FILE *fileopen
__PR((const char *, const char *));
180 #ifdef _SCHILY_TYPES_H
181 extern FILE *filemopen
__PR((const char *, const char *, mode_t
));
184 extern off_t filepos
__PR((FILE *));
187 extern ssize_t fileread
__PR((FILE *, void *, size_t));
188 extern ssize_t ffileread
__PR((FILE *, void *, size_t));
190 extern FILE *filereopen
__PR((const char *, const char *, FILE *));
192 extern int fileseek
__PR((FILE *, off_t
));
193 extern off_t filesize
__PR((FILE *));
196 extern int filestat
__PR((FILE *, struct stat
*));
199 extern ssize_t filewrite
__PR((FILE *, void *, size_t));
200 extern ssize_t ffilewrite
__PR((FILE *, void *, size_t));
202 extern int flush
__PR((void));
203 extern int fpipe
__PR((FILE **));
205 extern int fprintf
__PR((FILE *, const char *, ...)) __printflike__(2, 3);
207 extern int getbroken
__PR((FILE *, char *, char, char **, int));
208 extern int ofindline
__PR((FILE *, char, const char *, int,
210 extern int peekc
__PR((FILE *));
214 * We cannot define this or we may get into problems with DOS based systems.
216 extern int spawnv
__PR((FILE *, FILE *, FILE *, int, char * const *));
217 extern int spawnl
__PR((FILE *, FILE *, FILE *, const char *, ...));
218 extern int spawnv_nowait
__PR((FILE *, FILE *, FILE *,
219 const char *, int, char *const*));
220 #endif /* __never_def__ */
224 * Flags for absfpath() and resolvefpath():
226 #define RSPF_EXIST 0x01 /* All path components must exist */
227 #define RSPF_NOFOLLOW_LAST 0x02 /* Don't follow link in last pathcomp */
230 extern char *abspath
__PR((const char *relp
, char *absp
, size_t asize
));
231 extern char *absnpath
__PR((const char *relp
, char *absp
, size_t asize
));
232 extern char *absfpath
__PR((const char *relp
, char *absp
, size_t asize
,
234 #ifndef HAVE_RESOLVEPATH
235 extern int resolvepath
__PR((const char *__path
,
236 char *__buf
, size_t __bufsiz
));
238 extern int resolvenpath
__PR((const char *__path
,
239 char *__buf
, size_t __bufsiz
));
240 extern int resolvefpath
__PR((const char *__path
,
241 char *__buf
, size_t __bufsiz
, int __flags
));
244 #ifdef _SCHILY_TYPES_H
245 extern int mkdirs
__PR((char *, mode_t
));
246 extern int makedirs
__PR((char *, mode_t
, int __striplast
));
249 extern int lxchdir
__PR((char *));
251 #define fdsetname(fd, name) (0)
252 #define fdclosename(fd) (0)
254 extern int fdsetname
__PR((int fd
, const char *name
));
255 extern int fdclosename
__PR((int fd
));
257 extern int diropen
__PR((const char *));
258 extern int dirrdopen
__PR((const char *));
259 extern int dirclose
__PR((int));
266 extern int savewd
__PR((struct save_wd
*sp
));
267 extern void closewd
__PR((struct save_wd
*sp
));
268 extern int restorewd
__PR((struct save_wd
*sp
));
271 #ifdef _SCHILY_UTYPES_H
272 typedef struct gnmult
{
277 extern int getllnum
__PR((char *arg
, Llong
*lvalp
));
278 extern int getxnum
__PR((char *arg
, long *valp
, gnmult_t
*mult
));
279 extern int getllxnum
__PR((char *arg
, Llong
*lvalp
, gnmult_t
*mult
));
281 extern int getlltnum
__PR((char *arg
, Llong
*lvalp
));
282 extern int getxtnum
__PR((char *arg
, time_t *valp
, gnmult_t
*mult
));
283 extern int getllxtnum
__PR((char *arg
, Llong
*lvalp
, gnmult_t
*mult
));
285 extern int getnum
__PR((char *arg
, long *valp
));
286 #ifdef _SCHILY_TIME_H
287 extern int gettnum
__PR((char *arg
, time_t *valp
));
290 #ifdef _SCHILY_TIME_H
292 extern int getnstimeofday
__PR((struct timespec
*__tp
));
293 extern int setnstimeofday
__PR((struct timespec
*__tp
));
295 #ifdef _SCHILY_UTYPES_H
296 extern Llong mklgmtime
__PR((struct tm
*));
298 extern time_t mkgmtime
__PR((struct tm
*));
302 #ifdef EOF /* stdio.h has been included */
303 #ifdef _SCHILY_TYPES_H
307 #define GP_NOX 0 /* This is not a dir and 'X' is not valid */
308 #define GP_DOX 1 /* 'X' perm character is valid */
309 #define GP_XERR 2 /* 'X' perm characters are invalid */
310 #define GP_FPERM 4 /* TRUE if we implement find -perm */
311 #define GP_UMASK 8 /* TRUE if we implement umask */
313 extern int getperm
__PR((FILE *f
, char *perm
, char *opname
, \
314 mode_t
*modep
, int smode
, int flag
));
315 extern void permtostr
__PR((mode_t mode
, char *));
320 extern ssize_t _niread
__PR((int, void *, size_t));
321 extern ssize_t _niwrite
__PR((int, void *, size_t));
322 extern ssize_t _nixread
__PR((int, void *, size_t));
323 extern ssize_t _nixwrite
__PR((int, void *, size_t));
325 extern int _openfd
__PR((const char *, int));
326 extern int on_comerr
__PR((void (*fun
)(int, void *), void *arg
));
328 extern void comerr
__PR((const char *, ...)) __printflike__(1, 2);
330 extern void xcomerr
__PR((int, const char *, ...)) __printflike__(2, 3);
332 extern void comerrno
__PR((int, const char *, ...)) __printflike__(2, 3);
334 extern void xcomerrno
__PR((int, int, const char *, ...)) __printflike__(3, 4);
336 extern int errmsg
__PR((const char *, ...)) __printflike__(1, 2);
338 extern int errmsgno
__PR((int, const char *, ...)) __printflike__(2, 3);
341 extern int serrmsg
__PR((char *, size_t, const char *, ...))
342 __printflike__(3, 4);
344 extern int serrmsgno
__PR((int, char *, size_t, const char *, ...))
345 __printflike__(4, 5);
347 extern void comexit
__PR((int));
348 extern char *errmsgstr
__PR((int));
350 #ifdef EOF /* stdio.h has been included */
352 extern void fcomerr
__PR((FILE *, const char *, ...))
353 __printflike__(2, 3);
355 extern void fxcomerr
__PR((FILE *, int, const char *, ...))
356 __printflike__(3, 4);
358 extern void fcomerrno
__PR((FILE *, int, const char *, ...))
359 __printflike__(3, 4);
361 extern void fxcomerrno
__PR((FILE *, int, int, const char *, ...))
362 __printflike__(4, 5);
364 extern int ferrmsg
__PR((FILE *, const char *, ...))
365 __printflike__(2, 3);
367 extern int ferrmsgno
__PR((FILE *, int, const char *, ...))
368 __printflike__(3, 4);
369 #ifdef _SCHILY_VARARGS_H
370 #define COMERR_RETURN 0
371 #define COMERR_EXIT 1
372 #define COMERR_EXCODE 2
374 extern int _comerr
__PR((FILE *, int, int, int,
375 const char *, va_list));
380 extern int error
__PR((const char *, ...)) __printflike__(1, 2);
382 extern char *fillbytes
__PR((void *, ssize_t
, char));
383 extern char *zerobytes
__PR((void *, ssize_t
));
384 extern char *findbytes
__PR((const void *, ssize_t
, char));
386 extern char *findinpath
__PR((char *__name
, int __mode
,
387 BOOL __plain_file
, char *__path
));
388 extern int findline
__PR((const char *, char, const char *,
390 extern int js_getline
__PR((char *, int));
391 extern int getstr
__PR((char *, int));
392 extern int breakline
__PR((char *, char, char **, int));
393 extern int getallargs
__PR((int *, char * const**, const char *, ...));
394 extern int getargs
__PR((int *, char * const**, const char *, ...));
395 extern int getfiles
__PR((int *, char * const**, const char *));
396 extern char *astoi
__PR((const char *, int *));
397 extern char *astol
__PR((const char *, long *));
398 extern char *astolb
__PR((const char *, long *, int base
));
399 #ifdef _SCHILY_UTYPES_H
400 extern char *astoll
__PR((const char *, Llong
*));
401 extern char *astollb
__PR((const char *, Llong
*, int));
402 extern char *astoull
__PR((const char *, Ullong
*));
403 extern char *astoullb
__PR((const char *, Ullong
*, int));
406 extern int patcompile
__PR((const unsigned char *, int, int *));
407 extern unsigned char *patmatch
__PR((const unsigned char *, const int *,
408 const unsigned char *,
409 int, int, int, int[]));
410 extern unsigned char *patlmatch
__PR((const unsigned char *, const int *,
411 const unsigned char *,
412 int, int, int, int[]));
415 extern int printf
__PR((const char *, ...)) __printflike__(1, 2);
418 extern char *movebytes
__PR((const void *, void *, ssize_t
));
419 extern char *movecbytes
__PR((const void *, void *, int, size_t));
422 extern void save_args
__PR((int, char **));
423 extern int saved_ac
__PR((void));
424 extern char **saved_av
__PR((void));
425 extern char *saved_av0
__PR((void));
426 extern char *searchfileinpath
__PR((char *__name
, int __mode
,
427 int __file_mode
, char *__path
));
428 #define SIP_ANY_FILE 0x00 /* Search for any file type */
429 #define SIP_PLAIN_FILE 0x01 /* Search for plain files - not dirs */
430 #define SIP_NO_PATH 0x10 /* Do not do PATH search */
431 #define SIP_ONLY_PATH 0x20 /* Do only PATH search */
432 #define SIP_NO_STRIPBIN 0x40 /* Do not strip "/bin" from PATH elem. */
433 #define SIP_TYPE_MASK 0x0F /* Mask file type related bits */
436 extern int seterrno
__PR((int));
438 extern void set_progname
__PR((const char *));
439 extern char *get_progname
__PR((void));
440 extern char *get_progpath
__PR((void));
441 extern char *getexecpath
__PR((void));
443 extern void setfp
__PR((void * const *));
444 extern int wait_chld
__PR((int)); /* for fspawnv_nowait() */
445 extern int geterrno
__PR((void));
446 extern void raisecond
__PR((const char *, long));
449 * sprintf() may be declared incorrectly somewhere else
450 * e.g. in old BSD include files
452 extern int sprintf
__PR((char *, const char *, ...));
454 extern char *strcatl
__PR((char *, ...));
456 extern size_t strlcatl
__PR((char *, size_t, ...));
458 extern int streql
__PR((const char *, const char *));
459 #ifdef _SCHILY_WCHAR_H
460 extern wchar_t *wcscatl
__PR((wchar_t *, ...));
462 extern size_t wcslcatl
__PR((wchar_t *, size_t, ...));
464 extern int wcseql
__PR((const wchar_t *, const wchar_t *));
467 extern int format
__PR((void (*)(char, long), long, const char *,
469 extern int fprformat
__PR((long, const char *, va_list));
471 extern int format
__PR((void (*)(char, long), long, const char *, void *));
472 extern int fprformat
__PR((long, const char *, void *));
475 extern int ftoes
__PR((char *, double, int, int));
476 extern int ftofs
__PR((char *, double, int, int));
477 #ifdef HAVE_LONGDOUBLE
478 extern int qftoes
__PR((char *, long double, int, int));
479 extern int qftofs
__PR((char *, long double, int, int));
483 extern int js_error
__PR((const char *, ...)) __printflike__(1, 2);
485 extern int js_dprintf
__PR((int, const char *, ...))
486 __printflike__(2, 3);
487 #ifdef EOF /* stdio.h has been included */
489 extern int js_fprintf
__PR((FILE *, const char *, ...))
490 __printflike__(2, 3);
493 extern int js_printf
__PR((const char *, ...)) __printflike__(1, 2);
496 extern int js_snprintf
__PR((char *, size_t, const char *, ...))
497 __printflike__(3, 4);
500 extern int js_sprintf
__PR((char *, const char *, ...))
501 __printflike__(2, 3);
504 extern void swabbytes
__PR((void *, ssize_t
));
506 extern char **getmainfp
__PR((void));
507 extern char **getavp
__PR((void));
508 extern char *getav0
__PR((void));
509 extern void **getfp
__PR((void));
510 extern int flush_reg_windows
__PR((int));
512 extern ssize_t cmpbytes
__PR((const void *, const void *, ssize_t
));
513 extern int cmpmbytes
__PR((const void *, const void *, ssize_t
));
514 extern ssize_t cmpnullbytes
__PR((const void *, ssize_t
));
518 #if defined(HAVE_LARGEFILES)
520 * To allow this, we need to figure out how to do autoconfiguration for off64_t
522 extern FILE *_fcons64
__PR((FILE *, int, int));
523 extern FILE *fdup64
__PR((FILE *));
524 extern FILE *fileluopen64
__PR((int, const char *));
525 extern FILE *fileopen64
__PR((const char *, const char *));
527 extern off64_t filepos64
__PR((FILE *));
529 extern FILE *filereopen64
__PR((const char *, const char *, FILE *));
531 extern int fileseek64
__PR((FILE *, off64_t
));
532 extern off64_t filesize64
__PR((FILE *));
535 extern int filestat64
__PR((FILE *, struct stat
*));
537 extern int _openfd64
__PR((const char *, int));
541 #ifndef NO_SCHILY_PRINT /* Define to disable *printf() redirects */
545 #define error js_error
546 #endif /* __never__ */
548 #define dprintf js_dprintf
550 #define fprintf js_fprintf
552 #define printf js_printf
554 #define snprintf js_snprintf
556 #define sprintf js_sprintf
558 #ifndef HAVE_SNPRINTF
560 #define snprintf js_snprintf
561 #endif /* HAVE_SNPRINTF */
562 #endif /* SCHILY_PRINT */
563 #endif /* NO_SCHILY_PRINT */
565 #ifndef NO_SCHILY_GETLINE /* Define to disable *getline() redirect */
567 #define getline js_getline
569 #define fgetline js_fgetline
572 #ifndef NO_SCHILY_FEXEC /* Define to disable fexec*() redirect */
574 #define fexecl js_fexecl
576 #define fexecle js_fexecle
578 #define fexecv js_fexecv
580 #define fexecve js_fexecve
583 #ifndef NO_SCHILY_FSPAWN /* Define to disable fspawn*() redirect */
585 #define fspawnv js_fspawnv
586 #undef fspawnv_nowait
587 #define fspawnv_nowait js_fspawnv_nowait
589 #define fspawnl js_fspawnl
592 extern int js_mexval
__PR((int exval
));
594 extern void *js_malloc
__PR((size_t size
, char *msg
));
595 extern void *js_realloc
__PR((void *ptr
, size_t size
, char *msg
));
597 extern char *js_savestr
__PR((const char *s
));
599 #ifdef _SCHILY_JMPDEFS_H
602 * Special values for the "jmp" parameter.
604 * Control how the siglongjmp() should be handled:
606 #define JM_EXIT ((sigjmps_t *)-1) /* Call comexit(errno) instead */
607 #define JM_RETURN ((sigjmps_t *)0) /* Return instead */
609 extern int js_jmexval
__PR((int exval
));
611 extern void *js_jmalloc
__PR((size_t size
, char *msg
, sigjmps_t
*jmp
));
612 extern void *js_jrealloc
__PR((void *ptr
, size_t size
, char *msg
,
615 extern char *js_jsavestr
__PR((const char *s
, sigjmps_t
*jmp
));
617 extern int js_fjmexval
__PR((int exval
));
618 #ifdef EOF /* stdio.h has been included */
620 extern void *js_fjmalloc
__PR((FILE *f
, size_t size
, char *msg
,
622 extern void *js_fjrealloc
__PR((FILE *f
, void *ptr
, size_t size
,
623 char *msg
, sigjmps_t
*jmp
));
625 extern char *js_fjsavestr
__PR((FILE *f
, const char *s
, sigjmps_t
*jmp
));
627 #endif /* _SCHILY_JMPDEFS_H */
629 #define ___mexval js_mexval
630 #define ___malloc js_malloc
631 #define ___realloc js_realloc
632 #define ___savestr js_savestr
633 #define __jmexval js_jmexval
634 #define __jmalloc js_jmalloc
635 #define __jrealloc js_jrealloc
636 #define __jsavestr js_jsavestr
637 #define __fjmalloc js_fjmalloc
638 #define __fjmexval js_fjmexval
639 #define __fjrealloc js_fjrealloc
640 #define __fjsavestr js_fjsavestr
646 #if defined(_JOS) || defined(JOS)
647 # ifndef _SCHILY_JOS_IO_H
648 # include <schily/jos_io.h>
652 #if !defined(_SCHILY_LIBPORT_H) && !defined(NO_LIBPORT_H)
653 #include <schily/libport.h>
655 #if !defined(_SCHILY_HOSTNAME_H) && defined(USE_HOSTNAME_H)
656 #include <schily/hostname.h>
659 #endif /* _SCHILY_SCHILY_H */