sfhdr.h revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#ifndef _SFHDR_H
#define _SFHDR_H 1
#if !defined(_BLD_sfio) && !defined(_BLD_stdio)
#define _BLD_sfio 1
#endif
/* Internal definitions for sfio.
** Written by Kiem-Phong Vo
*/
#if !_PACKAGE_ast
/* some systems don't know large files */
#define _NO_LARGEFILE64_SOURCE 1
#endif
#define _LARGEFILE_SOURCE 1
#endif
#if _hdr_stdarg
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#if !__STD_C
#define const
#endif
#endif /* !_PACKAGE_ast */
#include "sfio_t.h"
/* note that the macro vt_threaded has effect on vthread.h */
#include <vthread.h>
/* file system info */
#if _PACKAGE_ast
#include <ast.h>
#include <ast_time.h>
#include <ast_tty.h>
#include <ls.h>
/* ast always provides multibyte handling */
#define _hdr_wchar 1
#define _lib_mbrtowc 1
#define _lib_wcrtomb 1
#define _stat_blksize 1
#endif
#if _lib_localeconv && _hdr_locale
#define _lib_locale 1
#endif
#define sysftruncatef ftruncate
#define sysmunmapf munmap
#define sysremovef remove
#else /*!_PACKAGE_ast*/
/* when building the binary compatibility package, a number of header files
are not needed and they may get in the way so we remove them here.
*/
#if _SFBINARY_H
#endif
#if _hdr_stdlib
#include <stdlib.h>
#endif
#if _hdr_string
#include <string.h>
#endif
#if _hdr_time
#include <time.h>
#endif
#if _sys_time
#endif
#if _sys_stat
#else
#if _hdr_stat
#include <stat.h>
#ifndef _sys_stat
#define _sys_stat 1
#endif
#endif
#endif /*_sys_stat*/
#ifndef _sys_stat
#define _sys_stat 0
#endif
#include <fcntl.h>
#ifndef F_SETFD
#ifndef FIOCLEX
#if _hdr_filio
#include <filio.h>
#else
#if _sys_filio
#endif /*_sys_filio*/
#endif /*_hdr_filio*/
#endif /*_FIOCLEX*/
#endif /*F_SETFD*/
#if _hdr_unistd
#include <unistd.h>
#endif
#if !_LARGEFILE64_SOURCE /* turn off the *64 stuff */
#endif /*!_LARGEFILE64_SOURCE */
/* see if we can use memory mapping for io */
#if _LARGEFILE64_SOURCE && !_lib_mmap64
#endif
#if !_mmap_worthy
#endif
#if _hdr_mman
#include <mman.h>
#endif
#if _sys_mman
#endif
/* standardize system calls and types dealing with files */
#if _typ_off64_t
#else
#endif
#else
#endif
#if _lib_lseek64
#else
#endif
#if _lib_stat64
#else
#endif
#if _lib_fstat64
#else
#endif
#if _lib_mmap64
#else
#endif
#if _lib_munmap64
#define sysmunmapf munmap64
#else
#define sysmunmapf munmap
#endif
#if _lib_open64
#else
#endif
#if _lib_creat64
#else
#endif
#if _lib_close64
#else
#endif
#if _lib_ftruncate64
#define _lib_ftruncate 1
#define sysftruncatef ftruncate64
#endif
#if !_lib_ftruncate64 && _lib_ftruncate
#define sysftruncatef ftruncate
#endif
#if _lib_remove
#define sysremovef remove
#else
#define sysremovef unlink
#endif
#endif /*_PACKAGE_ast*/
#if !_mmap_worthy
#endif
#include <errno.h>
#include <ctype.h>
/* deal with multi-byte character and string conversions */
#if _PACKAGE_ast
#include <wchar.h>
#define _has_multibyte 1
#else
#if _typ___va_list && !defined(__va_list)
#endif
#include <wchar.h>
#endif /*_hdr_wchar && _typ_mbstate_t && _lib_wcrtomb && _lib_mbrtowc*/
#include <wchar.h>
#endif /*!_has_multibyte && _hdr_wchar && _lib_mbtowc && _lib_wctomb*/
#ifdef MB_CUR_MAX
#define SFMBMAX MB_CUR_MAX
#else
#endif
#endif /* _PACKAGE_ast */
#if !_has_multibyte
#define _has_multibyte 0 /* no multibyte support */
#endif /* _has_multibyte */
/* dealing with streams that might be accessed concurrently */
#if vt_threaded
if(_Sfnotify) \
} \
} \
}
{ if(_Sfnotify) \
} \
}
#define POOLMTXENTER(p) { POOLMTXLOCK(p); }
#else /*!vt_threaded*/
#define SF_MTSAFE 0
#define SFONCE() /*(0)*/
#define SFMTXLOCK(f) /*(0)*/
#define SFMTXUNLOCK(f) /*(0)*/
#define SFMTXRETURN(ff,v) { return(v); }
#define POOLMTXLOCK(p)
#define POOLMTXUNLOCK(p)
#define POOLMTXENTER(p)
#define POOLMTXRETURN(p,v) { return(v); }
#endif /*vt_threaded*/
/* functions for polling readiness of streams */
#if _lib_select
#if _sys_select
#endif
#else
#if _lib_poll_fd_1 || _lib_poll_fd_2
#define _lib_poll 1
#endif
#endif /*_lib_select_*/
#if _lib_poll
#include <poll.h>
#if _lib_poll_fd_1
#else
#endif
#endif /*_lib_poll*/
#if _stream_peek
#include <stropts.h>
#endif
#if _socket_peek
#endif
/* to test for executable access mode of a file */
#ifndef X_OK
#define X_OK 01
#endif
/* alternative process forking */
#if _hdr_vfork
#include <vfork.h>
#endif
#if _sys_vfork
#endif
#endif
/* to get rid of pesky compiler warnings */
#if __STD_C
#define NOTUSED(x) (void)(x)
#else
#define NOTUSED(x) (&x,1)
#endif
/* Private flags in the "bits" field */
/* "bits" flags that must be cleared in sfclrlock */
#define SF_TMPBITS 00170000
#if _has_multibyte
#else
#define SFWCSET(f)
#define SFWCGET(f,v)
#endif
/* bits for the mode field, SF_INIT defined in sfio_t.h */
#ifdef DEBUG
#else
#define ASSERT(p)
#endif
/* short-hands */
#define NIL(t) ((t)0)
#define reg register
#ifndef uchar
#define uchar unsigned char
#endif
#ifndef ulong
#define ulong unsigned long
#endif
#ifndef uint
#define uint unsigned int
#endif
#ifndef ushort
#define ushort unsigned short
#endif
/* macros do determine stream types from sfstat_t data */
#ifndef S_IFDIR
#define S_IFDIR 0
#endif
#ifndef S_IFREG
#define S_IFREG 0
#endif
#ifndef S_IFCHR
#define S_IFCHR 0
#endif
#ifndef S_IFIFO
#define S_IFIFO 0
#endif
#ifndef S_ISOCK
#define S_ISOCK 0
#endif
#ifndef S_IFMT
#endif
#ifndef S_ISDIR
#endif
#ifndef S_ISREG
#endif
#ifndef S_ISCHR
#endif
#ifndef S_ISFIFO
# if S_IFIFO
# else
# define S_ISFIFO(m) (0)
# endif
#endif
#ifdef S_IRUSR
#else
#define SF_CREATMODE 0666
#endif
/* set close-on-exec */
#ifdef F_SETFD
# ifndef FD_CLOEXEC
# define FD_CLOEXEC 1
# endif /*FD_CLOEXEC*/
#else
# ifdef FIOCLEX
# else
# define SETCLOEXEC(fd)
# endif /*FIOCLEX*/
#endif /*F_SETFD*/
#define SF_FD_CLOEXEC 0x0001
/* a couple of error number that we use, default values are like Linux */
#ifndef EINTR
#define EINTR 4
#endif
#ifndef EBADF
#define EBADF 9
#endif
#ifndef EAGAIN
#define EAGAIN 11
#endif
#ifndef ENOMEM
#define ENOMEM 12
#endif
#ifndef EINVAL
#define EINVAL 22
#endif
#ifndef ESPIPE
#define ESPIPE 29
#endif
/* function to get the decimal point for local environment */
#if !defined(SFSETLOCALE) && _PACKAGE_ast
#include "lclib.h"
do if (*(dp) == 0) { \
} while (0)
#endif /*!defined(SFSETLOCALE) && _PACKAGE_ast*/
#if !defined(SFSETLOCALE) && _lib_locale
#include <locale.h>
if(*(decimal) == 0) \
{ *(decimal) = '.'; \
*(thousand) = -1; \
if((lv = localeconv())) \
} \
} \
} while (0)
#endif /*!defined(SFSETLOCALE) && _lib_locale*/
#if !defined(SFSETLOCALE)
#endif
/* stream pool structure. */
struct _sfpool_s
int mode; /* type of pool */
int s_sf; /* size of pool array */
int n_sf; /* number currently in pool */
};
/* reserve buffer structure */
struct _sfrsrv_s
};
/* co-process structure */
struct _sfproc_s
{ int pid; /* process id */
int ndata; /* size of cached data */
int size; /* buffer size */
int file; /* saved file descriptor */
int sigp; /* sigpipe protection needed */
};
#define FP_WIDTH 0
#define FP_PRECIS 1
#define FP_BASE 2
#define FP_STR 3
#define FP_SIZE 4
typedef union
{ int i, *ip;
long l, *lp;
short h, *hp;
double d;
float f;
#if _has_multibyte
#endif
char c, *s, **sp;
} Argv_t;
struct _fmt_s
{ char* form; /* format string */
char* oform; /* original format string */
int argn; /* number of args already used */
};
struct _fmtpos_s
int fmt; /* original format */
};
#define LEFTP '('
#define RIGHTP ')'
#define QUOTE '\''
#ifndef CHAR_BIT
#define CHAR_BIT 8
#endif
/* format flags&types, must coexist with those in sfio.h */
/* type of elements to be converted */
/* local variables used across sf-functions */
typedef struct _sfextern_s
void (*sf_cleanup)_ARG_((void));
int sf_exiting;
int sf_done;
} Sfextern_t;
/* get the real value of a byte in a coded long or ulong */
/* pick this many bits in each iteration of double encoding */
#define SF_PRECIS 7
/* grain size for buffer increment */
#define SF_GRAIN 1024
/* when the buffer is empty, certain io requests may be better done directly
on the given application buffers. The below condition determines when.
*/
/* number of pages to memory map at a time */
#if _ptr_bits >= 64
#define SF_NMAP 1024
#else
#define SF_NMAP 32
#endif
#ifndef MAP_VARIABLE
#define MAP_VARIABLE 0
#endif
#ifndef _mmap_fixed
#define _mmap_fixed 0
#endif
#define SFMMSEQON(f,a,s) \
} while(0)
#define SFMMSEQOFF(f,a,s) \
} while(0)
#else
#define SFMMSEQON(f,a,s)
#define SFMMSEQOFF(f,a,s)
#endif
/* safe closing function */
/* the bottomless bit bucket */
/* exception types */
#define SF_EDONE 0 /* stop this operation and return */
#define SFOPEN(f,l) (void)((l) ? 0 : \
/* check to see if the stream can be accessed */
/* set discipline code */
{ Sfdisc_t* d; \
if(!(dc)) \
if(d) (dc) = d; \
}
}
}
}
/* fast peek of a stream */
/* more than this for a line buffer, we might as well flush */
#define HIFORLINE 128
/* string stream extent */
if(s > (f)->here) \
}
/* control flags for open() */
#ifdef O_CREAT
#define _has_oflags 1
#else /* for example, research UNIX */
#define _has_oflags 0
#define O_CREAT 004
#define O_TRUNC 010
#define O_APPEND 020
#define O_EXCL 040
#ifndef O_RDONLY
#define O_RDONLY 000
#endif
#ifndef O_WRONLY
#define O_WRONLY 001
#endif
#ifndef O_RDWR
#define O_RDWR 002
#endif
#endif /*O_CREAT*/
#ifndef O_BINARY
#define O_BINARY 000
#endif
#ifndef O_TEXT
#define O_TEXT 000
#endif
#ifndef O_TEMPORARY
#define O_TEMPORARY 000
#endif
#if _PACKAGE_ast
#define SF_MAXLONG LONG_MAX
#else
#endif
#define SF_MAXCHAR ((uchar)(~0))
/* floating point to ascii conversion */
#define SF_MAXEXP10 6
#if !_ast_fltmax_double
#else
#endif
/* tables for numerical translation */
struct _sfieee_s
{ float fltnan; /* float NAN */
float fltinf; /* float INF */
double dblnan; /* double NAN */
double dblinf; /* double INF */
};
typedef struct _sftab_
char* sf_digits; /* digits for general bases */
int (*sf_cvinitf)(); /* initialization function */
int sf_cvinit; /* initialization state */
char* (*sf_fmtintf)_ARG_((const char*,int*));
float* sf_flt_pow10; /* float powers of 10 */
double* sf_dbl_pow10; /* double powers of 10 */
} Sftab_t;
/* sfucvt() converts decimal integers to ASCII */
{ if(v < 5*scale) \
if(v < 2*scale) \
if(v < 1*scale) \
{ digit = '0'; } \
else if(v < 3*scale) \
else if(v < 4*scale) \
else if(v < 7*scale) \
if(v < 6*scale) \
else if(v < 8*scale) \
else if(v < 9*scale) \
}
{ while((utype)v >= 10000) \
} \
if(v < 100) \
{ if(v < 10) \
{ s -= 1; s[0] = (char)('0'+v); \
} else \
} \
} else \
{ if(v < 1000) \
} else \
} \
} \
}
/* handy functions */
#define min(x,y) ((x) < (y) ? (x) : (y))
#define max(x,y) ((x) > (y) ? (x) : (y))
/* fast functions for memory copy and memory clear */
#if _PACKAGE_ast
#else
#if _lib_bcopy && !_lib_memcpy
#endif
#if _lib_bzero && !_lib_memset
#else
#endif
#endif /*_PACKAGE_ast*/
/* note that MEMCPY advances the associated pointers */
switch(n) \
}
#define MEMSET(s,c,n) \
switch(n) \
case 7 : *s++ = c; \
case 6 : *s++ = c; \
case 5 : *s++ = c; \
case 4 : *s++ = c; \
case 3 : *s++ = c; \
case 2 : *s++ = c; \
case 1 : *s++ = c; \
}
extern char** _sfgetpath _ARG_((char*));
#if _BLD_sfio && defined(__EXPORT__)
#define extern __EXPORT__
#endif
#if !_BLD_sfio && defined(__IMPORT__)
#define extern extern __IMPORT__
#endif
extern Sfextern_t _Sfextern;
#undef extern
#ifndef errno
extern int errno;
#endif
/* for portable encoding of double values */
#ifndef frexpl
#endif
#if !_lib_frexpl
#endif
#endif
#ifndef ldexpl
#endif
#if !_lib_ldexpl
#endif
#endif
#if !_PACKAGE_ast
#if !__STDC__ && !_hdr_stdlib
#ifndef memcpy
#endif
#if !defined(strtod)
#endif
#if !defined(remove)
extern int sysremovef _ARG_((const char*));
#endif
#endif /* !__STDC__ && !_hdr_stdlib */
#if !_hdr_unistd
#if _proto_open && __cplusplus
#endif
extern int sysaccessf _ARG_((const char*, int));
extern int sysremovef _ARG_((const char*));
#if !defined(fork)
#endif
#if _lib_unlink
#endif
#endif /*_hdr_unistd*/
#if _lib_bcopy && !_proto_bcopy
#endif
#if _lib_bzero && !_proto_bzero
#endif
#endif /*_lib_vfork*/
#if _lib_poll
#if _lib_poll_fd_1
#else
#endif
#endif /*_lib_poll*/
#endif /* _PACKAGE_ast */
#endif /*_SFHDR_H*/