mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
This takes another step towards cleaning up the build system. We now do not even pretend to be theoretically compatible with pre-1989 K&R C compilers or with C++ compilers. In practice, this had already been broken for many years due to bit rot. Commit46593a89already removed the license handling enormity that depended on proto, so now we can cleanly remove it altogether. But we do need to leave some backwards compatibility stubs to keep the build system compatible with older AST code; it should remain possible to build older ksh versions with the current build system (the bin/ and src/cmd/INIT/ directories) for testing purposes. So as of now there is no more __MANGLE__d rubbish in your generated header files. This is only about a quarter of a century overdue... This commit also includes a huge amount of code cleanup to remove thousands of unused K&R C fallbacks and other cruft, particularly in libast. This code base should now be a little easier to understand for people who are familiar with a modern(ish) C standard. ratz is now also removed; this was a standalone and simplified 2005 version of gunzip. As of6137b99a, none of our code uses it, even theoretically. And the real g(un)zip is now everywhere. src/cmd/INIT/proto.c, src/cmd/INIT/ratz.c: - Removed. COPYRIGHT: - Remove zlib license; this only applied to ratz. bin/package, src/cmd/INIT/package.sh: - Related cleanups. - Unset LC_ALL before invoking a new shell, respecting the user's locale again and avoiding multibyte character corruption on the command line. src/cmd/INIT/proto.sh: - Add stub for backwards compatibility with Mamfiles that depend on proto. It does nothing but pass input without modification and is now installed as the new arch/*/bin/proto by src/cmd/INIT/Mamfile. src/cmd/INIT/iffe.sh: - Ignore the proto-related -e (--package) and -p (--prototyped) options; keep parsing them for backwards compatibility. - Trim the macros passed to every test to their standard C versions, removing K&R C and C++ versions. These are now considered to be for backwards compatibility only. src/cmd/INIT/iffe.tst: - Remove proto(1) mangling code. By the way, iffe can be regression-tested as follows: $ bin/package use # set up environment in a child shell $ regress src/cmd/INIT/iffe.tst $ exit # leave package environment src/cmd/INIT/make.probe, src/cmd/INIT/probe.win32: - Remove code to handle C++. src/lib/libast/features/common: - As in iffe.sh above, trim macros designed for compatibility with C++ and ancient C compilers to their standard C versions and comment that they are for backwards compatibility with AST code. This is needed to keep all the old ast and ksh code compiling. src/cmd/ksh93/sh/init.c, src/cmd/ksh93/sh/name.c: - Clarify libshell ABI compatibility function versions of macros. A "proto workaround" comment in the original code mislead me into thinking this had something to do with the removed proto(1), but it's unrelated. Call the workaround macro BYPASS_MACRO instead. src/cmd/ksh93/include/defs.h: - sh_sigcheck() macro: allow &sh as an argument: parenthesise shp. src/cmd/ksh93/sh/nvtype.c: - Remove unused nv_mkstruct() function. (re:d0a5cab1) **/features/*: - Remove obsolete iffe 'set prototyped' option. **/Mamfile: - Remove all references to the ast/prototyped.h header. - Remove all use of the proto command. Simply copy instead. *** 850-ish source files: *** - Remove all '#pragma prototyped' directives. - Remove all C++ compat code conditional upon defined(__cplusplus). - Remove all use of the _ARG_ macro, which on standard C expands to its argument: #define _ARG_(x) x (on K&R C, it expanded to nothing) - Remove all use of _BEGIN_EXTERNS_ and _END_EXTERNS_ macros (empty on standard C; this was for C++ compatibility) - Reduce all #if __STD_C (standard code) #else (K&R code) #endif blocks to the standard code only, without use of the macro. - Same for _STD_ macro which seems to have had the same function. - Change all instances of 'Void_t' to standard 'void'.
This commit is contained in:
parent
3785a0685c
commit
a1f5c99204
869 changed files with 1853 additions and 14292 deletions
|
|
@ -24,12 +24,7 @@
|
|||
|
||||
#undef sfclrerr
|
||||
|
||||
#if __STD_C
|
||||
int sfclrerr(reg Sfio_t* f)
|
||||
#else
|
||||
int sfclrerr(f)
|
||||
reg Sfio_t* f;
|
||||
#endif
|
||||
{
|
||||
return __sf_clrerr(f);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,7 @@
|
|||
|
||||
#undef sfdlen
|
||||
|
||||
#if __STD_C
|
||||
int sfdlen(reg Sfdouble_t v)
|
||||
#else
|
||||
int sfdlen(v)
|
||||
reg Sfdouble_t v;
|
||||
#endif
|
||||
{
|
||||
return __sf_dlen(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,7 @@
|
|||
|
||||
#undef sfeof
|
||||
|
||||
#if __STD_C
|
||||
int sfeof(reg Sfio_t* f)
|
||||
#else
|
||||
int sfeof(f)
|
||||
reg Sfio_t* f;
|
||||
#endif
|
||||
{
|
||||
return __sf_eof(f);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,7 @@
|
|||
|
||||
#undef sferror
|
||||
|
||||
#if __STD_C
|
||||
int sferror(reg Sfio_t* f)
|
||||
#else
|
||||
int sferror(f)
|
||||
reg Sfio_t* f;
|
||||
#endif
|
||||
{
|
||||
return __sf_error(f);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,7 @@
|
|||
|
||||
#undef sffileno
|
||||
|
||||
#if __STD_C
|
||||
int sffileno(reg Sfio_t* f)
|
||||
#else
|
||||
int sffileno(f)
|
||||
reg Sfio_t* f;
|
||||
#endif
|
||||
{
|
||||
return __sf_fileno(f);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,7 @@
|
|||
|
||||
#undef sfgetc
|
||||
|
||||
#if __STD_C
|
||||
int sfgetc(reg Sfio_t* f)
|
||||
#else
|
||||
int sfgetc(f)
|
||||
reg Sfio_t* f;
|
||||
#endif
|
||||
{
|
||||
return __sf_getc(f);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,12 +31,7 @@
|
|||
#endif
|
||||
|
||||
extern
|
||||
#if __STD_C
|
||||
Sflong_t _sfgetl(reg Sfio_t* f)
|
||||
#else
|
||||
Sflong_t _sfgetl(f)
|
||||
reg Sfio_t* f;
|
||||
#endif
|
||||
{
|
||||
sfungetc(f, (unsigned char)_SF_(f)->val);
|
||||
return sfgetl(f);
|
||||
|
|
|
|||
|
|
@ -26,23 +26,15 @@
|
|||
|
||||
#undef _sfgetl2
|
||||
|
||||
_BEGIN_EXTERNS_
|
||||
#if _BLD_sfio && defined(__EXPORT__)
|
||||
#define extern __EXPORT__
|
||||
#endif
|
||||
|
||||
extern long _sfgetl2 _ARG_((Sfio_t*, long));
|
||||
extern long _sfgetl2(Sfio_t*, long);
|
||||
|
||||
#undef extern
|
||||
_END_EXTERNS_
|
||||
|
||||
#if __STD_C
|
||||
long _sfgetl2(reg Sfio_t* f, long v)
|
||||
#else
|
||||
long _sfgetl2(f, v)
|
||||
reg Sfio_t* f;
|
||||
long v;
|
||||
#endif
|
||||
{
|
||||
if (v < 0)
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -31,12 +31,7 @@
|
|||
#endif
|
||||
|
||||
extern
|
||||
#if __STD_C
|
||||
Sfulong_t _sfgetu(reg Sfio_t* f)
|
||||
#else
|
||||
Sfulong_t _sfgetu(f)
|
||||
reg Sfio_t* f;
|
||||
#endif
|
||||
{
|
||||
sfungetc(f, (unsigned char)_SF_(f)->val);
|
||||
return sfgetu(f);
|
||||
|
|
|
|||
|
|
@ -26,23 +26,15 @@
|
|||
|
||||
#undef _sfgetu2
|
||||
|
||||
_BEGIN_EXTERNS_
|
||||
#if _BLD_sfio && defined(__EXPORT__)
|
||||
#define extern __EXPORT__
|
||||
#endif
|
||||
|
||||
extern long _sfgetu2 _ARG_((Sfio_t*, long));
|
||||
extern long _sfgetu2(Sfio_t*, long);
|
||||
|
||||
#undef extern
|
||||
_END_EXTERNS_
|
||||
|
||||
#if __STD_C
|
||||
long _sfgetu2(reg Sfio_t* f, long v)
|
||||
#else
|
||||
long _sfgetu2(f, v)
|
||||
reg Sfio_t* f;
|
||||
long v;
|
||||
#endif
|
||||
{
|
||||
if (v < 0)
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -24,12 +24,7 @@
|
|||
|
||||
#undef sfllen
|
||||
|
||||
#if __STD_C
|
||||
int sfllen(reg Sflong_t v)
|
||||
#else
|
||||
int sfllen(v)
|
||||
reg Sflong_t v;
|
||||
#endif
|
||||
{
|
||||
return __sf_llen(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,14 +35,9 @@
|
|||
extern
|
||||
#undef extern
|
||||
|
||||
#if __STD_C
|
||||
Sfio_t* _sfopen(Sfio_t* f, const char* file, const char* mode)
|
||||
#else
|
||||
Sfio_t* _sfopen(f,file,mode)
|
||||
Sfio_t* f; /* old stream structure */
|
||||
char* file; /* file/string to be opened */
|
||||
char* mode; /* mode of the stream */
|
||||
#endif
|
||||
Sfio_t* _sfopen(Sfio_t* f, /* old stream structure */
|
||||
const char* file, /* file/string to be opened */
|
||||
const char* mode) /* mode of the stream */
|
||||
{
|
||||
int fd, oldfd, oflags, fflags, sflags;
|
||||
SFMTXDECL(f);
|
||||
|
|
@ -143,15 +138,7 @@ char* mode; /* mode of the stream */
|
|||
return f;
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
int _sftype(reg const char* mode, int* oflagsp, int* fflagsp, int* uflagp)
|
||||
#else
|
||||
int _sftype(mode, oflagsp, fflagsp, uflagp)
|
||||
reg char* mode;
|
||||
int* oflagsp;
|
||||
int* fflagsp;
|
||||
int* uflagp;
|
||||
#endif
|
||||
{
|
||||
reg int sflags, oflags, fflags, uflag;
|
||||
|
||||
|
|
|
|||
|
|
@ -24,13 +24,7 @@
|
|||
|
||||
#undef sfputc
|
||||
|
||||
#if __STD_C
|
||||
int sfputc(reg Sfio_t* f, reg int c)
|
||||
#else
|
||||
int sfputc(f,c)
|
||||
reg Sfio_t* f;
|
||||
reg int c;
|
||||
#endif
|
||||
{
|
||||
return __sf_putc(f,c);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,13 +27,7 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
int _sfputd(Sfio_t* f, Sfdouble_t v)
|
||||
#else
|
||||
int _sfputd(f,v)
|
||||
Sfio_t* f;
|
||||
Sfdouble_t v;
|
||||
#endif
|
||||
{
|
||||
#define N_ARRAY (16*sizeof(Sfdouble_t))
|
||||
reg ssize_t n, w;
|
||||
|
|
@ -90,7 +84,7 @@ Sfdouble_t v;
|
|||
|
||||
/* write out coded bytes */
|
||||
n = ends - s + 1;
|
||||
w = SFWRITE(f,(Void_t*)s,n) == n ? w+n : -1;
|
||||
w = SFWRITE(f,(void*)s,n) == n ? w+n : -1;
|
||||
|
||||
SFOPEN(f,0);
|
||||
SFMTXRETURN(f,w);
|
||||
|
|
|
|||
|
|
@ -27,13 +27,8 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
int _sfputl(Sfio_t* f, Sflong_t v)
|
||||
#else
|
||||
int _sfputl(f,v)
|
||||
Sfio_t* f; /* write a portable long to this stream */
|
||||
Sflong_t v; /* the value to be written */
|
||||
#endif
|
||||
int _sfputl(Sfio_t* f, /* write a portable long to this stream */
|
||||
Sflong_t v) /* the value to be written */
|
||||
{
|
||||
#define N_ARRAY (2*sizeof(Sflong_t))
|
||||
reg uchar *s, *ps;
|
||||
|
|
@ -62,7 +57,7 @@ Sflong_t v; /* the value to be written */
|
|||
n = (ps-s)+1;
|
||||
|
||||
if(n > 8 || SFWPEEK(f,ps,p) < n)
|
||||
n = SFWRITE(f,(Void_t*)s,n); /* write the hard way */
|
||||
n = SFWRITE(f,(void*)s,n); /* write the hard way */
|
||||
else
|
||||
{ switch(n)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,14 +27,9 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
int _sfputm(Sfio_t* f, Sfulong_t v, Sfulong_t m)
|
||||
#else
|
||||
int _sfputm(f,v,m)
|
||||
Sfio_t* f; /* write a portable ulong to this stream */
|
||||
Sfulong_t v; /* the unsigned value to be written */
|
||||
Sfulong_t m; /* the max value of the range */
|
||||
#endif
|
||||
int _sfputm(Sfio_t* f, /* write a portable ulong to this stream */
|
||||
Sfulong_t v, /* the unsigned value to be written */
|
||||
Sfulong_t m) /* the max value of the range */
|
||||
{
|
||||
#define N_ARRAY (2*sizeof(Sfulong_t))
|
||||
reg uchar *s, *ps;
|
||||
|
|
@ -58,7 +53,7 @@ Sfulong_t m; /* the max value of the range */
|
|||
n = (ps-s)+1;
|
||||
|
||||
if(n > 8 || SFWPEEK(f,ps,p) < n)
|
||||
n = SFWRITE(f,(Void_t*)s,n); /* write the hard way */
|
||||
n = SFWRITE(f,(void*)s,n); /* write the hard way */
|
||||
else
|
||||
{ switch(n)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,13 +27,8 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
int _sfputu(Sfio_t* f, Sfulong_t v)
|
||||
#else
|
||||
int _sfputu(f,v)
|
||||
Sfio_t* f; /* write a portable ulong to this stream */
|
||||
Sfulong_t v; /* the unsigned value to be written */
|
||||
#endif
|
||||
int _sfputu(Sfio_t* f, /* write a portable ulong to this stream */
|
||||
Sfulong_t v) /* the unsigned value to be written */
|
||||
{
|
||||
#define N_ARRAY (2*sizeof(Sfulong_t))
|
||||
reg uchar *s, *ps;
|
||||
|
|
@ -55,7 +50,7 @@ Sfulong_t v; /* the unsigned value to be written */
|
|||
n = (ps-s)+1;
|
||||
|
||||
if(n > 8 || SFWPEEK(f,ps,p) < n)
|
||||
n = SFWRITE(f,(Void_t*)s,n); /* write the hard way */
|
||||
n = SFWRITE(f,(void*)s,n); /* write the hard way */
|
||||
else
|
||||
{ switch(n)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -24,11 +24,7 @@
|
|||
|
||||
#undef sfslen
|
||||
|
||||
#if __STD_C
|
||||
ssize_t sfslen(void)
|
||||
#else
|
||||
ssize_t sfslen()
|
||||
#endif
|
||||
{
|
||||
return __sf_slen();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,7 @@
|
|||
|
||||
#undef sfstacked
|
||||
|
||||
#if __STD_C
|
||||
int sfstacked(reg Sfio_t* f)
|
||||
#else
|
||||
int sfstacked(f)
|
||||
reg Sfio_t* f;
|
||||
#endif
|
||||
{
|
||||
return __sf_stacked(f);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,7 @@
|
|||
|
||||
#undef sfulen
|
||||
|
||||
#if __STD_C
|
||||
int sfulen(reg Sfulong_t v)
|
||||
#else
|
||||
int sfulen(v)
|
||||
reg Sfulong_t v;
|
||||
#endif
|
||||
{
|
||||
return __sf_ulen(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,7 @@
|
|||
|
||||
#undef sfvalue
|
||||
|
||||
#if __STD_C
|
||||
ssize_t sfvalue(reg Sfio_t* f)
|
||||
#else
|
||||
ssize_t sfvalue(f)
|
||||
reg Sfio_t* f;
|
||||
#endif
|
||||
{
|
||||
return __sf_value(f);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,15 +27,10 @@
|
|||
** Written by Kiem-Phong Vo
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
int sfclose(Sfio_t* f)
|
||||
#else
|
||||
int sfclose(f)
|
||||
Sfio_t* f;
|
||||
#endif
|
||||
{
|
||||
reg int local, ex, rv;
|
||||
Void_t* data = NIL(Void_t*);
|
||||
void* data = NIL(void*);
|
||||
SFMTXDECL(f); /* declare a local stream variable for multithreading */
|
||||
|
||||
SFMTXENTER(f, -1);
|
||||
|
|
@ -72,7 +67,7 @@ Sfio_t* f;
|
|||
SFLOCK(f,0);
|
||||
|
||||
/* raise discipline exceptions */
|
||||
if(f->disc && (ex = SFRAISE(f,local ? SF_NEW : SF_CLOSING,NIL(Void_t*))) != 0)
|
||||
if(f->disc && (ex = SFRAISE(f,local ? SF_NEW : SF_CLOSING,NIL(void*))) != 0)
|
||||
SFMTXRETURN(f,ex);
|
||||
|
||||
if(!local && f->pool)
|
||||
|
|
@ -111,7 +106,7 @@ Sfio_t* f;
|
|||
else
|
||||
#endif
|
||||
if(f->flags&SF_MALLOC)
|
||||
data = (Void_t*)f->data;
|
||||
data = (void*)f->data;
|
||||
|
||||
f->data = NIL(uchar*);
|
||||
f->size = -1;
|
||||
|
|
@ -158,7 +153,7 @@ Sfio_t* f;
|
|||
}
|
||||
|
||||
if(!local)
|
||||
{ if(f->disc && (ex = SFRAISE(f,SF_FINAL,NIL(Void_t*))) != 0 )
|
||||
{ if(f->disc && (ex = SFRAISE(f,SF_FINAL,NIL(void*))) != 0 )
|
||||
{ rv = ex;
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -167,7 +162,7 @@ Sfio_t* f;
|
|||
free(f);
|
||||
else
|
||||
{ f->disc = NIL(Sfdisc_t*);
|
||||
f->stdio = NIL(Void_t*);
|
||||
f->stdio = NIL(void*);
|
||||
f->mode = SF_AVAIL;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,12 +28,7 @@
|
|||
**
|
||||
** Written by Kiem-Phong Vo
|
||||
*/
|
||||
#if __STD_C
|
||||
int sfclrlock(Sfio_t* f)
|
||||
#else
|
||||
int sfclrlock(f)
|
||||
Sfio_t *f;
|
||||
#endif
|
||||
{
|
||||
int rv;
|
||||
SFMTXDECL(f); /* declare a local stream variable for multithreading */
|
||||
|
|
|
|||
|
|
@ -109,20 +109,14 @@ static int neg0d(double f)
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#if __STD_C
|
||||
char* _sfcvt(Void_t* vp, char* buf, size_t size, int n_digit,
|
||||
int* decpt, int* sign, int* len, int format)
|
||||
#else
|
||||
char* _sfcvt(vp,buf,size,n_digit,decpt,sign,len,format)
|
||||
Void_t* vp; /* pointer to value to convert */
|
||||
char* buf; /* conversion goes here */
|
||||
size_t size; /* size of buf */
|
||||
int n_digit; /* number of digits wanted */
|
||||
int* decpt; /* to return decimal point */
|
||||
int* sign; /* to return sign */
|
||||
int* len; /* return string length */
|
||||
int format; /* conversion format */
|
||||
#endif
|
||||
char* _sfcvt(void* vp, /* pointer to value to convert */
|
||||
char* buf, /* conversion goes here */
|
||||
size_t size, /* size of buf */
|
||||
int n_digit, /* number of digits wanted */
|
||||
int* decpt, /* to return decimal point */
|
||||
int* sign, /* to return sign */
|
||||
int* len, /* return string length */
|
||||
int format) /* conversion format */
|
||||
{
|
||||
reg char *sp;
|
||||
reg long n, v;
|
||||
|
|
|
|||
|
|
@ -48,30 +48,14 @@ typedef struct _dccache_s
|
|||
uchar* endb;
|
||||
} Dccache_t;
|
||||
|
||||
#if __STD_C
|
||||
static int _dccaexcept(Sfio_t* f, int type, Void_t* val, Sfdisc_t* disc)
|
||||
#else
|
||||
static int _dccaexcept(f,type,val,disc)
|
||||
Sfio_t* f;
|
||||
int type;
|
||||
Void_t* val;
|
||||
Sfdisc_t* disc;
|
||||
#endif
|
||||
static int _dccaexcept(Sfio_t* f, int type, void* val, Sfdisc_t* disc)
|
||||
{
|
||||
if(disc && type == SF_FINAL)
|
||||
free(disc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
static ssize_t _dccaread(Sfio_t* f, Void_t* buf, size_t size, Sfdisc_t* disc)
|
||||
#else
|
||||
static ssize_t _dccaread(f, buf, size, disc)
|
||||
Sfio_t* f;
|
||||
Void_t* buf;
|
||||
size_t size;
|
||||
Sfdisc_t* disc;
|
||||
#endif
|
||||
static ssize_t _dccaread(Sfio_t* f, void* buf, size_t size, Sfdisc_t* disc)
|
||||
{
|
||||
ssize_t sz;
|
||||
Sfdisc_t *prev;
|
||||
|
|
@ -104,13 +88,7 @@ Sfdisc_t* disc;
|
|||
return sz;
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
Sfdisc_t* sfdisc(Sfio_t* f, Sfdisc_t* disc)
|
||||
#else
|
||||
Sfdisc_t* sfdisc(f,disc)
|
||||
Sfio_t* f;
|
||||
Sfdisc_t* disc;
|
||||
#endif
|
||||
{
|
||||
Sfdisc_t *d, *rdisc;
|
||||
Sfread_f oreadf;
|
||||
|
|
@ -201,7 +179,7 @@ Sfdisc_t* disc;
|
|||
disc = d->disc;
|
||||
if(d->exceptf)
|
||||
{ SFOPEN(f,0);
|
||||
if((*(d->exceptf))(f,SF_DPOP,(Void_t*)disc,d) < 0 )
|
||||
if((*(d->exceptf))(f,SF_DPOP,(void*)disc,d) < 0 )
|
||||
goto done;
|
||||
SFLOCK(f,0);
|
||||
}
|
||||
|
|
@ -215,7 +193,7 @@ Sfdisc_t* disc;
|
|||
d = f->disc;
|
||||
if(d && d->exceptf)
|
||||
{ SFOPEN(f,0);
|
||||
if( (*(d->exceptf))(f,SF_DPUSH,(Void_t*)disc,d) < 0 )
|
||||
if( (*(d->exceptf))(f,SF_DPUSH,(void*)disc,d) < 0 )
|
||||
goto done;
|
||||
SFLOCK(f,0);
|
||||
}
|
||||
|
|
@ -255,12 +233,12 @@ Sfdisc_t* disc;
|
|||
{ SETLOCAL(f);
|
||||
f->bits &= ~SF_NULL; /* turn off /dev/null handling */
|
||||
if((f->bits&SF_MMAP) || (f->mode&SF_INIT))
|
||||
sfsetbuf(f,NIL(Void_t*),(size_t)SF_UNBOUND);
|
||||
sfsetbuf(f,NIL(void*),(size_t)SF_UNBOUND);
|
||||
else if(f->data == f->tiny)
|
||||
sfsetbuf(f,NIL(Void_t*),0);
|
||||
sfsetbuf(f,NIL(void*),0);
|
||||
else
|
||||
{ int flags = f->flags;
|
||||
sfsetbuf(f,(Void_t*)f->data,f->size);
|
||||
sfsetbuf(f,(void*)f->data,f->size);
|
||||
f->flags |= (flags&SF_MALLOC);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,12 +27,7 @@
|
|||
** Written by Kiem-Phong Vo
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
int _sfdlen(Sfdouble_t v)
|
||||
#else
|
||||
int _sfdlen(v)
|
||||
Sfdouble_t v;
|
||||
#endif
|
||||
{
|
||||
#define N_ARRAY (16*sizeof(Sfdouble_t))
|
||||
reg int n, w;
|
||||
|
|
|
|||
|
|
@ -22,15 +22,10 @@
|
|||
***********************************************************************/
|
||||
#include "sfhdr.h"
|
||||
|
||||
#if __STD_C
|
||||
char* sfecvt(double dval, int n_digit, int* decpt, int* sign)
|
||||
#else
|
||||
char* sfecvt(dval,n_digit,decpt,sign)
|
||||
double dval; /* value to convert */
|
||||
int n_digit; /* number of digits wanted */
|
||||
int* decpt; /* to return decimal point */
|
||||
int* sign; /* to return sign */
|
||||
#endif
|
||||
char* sfecvt(double dval, /* value to convert */
|
||||
int n_digit, /* number of digits wanted */
|
||||
int* decpt, /* to return decimal point */
|
||||
int* sign) /* to return sign */
|
||||
{
|
||||
int len;
|
||||
static char buf[SF_MAXDIGITS];
|
||||
|
|
|
|||
|
|
@ -26,15 +26,10 @@
|
|||
** Written by Kiem-Phong Vo
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
int _sfexcept(Sfio_t* f, int type, ssize_t io, Sfdisc_t* disc)
|
||||
#else
|
||||
int _sfexcept(f,type,io,disc)
|
||||
Sfio_t* f; /* stream where the exception happened */
|
||||
int type; /* io type that was performed */
|
||||
ssize_t io; /* the io return value that indicated exception */
|
||||
Sfdisc_t* disc; /* discipline in use */
|
||||
#endif
|
||||
int _sfexcept(Sfio_t* f, /* stream where the exception happened */
|
||||
int type, /* io type that was performed */
|
||||
ssize_t io, /* the io return value that indicated exception */
|
||||
Sfdisc_t* disc) /* discipline in use */
|
||||
{
|
||||
reg int ev, local, lock;
|
||||
reg ssize_t size;
|
||||
|
|
|
|||
|
|
@ -42,17 +42,17 @@ static void _sfoncef()
|
|||
Sfextern_t _Sfextern =
|
||||
{ 0, /* _Sfpage */
|
||||
{ NIL(Sfpool_t*), 0, 0, 0, NIL(Sfio_t**) }, /* _Sfpool */
|
||||
NIL(int(*)_ARG_((Sfio_t*,int))), /* _Sfpmove */
|
||||
NIL(Sfio_t*(*)_ARG_((Sfio_t*, Sfio_t*))), /* _Sfstack */
|
||||
NIL(void(*)_ARG_((Sfio_t*, int, void*))), /* _Sfnotify */
|
||||
NIL(int(*)_ARG_((Sfio_t*))), /* _Sfstdsync */
|
||||
NIL(int(*)(Sfio_t*,int)), /* _Sfpmove */
|
||||
NIL(Sfio_t*(*)(Sfio_t*, Sfio_t*)), /* _Sfstack */
|
||||
NIL(void(*)(Sfio_t*, int, void*)), /* _Sfnotify */
|
||||
NIL(int(*)(Sfio_t*)), /* _Sfstdsync */
|
||||
{ NIL(Sfread_f), /* _Sfudisc */
|
||||
NIL(Sfwrite_f),
|
||||
NIL(Sfseek_f),
|
||||
NIL(Sfexcept_f),
|
||||
NIL(Sfdisc_t*)
|
||||
},
|
||||
NIL(void(*)_ARG_((void)) ), /* _Sfcleanup */
|
||||
NIL(void(*)(void)), /* _Sfcleanup */
|
||||
0, /* _Sfexiting */
|
||||
0, /* _Sfdone */
|
||||
&Sfonce, /* _Sfonce */
|
||||
|
|
|
|||
|
|
@ -22,15 +22,10 @@
|
|||
***********************************************************************/
|
||||
#include "sfhdr.h"
|
||||
|
||||
#if __STD_C
|
||||
char *sffcvt(double dval, int n_digit, int* decpt, int* sign)
|
||||
#else
|
||||
char *sffcvt(dval,n_digit,decpt,sign)
|
||||
double dval; /* value to convert */
|
||||
int n_digit; /* number of digits wanted */
|
||||
int* decpt; /* to return decimal point */
|
||||
int* sign; /* to return sign */
|
||||
#endif
|
||||
char *sffcvt(double dval, /* value to convert */
|
||||
int n_digit, /* number of digits wanted */
|
||||
int* decpt, /* to return decimal point */
|
||||
int* sign) /* to return sign */
|
||||
{
|
||||
int len;
|
||||
static char buf[SF_MAXDIGITS];
|
||||
|
|
|
|||
|
|
@ -32,13 +32,8 @@
|
|||
** Written by Kiem-Phong Vo
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
int _sffilbuf(Sfio_t* f, reg int n)
|
||||
#else
|
||||
int _sffilbuf(f,n)
|
||||
Sfio_t* f; /* fill the read buffer of this stream */
|
||||
reg int n; /* see above */
|
||||
#endif
|
||||
int _sffilbuf(Sfio_t* f, /* fill the read buffer of this stream */
|
||||
reg int n) /* see above */
|
||||
{
|
||||
reg ssize_t r;
|
||||
reg int first, local, rcrv, rc, justseek;
|
||||
|
|
|
|||
|
|
@ -28,13 +28,8 @@
|
|||
** Written by Kiem-Phong Vo
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
int _sfflsbuf(Sfio_t* f, int c)
|
||||
#else
|
||||
int _sfflsbuf(f,c)
|
||||
Sfio_t* f; /* write out the buffered content of this stream */
|
||||
int c; /* if c>=0, c is also written out */
|
||||
#endif
|
||||
int _sfflsbuf(Sfio_t* f, /* write out the buffered content of this stream */
|
||||
int c) /* if c>=0, c is also written out */
|
||||
{
|
||||
ssize_t n, w, written;
|
||||
uchar* data;
|
||||
|
|
|
|||
|
|
@ -27,12 +27,7 @@
|
|||
** Written by Kiem-Phong Vo
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
Sfdouble_t sfgetd(Sfio_t* f)
|
||||
#else
|
||||
Sfdouble_t sfgetd(f)
|
||||
Sfio_t* f;
|
||||
#endif
|
||||
{
|
||||
reg uchar *s, *ends, c;
|
||||
reg int p, sign, exp;
|
||||
|
|
|
|||
|
|
@ -27,12 +27,7 @@
|
|||
** Written by Kiem-Phong Vo
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
Sflong_t sfgetl(Sfio_t* f)
|
||||
#else
|
||||
Sflong_t sfgetl(f)
|
||||
Sfio_t* f;
|
||||
#endif
|
||||
{
|
||||
Sflong_t v;
|
||||
uchar *s, *ends, c;
|
||||
|
|
|
|||
|
|
@ -27,13 +27,7 @@
|
|||
** Written by Kiem-Phong Vo
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
Sfulong_t sfgetm(Sfio_t* f, Sfulong_t m)
|
||||
#else
|
||||
Sfulong_t sfgetm(f, m)
|
||||
Sfio_t* f;
|
||||
Sfulong_t m;
|
||||
#endif
|
||||
{
|
||||
Sfulong_t v;
|
||||
reg uchar *s, *ends, c;
|
||||
|
|
|
|||
|
|
@ -28,14 +28,9 @@
|
|||
** Written by Kiem-Phong Vo
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
char* sfgetr(Sfio_t *f, int rc, int type)
|
||||
#else
|
||||
char* sfgetr(f,rc,type)
|
||||
Sfio_t* f; /* stream to read from */
|
||||
int rc; /* record separator */
|
||||
int type;
|
||||
#endif
|
||||
char* sfgetr(Sfio_t* f, /* stream to read from */
|
||||
int rc, /* record separator */
|
||||
int type)
|
||||
{
|
||||
ssize_t n, un;
|
||||
uchar *s, *ends, *us;
|
||||
|
|
|
|||
|
|
@ -27,12 +27,7 @@
|
|||
** Written by Kiem-Phong Vo
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
Sfulong_t sfgetu(Sfio_t* f)
|
||||
#else
|
||||
Sfulong_t sfgetu(f)
|
||||
Sfio_t* f;
|
||||
#endif
|
||||
{
|
||||
Sfulong_t v;
|
||||
uchar *s, *ends, c;
|
||||
|
|
|
|||
|
|
@ -69,9 +69,6 @@
|
|||
#include <varargs.h>
|
||||
#endif
|
||||
#include "FEATURE/common"
|
||||
#if !__STD_C
|
||||
#define const
|
||||
#endif
|
||||
#endif /* !_PACKAGE_ast */
|
||||
|
||||
#include "sfio_t.h"
|
||||
|
|
@ -374,7 +371,7 @@
|
|||
{ (_mf_) = (ff); \
|
||||
if(sfmutex((ff), SFMTX_LOCK) != 0) return(rv); \
|
||||
if(_Sfnotify) \
|
||||
{ (*_Sfnotify)((_mf_), SF_MTACCESS, (Void_t*)(&(ff)) ); \
|
||||
{ (*_Sfnotify)((_mf_), SF_MTACCESS, (void*)(&(ff)) ); \
|
||||
if(!(ff)) (ff) = (_mf_); \
|
||||
} \
|
||||
} \
|
||||
|
|
@ -382,7 +379,7 @@
|
|||
#define SFMTXend(ff,_mf_) \
|
||||
{ if((ff)->_flags&SF_MTSAFE) \
|
||||
{ if(_Sfnotify) \
|
||||
(*_Sfnotify)((_mf_), SF_MTACCESS, NIL(Void_t*) ); \
|
||||
(*_Sfnotify)((_mf_), SF_MTACCESS, NIL(void*) ); \
|
||||
sfmutex((ff), SFMTX_UNLOCK); \
|
||||
(ff) = (_mf_); \
|
||||
} \
|
||||
|
|
@ -483,11 +480,7 @@
|
|||
#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 */
|
||||
#define SF_MMAP 00000001 /* in memory mapping mode */
|
||||
|
|
@ -713,7 +706,7 @@ typedef union
|
|||
#endif
|
||||
char c, *s, **sp;
|
||||
uchar uc, *us, **usp;
|
||||
Void_t *vp;
|
||||
void *vp;
|
||||
Sffmt_t *ft;
|
||||
} Argv_t;
|
||||
|
||||
|
|
@ -779,7 +772,7 @@ struct _fmtpos_s
|
|||
#define SFFMT_CLASS 040 /* %[ */
|
||||
|
||||
/* local variables used across sf-functions */
|
||||
typedef void (*Sfnotify_f)_ARG_((Sfio_t*, int, void*));
|
||||
typedef void (*Sfnotify_f)(Sfio_t*, int, void*);
|
||||
#define _Sfpage (_Sfextern.sf_page)
|
||||
#define _Sfpool (_Sfextern.sf_pool)
|
||||
#define _Sfpmove (_Sfextern.sf_pmove)
|
||||
|
|
@ -796,16 +789,16 @@ typedef void (*Sfnotify_f)_ARG_((Sfio_t*, int, void*));
|
|||
typedef struct _sfextern_s
|
||||
{ ssize_t sf_page;
|
||||
struct _sfpool_s sf_pool;
|
||||
int (*sf_pmove)_ARG_((Sfio_t*, int));
|
||||
Sfio_t* (*sf_stack)_ARG_((Sfio_t*, Sfio_t*));
|
||||
void (*sf_notify)_ARG_((Sfio_t*, int, void*));
|
||||
int (*sf_stdsync)_ARG_((Sfio_t*));
|
||||
int (*sf_pmove)(Sfio_t*, int);
|
||||
Sfio_t* (*sf_stack)(Sfio_t*, Sfio_t*);
|
||||
void (*sf_notify)(Sfio_t*, int, void*);
|
||||
int (*sf_stdsync)(Sfio_t*);
|
||||
struct _sfdisc_s sf_udisc;
|
||||
void (*sf_cleanup)_ARG_((void));
|
||||
void (*sf_cleanup)(void);
|
||||
int sf_exiting;
|
||||
int sf_done;
|
||||
Vtonce_t* sf_once;
|
||||
void (*sf_oncef)_ARG_((void));
|
||||
void (*sf_oncef)(void);
|
||||
Vtmutex_t* sf_mutex;
|
||||
} Sfextern_t;
|
||||
|
||||
|
|
@ -885,8 +878,8 @@ typedef struct _sfextern_s
|
|||
#define SFISALL(f,v) ((((v) = (f)->mode&SF_RV) ? ((f)->mode &= ~SF_RV) : 0), \
|
||||
((v) || ((f)->flags&(SF_SHARE|SF_APPENDWR|SF_WHOLE)) ) )
|
||||
#define SFSK(f,a,o,d) (SETLOCAL(f),sfsk(f,(Sfoff_t)a,o,d))
|
||||
#define SFRD(f,b,n,d) (SETLOCAL(f),sfrd(f,(Void_t*)b,n,d))
|
||||
#define SFWR(f,b,n,d) (SETLOCAL(f),sfwr(f,(Void_t*)b,n,d))
|
||||
#define SFRD(f,b,n,d) (SETLOCAL(f),sfrd(f,(void*)b,n,d))
|
||||
#define SFWR(f,b,n,d) (SETLOCAL(f),sfwr(f,(void*)b,n,d))
|
||||
#define SFSYNC(f) (SETLOCAL(f),sfsync(f))
|
||||
#define SFCLOSE(f) (SETLOCAL(f),sfclose(f))
|
||||
#define SFFLSBUF(f,n) (SETLOCAL(f),_sfflsbuf(f,n))
|
||||
|
|
@ -1049,8 +1042,8 @@ typedef struct _sftab_
|
|||
char* sf_digits; /* digits for general bases */
|
||||
int (*sf_cvinitf)(); /* initialization function */
|
||||
int sf_cvinit; /* initialization state */
|
||||
Fmtpos_t* (*sf_fmtposf)_ARG_((Sfio_t*,const char*,va_list,Sffmt_t*,int));
|
||||
char* (*sf_fmtintf)_ARG_((const char*,int*));
|
||||
Fmtpos_t* (*sf_fmtposf)(Sfio_t*,const char*,va_list,Sffmt_t*,int);
|
||||
char* (*sf_fmtintf)(const char*,int*);
|
||||
float* sf_flt_pow10; /* float powers of 10 */
|
||||
double* sf_dbl_pow10; /* double powers of 10 */
|
||||
Sfdouble_t* sf_ldbl_pow10; /* Sfdouble_t powers of 10 */
|
||||
|
|
@ -1132,7 +1125,7 @@ typedef struct _sftab_
|
|||
/* note that MEMCPY advances the associated pointers */
|
||||
#define MEMCPY(to,fr,n) \
|
||||
switch(n) \
|
||||
{ default : memcpy((Void_t*)to,(Void_t*)fr,n); to += n; fr += n; break; \
|
||||
{ default : memcpy((void*)to,(void*)fr,n); to += n; fr += n; break; \
|
||||
case 7 : *to++ = *fr++; \
|
||||
/* FALLTHROUGH */ \
|
||||
case 6 : *to++ = *fr++; \
|
||||
|
|
@ -1149,7 +1142,7 @@ typedef struct _sftab_
|
|||
}
|
||||
#define MEMSET(s,c,n) \
|
||||
switch(n) \
|
||||
{ default : memset((Void_t*)s,(int)c,n); s += n; break; \
|
||||
{ default : memset((void*)s,(int)c,n); s += n; break; \
|
||||
case 7 : *s++ = c; \
|
||||
/* FALLTHROUGH */ \
|
||||
case 6 : *s++ = c; \
|
||||
|
|
@ -1165,17 +1158,15 @@ typedef struct _sftab_
|
|||
case 1 : *s++ = c; \
|
||||
}
|
||||
|
||||
_BEGIN_EXTERNS_
|
||||
|
||||
extern Sftab_t _Sftable;
|
||||
|
||||
extern int _sfpopen _ARG_((Sfio_t*, int, int, int));
|
||||
extern int _sfpclose _ARG_((Sfio_t*));
|
||||
extern int _sfexcept _ARG_((Sfio_t*, int, ssize_t, Sfdisc_t*));
|
||||
extern Sfrsrv_t* _sfrsrv _ARG_((Sfio_t*, ssize_t));
|
||||
extern int _sfsetpool _ARG_((Sfio_t*));
|
||||
extern char* _sfcvt _ARG_((Void_t*,char*,size_t,int,int*,int*,int*,int));
|
||||
extern char** _sfgetpath _ARG_((char*));
|
||||
extern int _sfpopen(Sfio_t*, int, int, int);
|
||||
extern int _sfpclose(Sfio_t*);
|
||||
extern int _sfexcept(Sfio_t*, int, ssize_t, Sfdisc_t*);
|
||||
extern Sfrsrv_t* _sfrsrv(Sfio_t*, ssize_t);
|
||||
extern int _sfsetpool(Sfio_t*);
|
||||
extern char* _sfcvt(void*,char*,size_t,int,int*,int*,int*,int);
|
||||
extern char** _sfgetpath(char*);
|
||||
|
||||
#if _BLD_sfio && defined(__EXPORT__)
|
||||
#define extern __EXPORT__
|
||||
|
|
@ -1186,8 +1177,8 @@ extern char** _sfgetpath _ARG_((char*));
|
|||
|
||||
extern Sfextern_t _Sfextern;
|
||||
|
||||
extern int _sfmode _ARG_((Sfio_t*, int, int));
|
||||
extern int _sftype _ARG_((const char*, int*, int*, int*));
|
||||
extern int _sfmode(Sfio_t*, int, int);
|
||||
extern int _sftype(const char*, int*, int*, int*);
|
||||
|
||||
#undef extern
|
||||
|
||||
|
|
@ -1201,7 +1192,7 @@ extern int errno;
|
|||
#define frexpl frexp
|
||||
#endif
|
||||
#if !_lib_frexpl
|
||||
extern Sfdouble_t frexpl _ARG_((Sfdouble_t, int*));
|
||||
extern Sfdouble_t frexpl(Sfdouble_t, int*);
|
||||
#endif
|
||||
#endif
|
||||
#ifndef ldexpl
|
||||
|
|
@ -1209,95 +1200,90 @@ extern Sfdouble_t frexpl _ARG_((Sfdouble_t, int*));
|
|||
#define ldexpl ldexp
|
||||
#endif
|
||||
#if !_lib_ldexpl
|
||||
extern Sfdouble_t ldexpl _ARG_((Sfdouble_t, int));
|
||||
extern Sfdouble_t ldexpl(Sfdouble_t, int);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !_PACKAGE_ast
|
||||
|
||||
#if !__STDC__ && !_hdr_stdlib
|
||||
extern void abort _ARG_((void));
|
||||
extern int atexit _ARG_((void(*)(void)));
|
||||
extern char* getenv _ARG_((const char*));
|
||||
extern void* malloc _ARG_((size_t));
|
||||
extern void* realloc _ARG_((void*, size_t));
|
||||
extern void free _ARG_((void*));
|
||||
extern size_t strlen _ARG_((const char*));
|
||||
extern char* strcpy _ARG_((char*, const char*));
|
||||
extern void abort(void);
|
||||
extern int atexit(void(*)(void));
|
||||
extern char* getenv(const char*);
|
||||
extern void* malloc(size_t);
|
||||
extern void* realloc(void*, size_t);
|
||||
extern void free(void*);
|
||||
extern size_t strlen(const char*);
|
||||
extern char* strcpy(char*, const char*);
|
||||
|
||||
extern Void_t* memset _ARG_((void*, int, size_t));
|
||||
extern Void_t* memchr _ARG_((const void*, int, size_t));
|
||||
extern Void_t* memccpy _ARG_((void*, const void*, int, size_t));
|
||||
extern void* memset(void*, int, size_t);
|
||||
extern void* memchr(const void*, int, size_t);
|
||||
extern void* memccpy(void*, const void*, int, size_t);
|
||||
#ifndef memcpy
|
||||
extern Void_t* memcpy _ARG_((void*, const void*, size_t));
|
||||
extern void* memcpy(void*, const void*, size_t);
|
||||
#endif
|
||||
#if !defined(strtod)
|
||||
extern double strtod _ARG_((const char*, char**));
|
||||
extern double strtod(const char*, char**);
|
||||
#endif
|
||||
#if !defined(remove)
|
||||
extern int sysremovef _ARG_((const char*));
|
||||
extern int sysremovef(const char*);
|
||||
#endif
|
||||
#endif /* !__STDC__ && !_hdr_stdlib */
|
||||
|
||||
#if !_hdr_unistd
|
||||
#if _proto_open && __cplusplus
|
||||
extern int sysopenf _ARG_((const char*, int, ...));
|
||||
#endif
|
||||
extern int sysclosef _ARG_((int));
|
||||
extern ssize_t sysreadf _ARG_((int, void*, size_t));
|
||||
extern ssize_t syswritef _ARG_((int, const void*, size_t));
|
||||
extern sfoff_t syslseekf _ARG_((int, sfoff_t, int));
|
||||
extern int sysdupf _ARG_((int));
|
||||
extern int syspipef _ARG_((int*));
|
||||
extern int sysaccessf _ARG_((const char*, int));
|
||||
extern int sysremovef _ARG_((const char*));
|
||||
extern int sysfstatf _ARG_((int, sfstat_t*));
|
||||
extern int sysstatf _ARG_((const char*, sfstat_t*));
|
||||
extern int sysclosef(int);
|
||||
extern ssize_t sysreadf(int, void*, size_t);
|
||||
extern ssize_t syswritef(int, const void*, size_t);
|
||||
extern sfoff_t syslseekf(int, sfoff_t, int);
|
||||
extern int sysdupf(int);
|
||||
extern int syspipef(int*);
|
||||
extern int sysaccessf(const char*, int);
|
||||
extern int sysremovef(const char*);
|
||||
extern int sysfstatf(int, sfstat_t*);
|
||||
extern int sysstatf(const char*, sfstat_t*);
|
||||
|
||||
extern int isatty _ARG_((int));
|
||||
extern int isatty(int);
|
||||
|
||||
extern int wait _ARG_((int*));
|
||||
extern uint sleep _ARG_((uint));
|
||||
extern int execl _ARG_((const char*, const char*,...));
|
||||
extern int execv _ARG_((const char*, char**));
|
||||
extern int wait(int*);
|
||||
extern uint sleep(uint);
|
||||
extern int execl(const char*, const char*,...);
|
||||
extern int execv(const char*, char**);
|
||||
#if !defined(fork)
|
||||
extern int fork _ARG_((void));
|
||||
extern int fork(void);
|
||||
#endif
|
||||
#if _lib_unlink
|
||||
extern int unlink _ARG_((const char*));
|
||||
extern int unlink(const char*);
|
||||
#endif
|
||||
|
||||
#endif /*_hdr_unistd*/
|
||||
|
||||
#if _lib_bcopy && !_proto_bcopy
|
||||
extern void bcopy _ARG_((const void*, void*, size_t));
|
||||
extern void bcopy(const void*, void*, size_t);
|
||||
#endif
|
||||
#if _lib_bzero && !_proto_bzero
|
||||
extern void bzero _ARG_((void*, size_t));
|
||||
extern void bzero(void*, size_t);
|
||||
#endif
|
||||
|
||||
extern time_t time _ARG_((time_t*));
|
||||
extern int waitpid _ARG_((int,int*,int));
|
||||
extern void _exit _ARG_((int));
|
||||
typedef int(* Onexit_f)_ARG_((void));
|
||||
extern Onexit_f onexit _ARG_((Onexit_f));
|
||||
extern time_t time(time_t*);
|
||||
extern int waitpid(int,int*,int);
|
||||
extern void _exit(int);
|
||||
typedef int(* Onexit_f)(void);
|
||||
extern Onexit_f onexit(Onexit_f);
|
||||
|
||||
#if _lib_vfork && !_hdr_vfork && !_sys_vfork
|
||||
extern pid_t vfork _ARG_((void));
|
||||
extern pid_t vfork(void);
|
||||
#endif /*_lib_vfork*/
|
||||
|
||||
#if _lib_poll
|
||||
#if _lib_poll_fd_1
|
||||
extern int poll _ARG_((struct pollfd*, ulong, int));
|
||||
extern int poll(struct pollfd*, ulong, int);
|
||||
#else
|
||||
extern int poll _ARG_((ulong, struct pollfd*, int));
|
||||
extern int poll(ulong, struct pollfd*, int);
|
||||
#endif
|
||||
#endif /*_lib_poll*/
|
||||
|
||||
#endif /* _PACKAGE_ast */
|
||||
|
||||
_END_EXTERNS_
|
||||
|
||||
#ifdef _SF_HIDESFFLAGS
|
||||
#undef SFIO_FLAGS
|
||||
#define SFIO_FLAGS 0177177 /* PUBLIC FLAGS PASSABLE TO SFNEW() */
|
||||
|
|
|
|||
|
|
@ -26,12 +26,7 @@
|
|||
**
|
||||
** Written by Kiem-Phong Vo
|
||||
*/
|
||||
#if __STD_C
|
||||
int _sfllen(Sflong_t v)
|
||||
#else
|
||||
int _sfllen(v)
|
||||
Sflong_t v;
|
||||
#endif
|
||||
{
|
||||
if(v < 0)
|
||||
v = -(v+1);
|
||||
|
|
|
|||
|
|
@ -57,16 +57,12 @@ static char* Version = "\n@(#)$Id: sfio (AT&T Labs - Research) 2009-09-15 $\0\n"
|
|||
#define Sfsignal_f Sig_handler_t
|
||||
#else
|
||||
#include <signal.h>
|
||||
typedef void(* Sfsignal_f)_ARG_((int));
|
||||
typedef void(* Sfsignal_f)(int);
|
||||
#endif
|
||||
static int _Sfsigp = 0; /* # of streams needing SIGPIPE protection */
|
||||
|
||||
/* done at exiting time */
|
||||
#if __STD_C
|
||||
static void _sfcleanup(void)
|
||||
#else
|
||||
static void _sfcleanup()
|
||||
#endif
|
||||
{
|
||||
reg Sfpool_t* p;
|
||||
reg Sfio_t* f;
|
||||
|
|
@ -89,7 +85,7 @@ static void _sfcleanup()
|
|||
SFMTXLOCK(f);
|
||||
|
||||
/* let application know that we are leaving */
|
||||
(void)SFRAISE(f, SF_ATEXIT, NIL(Void_t*));
|
||||
(void)SFRAISE(f, SF_ATEXIT, NIL(void*));
|
||||
|
||||
if(f->flags&SF_STRING)
|
||||
continue;
|
||||
|
|
@ -102,7 +98,7 @@ static void _sfcleanup()
|
|||
if(f->data &&
|
||||
((f->bits&SF_MMAP) ||
|
||||
((f->mode&SF_WRITE) && f->next == f->data) ) )
|
||||
(void)SFSETBUF(f,NIL(Void_t*),0);
|
||||
(void)SFSETBUF(f,NIL(void*),0);
|
||||
f->mode |= pool;
|
||||
|
||||
SFMTXUNLOCK(f);
|
||||
|
|
@ -112,12 +108,7 @@ static void _sfcleanup()
|
|||
}
|
||||
|
||||
/* put into discrete pool */
|
||||
#if __STD_C
|
||||
int _sfsetpool(Sfio_t* f)
|
||||
#else
|
||||
int _sfsetpool(f)
|
||||
Sfio_t* f;
|
||||
#endif
|
||||
{
|
||||
reg Sfpool_t* p;
|
||||
reg Sfio_t** array;
|
||||
|
|
@ -146,9 +137,9 @@ Sfio_t* f;
|
|||
goto done;
|
||||
|
||||
/* move old array to new one */
|
||||
memcpy((Void_t*)array,(Void_t*)p->sf,p->n_sf*sizeof(Sfio_t*));
|
||||
memcpy((void*)array,(void*)p->sf,p->n_sf*sizeof(Sfio_t*));
|
||||
if(p->sf != p->array)
|
||||
free((Void_t*)p->sf);
|
||||
free((void*)p->sf);
|
||||
|
||||
p->sf = array;
|
||||
p->s_sf = n;
|
||||
|
|
@ -166,13 +157,7 @@ done:
|
|||
}
|
||||
|
||||
/* create an auxiliary buffer for sfgetr/sfreserve/sfputr */
|
||||
#if __STD_C
|
||||
Sfrsrv_t* _sfrsrv(reg Sfio_t* f, reg ssize_t size)
|
||||
#else
|
||||
Sfrsrv_t* _sfrsrv(f,size)
|
||||
reg Sfio_t* f;
|
||||
reg ssize_t size;
|
||||
#endif
|
||||
{
|
||||
Sfrsrv_t *rsrv, *rs;
|
||||
|
||||
|
|
@ -200,26 +185,13 @@ reg ssize_t size;
|
|||
}
|
||||
|
||||
#ifdef SIGPIPE
|
||||
#if __STD_C
|
||||
static void ignoresig(int sig)
|
||||
#else
|
||||
static void ignoresig(sig)
|
||||
int sig;
|
||||
#endif
|
||||
{
|
||||
signal(sig, ignoresig);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if __STD_C
|
||||
int _sfpopen(reg Sfio_t* f, int fd, int pid, int stdio)
|
||||
#else
|
||||
int _sfpopen(f, fd, pid, stdio)
|
||||
reg Sfio_t* f;
|
||||
int fd;
|
||||
int pid;
|
||||
int stdio; /* stdio popen() does not reset SIGPIPE handler */
|
||||
#endif
|
||||
int _sfpopen(reg Sfio_t* f, int fd, int pid, int stdio) /* stdio popen() does not reset SIGPIPE handler */
|
||||
{
|
||||
reg Sfproc_t* p;
|
||||
|
||||
|
|
@ -251,12 +223,7 @@ int stdio; /* stdio popen() does not reset SIGPIPE handler */
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
int _sfpclose(reg Sfio_t* f)
|
||||
#else
|
||||
int _sfpclose(f)
|
||||
reg Sfio_t* f; /* stream to close */
|
||||
#endif
|
||||
{
|
||||
Sfproc_t* p;
|
||||
int status;
|
||||
|
|
@ -308,13 +275,7 @@ reg Sfio_t* f; /* stream to close */
|
|||
return status;
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
static int _sfpmode(Sfio_t* f, int type)
|
||||
#else
|
||||
static int _sfpmode(f,type)
|
||||
Sfio_t* f;
|
||||
int type;
|
||||
#endif
|
||||
{
|
||||
Sfproc_t* p;
|
||||
|
||||
|
|
@ -335,7 +296,7 @@ int type;
|
|||
}
|
||||
}
|
||||
if(p->ndata > 0)
|
||||
memcpy((Void_t*)p->rdata,(Void_t*)f->next,p->ndata);
|
||||
memcpy((void*)p->rdata,(void*)f->next,p->ndata);
|
||||
f->endb = f->data;
|
||||
}
|
||||
else
|
||||
|
|
@ -343,7 +304,7 @@ int type;
|
|||
if(p->ndata > f->size) /* may lose data!!! */
|
||||
p->ndata = f->size;
|
||||
if(p->ndata > 0)
|
||||
{ memcpy((Void_t*)f->data,(Void_t*)p->rdata,p->ndata);
|
||||
{ memcpy((void*)f->data,(void*)p->rdata,p->ndata);
|
||||
f->endb = f->data+p->ndata;
|
||||
p->ndata = 0;
|
||||
}
|
||||
|
|
@ -359,14 +320,9 @@ int type;
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
int _sfmode(reg Sfio_t* f, reg int wanted, reg int local)
|
||||
#else
|
||||
int _sfmode(f, wanted, local)
|
||||
reg Sfio_t* f; /* change r/w mode and sync file pointer for this stream */
|
||||
reg int wanted; /* desired mode */
|
||||
reg int local; /* a local call */
|
||||
#endif
|
||||
int _sfmode(reg Sfio_t* f, /* change r/w mode and sync file pointer for this stream */
|
||||
reg int wanted, /* desired mode */
|
||||
reg int local) /* a local call */
|
||||
{
|
||||
reg int n;
|
||||
Sfoff_t addr;
|
||||
|
|
@ -412,7 +368,7 @@ reg int local; /* a local call */
|
|||
f->tiny[0]++;
|
||||
if(((f->tiny[0]<<8)|f->ngetr) >= (4*SF_NMAP) )
|
||||
{ /* turn off mmap to avoid page faulting */
|
||||
sfsetbuf(f,(Void_t*)f->tiny,(size_t)SF_UNBOUND);
|
||||
sfsetbuf(f,(void*)f->tiny,(size_t)SF_UNBOUND);
|
||||
f->ngetr = f->tiny[0] = 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -572,7 +528,7 @@ reg int local; /* a local call */
|
|||
if(f->bits&SF_MMAP)
|
||||
{ if(f->data)
|
||||
SFMUNMAP(f,f->data,f->endb-f->data);
|
||||
(void)SFSETBUF(f,(Void_t*)f->tiny,(size_t)SF_UNBOUND);
|
||||
(void)SFSETBUF(f,(void*)f->tiny,(size_t)SF_UNBOUND);
|
||||
}
|
||||
#endif
|
||||
if(f->data == f->tiny)
|
||||
|
|
|
|||
|
|
@ -31,15 +31,10 @@
|
|||
*/
|
||||
#define MAX_SSIZE ((ssize_t)((~((size_t)0)) >> 1))
|
||||
|
||||
#if __STD_C
|
||||
Sfoff_t sfmove(Sfio_t* fr, Sfio_t* fw, Sfoff_t n, reg int rc)
|
||||
#else
|
||||
Sfoff_t sfmove(fr,fw,n,rc)
|
||||
Sfio_t* fr; /* moving data from this stream */
|
||||
Sfio_t* fw; /* moving data to this stream */
|
||||
Sfoff_t n; /* number of bytes/records to move. <0 for unbounded move */
|
||||
reg int rc; /* record separator */
|
||||
#endif
|
||||
Sfoff_t sfmove(Sfio_t* fr, /* moving data from this stream */
|
||||
Sfio_t* fw, /* moving data to this stream */
|
||||
Sfoff_t n, /* number of bytes/records to move. <0 for unbounded move */
|
||||
reg int rc) /* record separator */
|
||||
{
|
||||
reg uchar *cp, *next;
|
||||
reg ssize_t r, w;
|
||||
|
|
@ -195,7 +190,7 @@ reg int rc; /* record separator */
|
|||
{ /* move leftover to read stream */
|
||||
if(w > fr->size)
|
||||
w = fr->size;
|
||||
memmove((Void_t*)fr->data,(Void_t*)cp,w);
|
||||
memmove((void*)fr->data,(void*)cp,w);
|
||||
fr->endb = fr->data+w;
|
||||
if((w = endb - (cp+w)) > 0)
|
||||
(void)SFSK(fr,(Sfoff_t)(-w),SEEK_CUR,fr->disc);
|
||||
|
|
@ -205,10 +200,10 @@ reg int rc; /* record separator */
|
|||
{ if(direct == SF_WRITE)
|
||||
fw->next += r;
|
||||
else if(r <= (fw->endb-fw->next) )
|
||||
{ memmove((Void_t*)fw->next,(Void_t*)next,r);
|
||||
{ memmove((void*)fw->next,(void*)next,r);
|
||||
fw->next += r;
|
||||
}
|
||||
else if((w = SFWRITE(fw,(Void_t*)next,r)) != r)
|
||||
else if((w = SFWRITE(fw,(void*)next,r)) != r)
|
||||
{ /* a write error happened */
|
||||
if(w > 0)
|
||||
{ r -= w;
|
||||
|
|
|
|||
|
|
@ -28,13 +28,7 @@
|
|||
*/
|
||||
|
||||
/* the main locking/unlocking interface */
|
||||
#if __STD_C
|
||||
int sfmutex(Sfio_t* f, int type)
|
||||
#else
|
||||
int sfmutex(f, type)
|
||||
Sfio_t* f;
|
||||
int type;
|
||||
#endif
|
||||
{
|
||||
#if !vt_threaded
|
||||
NOTUSED(f); NOTUSED(type);
|
||||
|
|
|
|||
|
|
@ -29,16 +29,11 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
Sfio_t* sfnew(Sfio_t* oldf, Void_t* buf, size_t size, int file, int flags)
|
||||
#else
|
||||
Sfio_t* sfnew(oldf,buf,size,file,flags)
|
||||
Sfio_t* oldf; /* old stream to be reused */
|
||||
Void_t* buf; /* a buffer to read/write, if NULL, will be allocated */
|
||||
size_t size; /* buffer size if buf is given or desired buffer size */
|
||||
int file; /* file descriptor to read/write from */
|
||||
int flags; /* type of file stream */
|
||||
#endif
|
||||
Sfio_t* sfnew(Sfio_t* oldf, /* old stream to be reused */
|
||||
void* buf, /* a buffer to read/write, if NULL, will be allocated */
|
||||
size_t size, /* buffer size if buf is given or desired buffer size */
|
||||
int file, /* file descriptor to read/write from */
|
||||
int flags) /* type of file stream */
|
||||
{
|
||||
reg Sfio_t* f;
|
||||
reg int sflags;
|
||||
|
|
@ -73,7 +68,7 @@ int flags; /* type of file stream */
|
|||
|
||||
if(f->data && ((flags&SF_STRING) || size != (size_t)SF_UNBOUND) )
|
||||
{ if(sflags&SF_MALLOC)
|
||||
free((Void_t*)f->data);
|
||||
free((void*)f->data);
|
||||
f->data = NIL(uchar*);
|
||||
}
|
||||
if(!f->data)
|
||||
|
|
|
|||
|
|
@ -27,12 +27,7 @@
|
|||
**
|
||||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
#if __STD_C
|
||||
int sfnotify(void(*notify)(Sfio_t*, int, void*))
|
||||
#else
|
||||
int sfnotify(notify)
|
||||
void (*notify)();
|
||||
#endif
|
||||
{
|
||||
_Sfnotify = notify;
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -27,14 +27,9 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
ssize_t sfnputc(Sfio_t* f, int c, size_t n)
|
||||
#else
|
||||
ssize_t sfnputc(f,c,n)
|
||||
Sfio_t* f; /* file to write */
|
||||
int c; /* char to be written */
|
||||
size_t n; /* number of time to repeat */
|
||||
#endif
|
||||
ssize_t sfnputc(Sfio_t* f, /* file to write */
|
||||
int c, /* char to be written */
|
||||
size_t n) /* number of time to repeat */
|
||||
{
|
||||
reg uchar* ps;
|
||||
reg ssize_t p, w;
|
||||
|
|
@ -69,7 +64,7 @@ size_t n; /* number of time to repeat */
|
|||
|
||||
for(;;)
|
||||
{ /* hard write of data */
|
||||
if((p = SFWRITE(f,(Void_t*)ps,p)) <= 0 || (n -= p) <= 0)
|
||||
if((p = SFWRITE(f,(void*)ps,p)) <= 0 || (n -= p) <= 0)
|
||||
{ w -= n;
|
||||
goto done;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,16 +26,11 @@
|
|||
* _sfopen() wrapper to allow user sfopen() intercept
|
||||
*/
|
||||
|
||||
extern Sfio_t* _sfopen _ARG_((Sfio_t*, const char*, const char*));
|
||||
extern Sfio_t* _sfopen(Sfio_t*, const char*, const char*);
|
||||
|
||||
#if __STD_C
|
||||
Sfio_t* sfopen(Sfio_t* f, const char* file, const char* mode)
|
||||
#else
|
||||
Sfio_t* sfopen(f,file,mode)
|
||||
Sfio_t* f; /* old stream structure */
|
||||
char* file; /* file/string to be opened */
|
||||
reg char* mode; /* mode of the stream */
|
||||
#endif
|
||||
Sfio_t* sfopen(Sfio_t* f, /* old stream structure */
|
||||
const char* file, /* file/string to be opened */
|
||||
reg const char* mode) /* mode of the stream */
|
||||
{
|
||||
return _sfopen(f, file, mode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,14 +32,9 @@
|
|||
#define extern __EXPORT__
|
||||
#endif
|
||||
|
||||
#if __STD_C
|
||||
extern ssize_t sfpeek(reg Sfio_t* f, Void_t** bp, reg size_t size)
|
||||
#else
|
||||
extern ssize_t sfpeek(f,bp,size)
|
||||
reg Sfio_t* f; /* file to peek */
|
||||
Void_t** bp; /* start of data area */
|
||||
reg size_t size; /* size of peek */
|
||||
#endif
|
||||
extern ssize_t sfpeek(reg Sfio_t* f, /* file to peek */
|
||||
void** bp, /* start of data area */
|
||||
reg size_t size) /* size of peek */
|
||||
{ reg ssize_t n, sz;
|
||||
reg int mode;
|
||||
|
||||
|
|
@ -57,7 +52,7 @@ reg size_t size; /* size of peek */
|
|||
if(!bp)
|
||||
return n;
|
||||
else if(n > 0) /* size == 0 */
|
||||
{ *bp = (Void_t*)f->next;
|
||||
{ *bp = (void*)f->next;
|
||||
return 0;
|
||||
}
|
||||
/* else fall down and fill buffer */
|
||||
|
|
@ -74,7 +69,7 @@ reg size_t size; /* size of peek */
|
|||
return sz;
|
||||
|
||||
if((n = sfvalue(f)) > 0)
|
||||
{ *bp = (Void_t*)f->next;
|
||||
{ *bp = (void*)f->next;
|
||||
if(sz < 0)
|
||||
{ f->mode |= SF_PEEK;
|
||||
f->endr = f->endw = f->data;
|
||||
|
|
|
|||
|
|
@ -45,21 +45,16 @@
|
|||
#define STREAM_PEEK 001
|
||||
#define SOCKET_PEEK 002
|
||||
|
||||
#if __STD_C
|
||||
ssize_t sfpkrd(int fd, Void_t* argbuf, size_t n, int rc, long tm, int action)
|
||||
#else
|
||||
ssize_t sfpkrd(fd, argbuf, n, rc, tm, action)
|
||||
int fd; /* file descriptor */
|
||||
Void_t* argbuf; /* buffer to read data */
|
||||
size_t n; /* buffer size */
|
||||
int rc; /* record character */
|
||||
long tm; /* time-out */
|
||||
int action; /* >0: peeking, if rc>=0, get action records,
|
||||
<0: no peeking, if rc>=0, get action records,
|
||||
=0: no peeking, if rc>=0, must get a single record
|
||||
=2: same as >0, but always use select(2)
|
||||
*/
|
||||
#endif
|
||||
ssize_t sfpkrd(int fd, /* file descriptor */
|
||||
void* argbuf, /* buffer to read data */
|
||||
size_t n, /* buffer size */
|
||||
int rc, /* record character */
|
||||
long tm, /* time-out */
|
||||
int action) /* >0: peeking, if rc>=0, get action records,
|
||||
<0: no peeking, if rc>=0, get action records,
|
||||
=0: no peeking, if rc>=0, must get a single record
|
||||
=2: same as >0, but always use select(2)
|
||||
*/
|
||||
{
|
||||
reg ssize_t r;
|
||||
reg int ntry, t;
|
||||
|
|
|
|||
|
|
@ -29,14 +29,9 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
int sfpoll(Sfio_t** fa, reg int n, int tm)
|
||||
#else
|
||||
int sfpoll(fa, n, tm)
|
||||
Sfio_t** fa; /* array of streams to poll */
|
||||
reg int n; /* number of streams in array */
|
||||
int tm; /* time in milliseconds for select/poll */
|
||||
#endif
|
||||
int sfpoll(Sfio_t** fa, /* array of streams to poll */
|
||||
reg int n, /* number of streams in array */
|
||||
int tm) /* time in milliseconds for select/poll */
|
||||
{
|
||||
reg int r, c, m, np, eintr;
|
||||
reg Sfio_t* f;
|
||||
|
|
@ -160,7 +155,7 @@ int tm; /* time in milliseconds for select/poll */
|
|||
}
|
||||
}
|
||||
|
||||
free((Void_t*)fds);
|
||||
free((void*)fds);
|
||||
}
|
||||
#endif /*_lib_poll*/
|
||||
|
||||
|
|
@ -238,7 +233,7 @@ int tm; /* time in milliseconds for select/poll */
|
|||
|
||||
/* announce status */
|
||||
if(f->disc && f->disc->exceptf)
|
||||
(*f->disc->exceptf)(f,SF_READY,(Void_t*)(long)status[c],f->disc);
|
||||
(*f->disc->exceptf)(f,SF_READY,(void*)(long)status[c],f->disc);
|
||||
|
||||
if(c > r) /* move to front of list */
|
||||
{ fa[c] = fa[r];
|
||||
|
|
@ -247,6 +242,6 @@ int tm; /* time in milliseconds for select/poll */
|
|||
r += 1;
|
||||
}
|
||||
|
||||
free((Void_t*)status);
|
||||
free((void*)status);
|
||||
return r ? r : np < 0 ? -1 : 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,28 +35,18 @@
|
|||
** link list and during such walks may free up streams&pools. Free pools will be
|
||||
** reused in newpool().
|
||||
*/
|
||||
#if __STD_C
|
||||
static int delpool(reg Sfpool_t* p)
|
||||
#else
|
||||
static int delpool(p)
|
||||
reg Sfpool_t* p;
|
||||
#endif
|
||||
{
|
||||
POOLMTXENTER(p);
|
||||
|
||||
if(p->s_sf && p->sf != p->array)
|
||||
free((Void_t*)p->sf);
|
||||
free((void*)p->sf);
|
||||
p->mode = SF_AVAIL;
|
||||
|
||||
POOLMTXRETURN(p,0);
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
static Sfpool_t* newpool(reg int mode)
|
||||
#else
|
||||
static Sfpool_t* newpool(mode)
|
||||
reg int mode;
|
||||
#endif
|
||||
{
|
||||
reg Sfpool_t *p, *last = &_Sfpool;
|
||||
|
||||
|
|
@ -96,14 +86,9 @@ reg int mode;
|
|||
}
|
||||
|
||||
/* move a stream to head */
|
||||
#if __STD_C
|
||||
static int _sfphead(Sfpool_t* p, Sfio_t* f, int n)
|
||||
#else
|
||||
static int _sfphead(p, f, n)
|
||||
Sfpool_t* p; /* the pool */
|
||||
Sfio_t* f; /* the stream */
|
||||
int n; /* current position in pool */
|
||||
#endif
|
||||
static int _sfphead(Sfpool_t* p, /* the pool */
|
||||
Sfio_t* f, /* the stream */
|
||||
int n) /* current position in pool */
|
||||
{
|
||||
reg Sfio_t* head;
|
||||
reg ssize_t k, w, v;
|
||||
|
|
@ -167,14 +152,9 @@ done:
|
|||
}
|
||||
|
||||
/* delete a stream from its pool */
|
||||
#if __STD_C
|
||||
static int _sfpdelete(Sfpool_t* p, Sfio_t* f, int n)
|
||||
#else
|
||||
static int _sfpdelete(p, f, n)
|
||||
Sfpool_t* p; /* the pool */
|
||||
Sfio_t* f; /* the stream */
|
||||
int n; /* position in pool */
|
||||
#endif
|
||||
static int _sfpdelete(Sfpool_t* p, /* the pool */
|
||||
Sfio_t* f, /* the stream */
|
||||
int n) /* position in pool */
|
||||
{
|
||||
POOLMTXENTER(p);
|
||||
|
||||
|
|
@ -217,13 +197,8 @@ done:
|
|||
POOLMTXRETURN(p,0);
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
static int _sfpmove(reg Sfio_t* f, reg int type)
|
||||
#else
|
||||
static int _sfpmove(f,type)
|
||||
reg Sfio_t* f;
|
||||
reg int type; /* <0 : deleting, 0: move-to-front, >0: inserting */
|
||||
#endif
|
||||
static int _sfpmove(reg Sfio_t* f,
|
||||
reg int type) /* <0 : deleting, 0: move-to-front, >0: inserting */
|
||||
{
|
||||
reg Sfpool_t* p;
|
||||
reg int n;
|
||||
|
|
@ -243,14 +218,7 @@ reg int type; /* <0 : deleting, 0: move-to-front, >0: inserting */
|
|||
}
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
Sfio_t* sfpool(reg Sfio_t* f, reg Sfio_t* pf, reg int mode)
|
||||
#else
|
||||
Sfio_t* sfpool(f,pf,mode)
|
||||
reg Sfio_t* f;
|
||||
reg Sfio_t* pf;
|
||||
reg int mode;
|
||||
#endif
|
||||
{
|
||||
int k;
|
||||
Sfpool_t* p;
|
||||
|
|
|
|||
|
|
@ -41,12 +41,7 @@
|
|||
static char Meta[1<<CHAR_BIT], **Path;
|
||||
|
||||
/* execute command directly if possible; else use the shell */
|
||||
#if __STD_C
|
||||
static void execute(const char* argcmd)
|
||||
#else
|
||||
static void execute(argcmd)
|
||||
char* argcmd;
|
||||
#endif
|
||||
{
|
||||
reg char *s, *cmd, **argv, **p, *interp;
|
||||
reg int n;
|
||||
|
|
@ -131,14 +126,9 @@ do_interp:
|
|||
|
||||
#endif /*_PACKAGE_ast*/
|
||||
|
||||
#if __STD_C
|
||||
Sfio_t* sfpopen(Sfio_t* f, const char* command, const char* mode)
|
||||
#else
|
||||
Sfio_t* sfpopen(f,command,mode)
|
||||
Sfio_t* f;
|
||||
char* command; /* command to execute */
|
||||
char* mode; /* mode of the stream */
|
||||
#endif
|
||||
Sfio_t* sfpopen(Sfio_t* f,
|
||||
const char* command, /* command to execute */
|
||||
const char* mode) /* mode of the stream */
|
||||
{
|
||||
#if _PACKAGE_ast
|
||||
reg Proc_t* proc;
|
||||
|
|
@ -169,7 +159,7 @@ char* mode; /* mode of the stream */
|
|||
av[3] = 0;
|
||||
if (!(proc = procopen(0, av, 0, 0, flags)))
|
||||
return 0;
|
||||
if (!(f = sfnew(f, NIL(Void_t*), (size_t)SF_UNBOUND,
|
||||
if (!(f = sfnew(f, NIL(void*), (size_t)SF_UNBOUND,
|
||||
(sflags&SF_READ) ? proc->rfd : proc->wfd, sflags|((sflags&SF_RDWR)?0:SF_READ))) ||
|
||||
_sfpopen(f, (sflags&SF_READ) ? proc->wfd : -1, proc->pid, pflags) < 0)
|
||||
{
|
||||
|
|
@ -223,7 +213,7 @@ char* mode; /* mode of the stream */
|
|||
else stdio = 0;
|
||||
|
||||
/* make the streams */
|
||||
if(!(f = sfnew(f,NIL(Void_t*),(size_t)SF_UNBOUND,parent[pkeep],sflags|((sflags&SF_RDWR)?0:SF_READ))))
|
||||
if(!(f = sfnew(f,NIL(void*),(size_t)SF_UNBOUND,parent[pkeep],sflags|((sflags&SF_RDWR)?0:SF_READ))))
|
||||
goto error;
|
||||
if(sflags&SF_RDWR)
|
||||
{ CLOSE(parent[!pkeep]);
|
||||
|
|
|
|||
|
|
@ -27,40 +27,17 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
int sfprintf(Sfio_t* f, const char* form, ...)
|
||||
#else
|
||||
int sfprintf(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
reg int rv;
|
||||
|
||||
#if __STD_C
|
||||
va_start(args,form);
|
||||
#else
|
||||
reg Sfio_t* f;
|
||||
reg char* form;
|
||||
va_start(args);
|
||||
f = va_arg(args,Sfio_t*);
|
||||
form = va_arg(args,char*);
|
||||
#endif
|
||||
rv = sfvprintf(f,form,args);
|
||||
|
||||
va_end(args);
|
||||
return rv;
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
ssize_t sfvsprintf(char* s, size_t n, const char* form, va_list args)
|
||||
#else
|
||||
ssize_t sfvsprintf(s, n, form, args)
|
||||
char* s;
|
||||
size_t n;
|
||||
char* form;
|
||||
va_list args;
|
||||
#endif
|
||||
{
|
||||
Sfio_t *f;
|
||||
ssize_t rv;
|
||||
|
|
@ -91,30 +68,12 @@ va_list args;
|
|||
return rv;
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
ssize_t sfsprintf(char* s, size_t n, const char* form, ...)
|
||||
#else
|
||||
ssize_t sfsprintf(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
ssize_t rv;
|
||||
|
||||
#if __STD_C
|
||||
va_start(args,form);
|
||||
#else
|
||||
reg char* s;
|
||||
reg size_t n;
|
||||
reg char* form;
|
||||
va_start(args);
|
||||
s = va_arg(args,char*);
|
||||
n = va_arg(args,size_t);
|
||||
form = va_arg(args,char*);
|
||||
#endif
|
||||
|
||||
rv = sfvsprintf(s,n,form,args);
|
||||
va_end(args);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,13 +29,7 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
char* sfvprints(const char* form, va_list args)
|
||||
#else
|
||||
char* sfvprints(form, args)
|
||||
char* form;
|
||||
va_list args;
|
||||
#endif
|
||||
{
|
||||
reg int rv;
|
||||
Sfnotify_f notify = _Sfnotify;
|
||||
|
|
@ -59,37 +53,17 @@ va_list args;
|
|||
return (char*)f->data;
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
char* sfprints(const char* form, ...)
|
||||
#else
|
||||
char* sfprints(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
char* s;
|
||||
va_list args;
|
||||
|
||||
#if __STD_C
|
||||
va_start(args,form);
|
||||
#else
|
||||
char *form;
|
||||
va_start(args);
|
||||
form = va_arg(args,char*);
|
||||
#endif
|
||||
s = sfvprints(form, args);
|
||||
va_end(args);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
ssize_t sfvaprints(char** sp, const char* form, va_list args)
|
||||
#else
|
||||
ssize_t sfvaprints(sp, form, args)
|
||||
char** sp;
|
||||
char* form;
|
||||
va_list args;
|
||||
#endif
|
||||
{
|
||||
char *s;
|
||||
ssize_t n;
|
||||
|
|
@ -104,26 +78,12 @@ va_list args;
|
|||
}
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
ssize_t sfaprints(char** sp, const char* form, ...)
|
||||
#else
|
||||
ssize_t sfaprints(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
ssize_t n;
|
||||
va_list args;
|
||||
|
||||
#if __STD_C
|
||||
va_start(args,form);
|
||||
#else
|
||||
char **sp, *form;
|
||||
va_start(args);
|
||||
sp = va_arg(args, char**);
|
||||
form = va_arg(args, char*);
|
||||
#endif
|
||||
n = sfvaprints(sp, form, args);
|
||||
va_end(args);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,12 +27,7 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
int sfpurge(Sfio_t* f)
|
||||
#else
|
||||
int sfpurge(f)
|
||||
Sfio_t* f;
|
||||
#endif
|
||||
{
|
||||
reg int mode;
|
||||
SFMTXDECL(f);
|
||||
|
|
@ -43,7 +38,7 @@ Sfio_t* f;
|
|||
SFMTXRETURN(f, -1);
|
||||
|
||||
if((f->flags&SF_IOCHECK) && f->disc && f->disc->exceptf)
|
||||
(void)(*f->disc->exceptf)(f,SF_PURGE,(Void_t*)((int)1),f->disc);
|
||||
(void)(*f->disc->exceptf)(f,SF_PURGE,(void*)((int)1),f->disc);
|
||||
|
||||
if(f->disc == _Sfudisc)
|
||||
(void)sfclose((*_Sfstack)(f,NIL(Sfio_t*)));
|
||||
|
|
@ -93,7 +88,7 @@ Sfio_t* f;
|
|||
|
||||
done:
|
||||
if((f->flags&SF_IOCHECK) && f->disc && f->disc->exceptf)
|
||||
(void)(*f->disc->exceptf)(f,SF_PURGE,(Void_t*)((int)0),f->disc);
|
||||
(void)(*f->disc->exceptf)(f,SF_PURGE,(void*)((int)0),f->disc);
|
||||
|
||||
SFMTXRETURN(f, 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,13 +24,7 @@
|
|||
|
||||
#undef sfputd
|
||||
|
||||
#if __STD_C
|
||||
int sfputd(reg Sfio_t* f, Sfdouble_t d)
|
||||
#else
|
||||
int sfputd(f,d)
|
||||
reg Sfio_t* f;
|
||||
reg Sfdouble_t d;
|
||||
#endif
|
||||
{
|
||||
return __sf_putd(f,d);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,13 +24,7 @@
|
|||
|
||||
#undef sfputl
|
||||
|
||||
#if __STD_C
|
||||
int sfputl(reg Sfio_t* f, Sflong_t l)
|
||||
#else
|
||||
int sfputl(f,l)
|
||||
reg Sfio_t* f;
|
||||
reg Sflong_t l;
|
||||
#endif
|
||||
{
|
||||
return __sf_putl(f,l);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,14 +24,7 @@
|
|||
|
||||
#undef sfputm
|
||||
|
||||
#if __STD_C
|
||||
int sfputm(Sfio_t* f, Sfulong_t u, Sfulong_t m)
|
||||
#else
|
||||
int sfputm(f,u,m)
|
||||
Sfio_t* f;
|
||||
Sfulong_t u;
|
||||
Sfulong_t m;
|
||||
#endif
|
||||
{
|
||||
return __sf_putm(f, u, m);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,14 +26,9 @@
|
|||
**
|
||||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
#if __STD_C
|
||||
ssize_t sfputr(Sfio_t* f, const char* s, int rc)
|
||||
#else
|
||||
ssize_t sfputr(f,s,rc)
|
||||
Sfio_t* f; /* write to this stream */
|
||||
char* s; /* string to write */
|
||||
int rc; /* record separator. */
|
||||
#endif
|
||||
ssize_t sfputr(Sfio_t* f, /* write to this stream */
|
||||
const char* s, /* string to write */
|
||||
int rc) /* record separator */
|
||||
{
|
||||
ssize_t p, n, w, sn;
|
||||
uchar *ps;
|
||||
|
|
@ -128,7 +123,7 @@ int rc; /* record separator. */
|
|||
{ if(n > w)
|
||||
n = w;
|
||||
f->next -= n;
|
||||
(void)SFWRITE(f,(Void_t*)f->next,n);
|
||||
(void)SFWRITE(f,(void*)f->next,n);
|
||||
}
|
||||
|
||||
SFOPEN(f,0);
|
||||
|
|
|
|||
|
|
@ -24,13 +24,7 @@
|
|||
|
||||
#undef sfputu
|
||||
|
||||
#if __STD_C
|
||||
int sfputu(reg Sfio_t* f, Sfulong_t u)
|
||||
#else
|
||||
int sfputu(f,u)
|
||||
reg Sfio_t* f;
|
||||
reg Sfulong_t u;
|
||||
#endif
|
||||
{
|
||||
return __sf_putu(f,u);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,13 +27,8 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
static int _sfraiseall(int type, Void_t* data)
|
||||
#else
|
||||
static int _sfraiseall(type, data)
|
||||
int type; /* type of event */
|
||||
Void_t* data; /* associated data */
|
||||
#endif
|
||||
static int _sfraiseall(int type, /* type of event */
|
||||
void* data) /* associated data */
|
||||
{
|
||||
Sfio_t *f;
|
||||
Sfpool_t *p, *next;
|
||||
|
|
@ -55,12 +50,12 @@ Void_t* data; /* associated data */
|
|||
}
|
||||
|
||||
#if __STD_C
|
||||
int sfraise(Sfio_t* f, int type, Void_t* data)
|
||||
int sfraise(Sfio_t* f, int type, void* data)
|
||||
#else
|
||||
int sfraise(f, type, data)
|
||||
Sfio_t* f; /* stream */
|
||||
int type; /* type of event */
|
||||
Void_t* data; /* associated data */
|
||||
void* data; /* associated data */
|
||||
#endif
|
||||
{
|
||||
reg Sfdisc_t *disc, *next, *d;
|
||||
|
|
|
|||
|
|
@ -29,11 +29,7 @@
|
|||
*/
|
||||
|
||||
/* synchronize unseekable write streams */
|
||||
#if __STD_C
|
||||
static void _sfwrsync(void)
|
||||
#else
|
||||
static void _sfwrsync()
|
||||
#endif
|
||||
{ reg Sfpool_t* p;
|
||||
reg Sfio_t* f;
|
||||
reg int n;
|
||||
|
|
@ -58,15 +54,7 @@ static void _sfwrsync()
|
|||
}
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
ssize_t sfrd(Sfio_t* f, Void_t* buf, size_t n, Sfdisc_t* disc)
|
||||
#else
|
||||
ssize_t sfrd(f,buf,n,disc)
|
||||
Sfio_t* f;
|
||||
Void_t* buf;
|
||||
size_t n;
|
||||
Sfdisc_t* disc;
|
||||
#endif
|
||||
ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc)
|
||||
{
|
||||
Sfoff_t r;
|
||||
reg Sfdisc_t* dc;
|
||||
|
|
@ -217,10 +205,10 @@ Sfdisc_t* disc;
|
|||
(void)SFSK(f,f->here,SEEK_SET,dc);
|
||||
|
||||
/* make a buffer */
|
||||
(void)SFSETBUF(f,(Void_t*)f->tiny,(size_t)SF_UNBOUND);
|
||||
(void)SFSETBUF(f,(void*)f->tiny,(size_t)SF_UNBOUND);
|
||||
|
||||
if(!buf)
|
||||
{ buf = (Void_t*)f->data;
|
||||
{ buf = (void*)f->data;
|
||||
n = f->size;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,14 +27,9 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
ssize_t sfread(Sfio_t* f, Void_t* buf, size_t n)
|
||||
#else
|
||||
ssize_t sfread(f,buf,n)
|
||||
Sfio_t* f; /* read from this stream. */
|
||||
Void_t* buf; /* buffer to read into */
|
||||
size_t n; /* number of bytes to be read. */
|
||||
#endif
|
||||
ssize_t sfread(Sfio_t* f, /* read from this stream. */
|
||||
void* buf, /* buffer to read into */
|
||||
size_t n) /* number of bytes to be read. */
|
||||
{
|
||||
reg uchar *s, *begs;
|
||||
reg ssize_t r;
|
||||
|
|
|
|||
|
|
@ -27,22 +27,17 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
Void_t* sfreserve(Sfio_t* f, ssize_t size, int type)
|
||||
#else
|
||||
Void_t* sfreserve(f,size,type)
|
||||
Sfio_t* f; /* file to peek */
|
||||
ssize_t size; /* size of peek */
|
||||
int type; /* LOCKR: lock stream, LASTR: last record */
|
||||
#endif
|
||||
void* sfreserve(Sfio_t* f, /* file to peek */
|
||||
ssize_t size, /* size of peek */
|
||||
int type) /* LOCKR: lock stream, LASTR: last record */
|
||||
{
|
||||
reg ssize_t n, now, sz, iosz;
|
||||
reg Sfrsrv_t* rsrv;
|
||||
reg Void_t* data;
|
||||
reg void* data;
|
||||
reg int mode, local;
|
||||
SFMTXDECL(f);
|
||||
|
||||
SFMTXENTER(f,NIL(Void_t*));
|
||||
SFMTXENTER(f,NIL(void*));
|
||||
|
||||
sz = size < 0 ? -size : size;
|
||||
|
||||
|
|
@ -55,17 +50,17 @@ int type; /* LOCKR: lock stream, LASTR: last record */
|
|||
/* return the last record */
|
||||
if(type == SF_LASTR )
|
||||
{ if((n = f->endb - f->next) > 0 && n == f->val )
|
||||
{ data = (Void_t*)f->next;
|
||||
{ data = (void*)f->next;
|
||||
f->next += n;
|
||||
}
|
||||
else if((rsrv = f->rsrv) && (n = -rsrv->slen) > 0)
|
||||
{ rsrv->slen = 0;
|
||||
_Sfi = f->val = n;
|
||||
data = (Void_t*)rsrv->data;
|
||||
data = (void*)rsrv->data;
|
||||
}
|
||||
else
|
||||
{ _Sfi = f->val = -1;
|
||||
data = NIL(Void_t*);
|
||||
data = NIL(void*);
|
||||
}
|
||||
|
||||
SFMTXRETURN(f, data);
|
||||
|
|
@ -75,12 +70,12 @@ int type; /* LOCKR: lock stream, LASTR: last record */
|
|||
{ if(type == 1 ) /* upward compatibility mode */
|
||||
type = SF_LOCKR;
|
||||
else if(type != SF_LOCKR)
|
||||
SFMTXRETURN(f, NIL(Void_t*));
|
||||
SFMTXRETURN(f, NIL(void*));
|
||||
}
|
||||
|
||||
if(size == 0 && (type < 0 || type == SF_LOCKR) )
|
||||
{ if((f->mode&SF_RDWR) != f->mode && _sfmode(f,0,0) < 0)
|
||||
SFMTXRETURN(f, NIL(Void_t*));
|
||||
SFMTXRETURN(f, NIL(void*));
|
||||
|
||||
SFLOCK(f,0);
|
||||
if((n = f->endb - f->next) < 0)
|
||||
|
|
@ -97,7 +92,7 @@ int type; /* LOCKR: lock stream, LASTR: last record */
|
|||
mode = SF_WRITE;
|
||||
if((int)f->mode != mode && _sfmode(f,mode,local) < 0)
|
||||
{ SFOPEN(f,0);
|
||||
SFMTXRETURN(f, NIL(Void_t*));
|
||||
SFMTXRETURN(f, NIL(void*));
|
||||
}
|
||||
|
||||
SFLOCK(f,local);
|
||||
|
|
@ -164,29 +159,29 @@ int type; /* LOCKR: lock stream, LASTR: last record */
|
|||
}
|
||||
|
||||
done: /* compute the buffer to be returned */
|
||||
data = NIL(Void_t*);
|
||||
data = NIL(void*);
|
||||
if(size == 0 || n == 0)
|
||||
{ if(n > 0) /* got data */
|
||||
data = (Void_t*)f->next;
|
||||
data = (void*)f->next;
|
||||
else if(type == SF_LOCKR && size == 0 && (rsrv = _sfrsrv(f,0)) )
|
||||
data = (Void_t*)rsrv->data;
|
||||
data = (void*)rsrv->data;
|
||||
}
|
||||
else if(n >= sz) /* got data */
|
||||
data = (Void_t*)f->next;
|
||||
data = (void*)f->next;
|
||||
else if(f->flags&SF_STRING) /* try extending string buffer */
|
||||
{ if((f->mode&SF_WRITE) && (f->flags&SF_MALLOC) )
|
||||
{ (void)SFWR(f,f->next,sz,f->disc);
|
||||
if((n = f->endb - f->next) >= sz )
|
||||
data = (Void_t*)f->next;
|
||||
data = (void*)f->next;
|
||||
}
|
||||
}
|
||||
else if(f->mode&SF_WRITE) /* allocate side buffer */
|
||||
{ if(type == SF_LOCKR && (rsrv = _sfrsrv(f, sz)) )
|
||||
data = (Void_t*)rsrv->data;
|
||||
data = (void*)rsrv->data;
|
||||
}
|
||||
else if(type != SF_LOCKR && sz > f->size && (rsrv = _sfrsrv(f,sz)) )
|
||||
{ if((n = SFREAD(f,(Void_t*)rsrv->data,sz)) >= sz) /* read side buffer */
|
||||
data = (Void_t*)rsrv->data;
|
||||
{ if((n = SFREAD(f,(void*)rsrv->data,sz)) >= sz) /* read side buffer */
|
||||
data = (void*)rsrv->data;
|
||||
else rsrv->slen = -n;
|
||||
}
|
||||
|
||||
|
|
@ -200,7 +195,7 @@ done: /* compute the buffer to be returned */
|
|||
f->endr = f->endw = f->data;
|
||||
}
|
||||
else
|
||||
{ if(data == (Void_t*)f->next)
|
||||
{ if(data == (void*)f->next)
|
||||
f->next += (size >= 0 ? size : n);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,13 +26,7 @@
|
|||
Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
int sfresize(Sfio_t* f, Sfoff_t size)
|
||||
#else
|
||||
int sfresize(f, size)
|
||||
Sfio_t* f;
|
||||
Sfoff_t size;
|
||||
#endif
|
||||
{
|
||||
SFMTXDECL(f);
|
||||
|
||||
|
|
@ -50,7 +44,7 @@ Sfoff_t size;
|
|||
if(f->extent >= size)
|
||||
{ if((f->flags&SF_MALLOC) && (f->next - f->data) <= size)
|
||||
{ size_t s = (((size_t)size + 1023)/1024)*1024;
|
||||
Void_t* d;
|
||||
void* d;
|
||||
if(s < f->size && (d = realloc(f->data, s)) )
|
||||
{ f->data = d;
|
||||
f->size = s;
|
||||
|
|
|
|||
|
|
@ -27,39 +27,17 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
int sfscanf(Sfio_t* f, const char* form, ...)
|
||||
#else
|
||||
int sfscanf(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
reg int rv;
|
||||
|
||||
#if __STD_C
|
||||
va_start(args,form);
|
||||
#else
|
||||
reg Sfio_t* f;
|
||||
reg char* form;
|
||||
va_start(args);
|
||||
f = va_arg(args,Sfio_t*);
|
||||
form = va_arg(args,char*);
|
||||
#endif
|
||||
|
||||
rv = (f && form) ? sfvscanf(f,form,args) : -1;
|
||||
va_end(args);
|
||||
return rv;
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
int sfvsscanf(const char* s, const char* form, va_list args)
|
||||
#else
|
||||
int sfvsscanf(s, form, args)
|
||||
char* s;
|
||||
char* form;
|
||||
va_list args;
|
||||
#endif
|
||||
{
|
||||
Sfio_t f;
|
||||
|
||||
|
|
@ -78,25 +56,11 @@ va_list args;
|
|||
return sfvscanf(&f,form,args);
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
int sfsscanf(const char* s, const char* form,...)
|
||||
#else
|
||||
int sfsscanf(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
reg int rv;
|
||||
#if __STD_C
|
||||
va_start(args,form);
|
||||
#else
|
||||
reg char* s;
|
||||
reg char* form;
|
||||
va_start(args);
|
||||
s = va_arg(args,char*);
|
||||
form = va_arg(args,char*);
|
||||
#endif
|
||||
|
||||
rv = (s && form) ? sfvsscanf(s,form,args) : -1;
|
||||
va_end(args);
|
||||
return rv;
|
||||
|
|
|
|||
|
|
@ -27,13 +27,7 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
static void newpos(Sfio_t* f, Sfoff_t p)
|
||||
#else
|
||||
static void newpos(f, p)
|
||||
Sfio_t* f;
|
||||
Sfoff_t p;
|
||||
#endif
|
||||
{
|
||||
#ifdef MAP_TYPE
|
||||
if((f->bits&SF_MMAP) && f->data)
|
||||
|
|
@ -49,14 +43,9 @@ Sfoff_t p;
|
|||
}
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
Sfoff_t sfseek(Sfio_t* f, Sfoff_t p, int type)
|
||||
#else
|
||||
Sfoff_t sfseek(f,p,type)
|
||||
Sfio_t* f; /* seek to a new location in this stream */
|
||||
Sfoff_t p; /* place to seek to */
|
||||
int type; /* 0: from org, 1: from here, 2: from end */
|
||||
#endif
|
||||
Sfoff_t sfseek(Sfio_t* f, /* seek to a new location in this stream */
|
||||
Sfoff_t p, /* place to seek to */
|
||||
int type) /* 0: from org, 1: from here, 2: from end */
|
||||
{
|
||||
Sfoff_t r, s;
|
||||
int mode, local, hardseek, mustsync;
|
||||
|
|
@ -207,7 +196,7 @@ int type; /* 0: from org, 1: from here, 2: from end */
|
|||
{ /* if mmap is not great, stop mmapping if moving around too much */
|
||||
#if _mmap_worthy < 2
|
||||
if((f->next - f->data) < ((f->endb - f->data)/4) )
|
||||
{ SFSETBUF(f,(Void_t*)f->tiny,(size_t)SF_UNBOUND);
|
||||
{ SFSETBUF(f,(void*)f->tiny,(size_t)SF_UNBOUND);
|
||||
hardseek = 1; /* this forces a hard seek below */
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -27,14 +27,7 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
int sfset(Sfio_t* f, int flags, int set)
|
||||
#else
|
||||
int sfset(f,flags,set)
|
||||
Sfio_t* f;
|
||||
int flags;
|
||||
int set;
|
||||
#endif
|
||||
{
|
||||
reg int oflags, tflags, rv;
|
||||
SFMTXDECL(f);
|
||||
|
|
|
|||
|
|
@ -35,9 +35,7 @@ __STDPP__directive pragma pp:nohide getpagesize
|
|||
#endif
|
||||
|
||||
#if _lib_getpagesize
|
||||
_BEGIN_EXTERNS_
|
||||
extern int getpagesize _ARG_((void));
|
||||
_END_EXTERNS_
|
||||
extern int getpagesize(void);
|
||||
#endif
|
||||
|
||||
/* Set a (new) buffer for a stream.
|
||||
|
|
@ -102,14 +100,9 @@ static int sfsetlinemode()
|
|||
|
||||
#endif
|
||||
|
||||
#if __STD_C
|
||||
Void_t* sfsetbuf(Sfio_t* f, Void_t* buf, size_t size)
|
||||
#else
|
||||
Void_t* sfsetbuf(f,buf,size)
|
||||
Sfio_t* f; /* stream to be buffered */
|
||||
Void_t* buf; /* new buffer */
|
||||
size_t size; /* buffer size, -1 for default size */
|
||||
#endif
|
||||
void* sfsetbuf(Sfio_t* f, /* stream to be buffered */
|
||||
void* buf, /* new buffer */
|
||||
size_t size) /* buffer size, -1 for default size */
|
||||
{
|
||||
int sf_malloc, oflags, init, okmmap, local;
|
||||
ssize_t bufsize, blksz;
|
||||
|
|
@ -121,28 +114,28 @@ size_t size; /* buffer size, -1 for default size */
|
|||
|
||||
SFONCE();
|
||||
|
||||
SFMTXENTER(f,NIL(Void_t*));
|
||||
SFMTXENTER(f,NIL(void*));
|
||||
|
||||
GETLOCAL(f,local);
|
||||
|
||||
if(size == 0 && buf)
|
||||
{ /* special case to get buffer info */
|
||||
_Sfi = f->val = (f->bits&SF_MMAP) ? (f->endb-f->data) : f->size;
|
||||
SFMTXRETURN(f, (Void_t*)f->data);
|
||||
SFMTXRETURN(f, (void*)f->data);
|
||||
}
|
||||
|
||||
/* cleanup actions already done, don't allow write buffering any more */
|
||||
if(_Sfexiting && !(f->flags&SF_STRING) && (f->mode&SF_WRITE))
|
||||
{ buf = NIL(Void_t*);
|
||||
{ buf = NIL(void*);
|
||||
size = 0;
|
||||
}
|
||||
|
||||
if((init = f->mode&SF_INIT) )
|
||||
{ if(!f->pool && _sfsetpool(f) < 0)
|
||||
SFMTXRETURN(f, NIL(Void_t*));
|
||||
SFMTXRETURN(f, NIL(void*));
|
||||
}
|
||||
else if((f->mode&SF_RDWR) != SFMODE(f,local) && _sfmode(f,0,local) < 0)
|
||||
SFMTXRETURN(f, NIL(Void_t*));
|
||||
SFMTXRETURN(f, NIL(void*));
|
||||
|
||||
if(init)
|
||||
f->mode = (f->mode&SF_RDWR)|SF_LOCK;
|
||||
|
|
@ -152,12 +145,12 @@ size_t size; /* buffer size, -1 for default size */
|
|||
/* make sure there is no hidden read data */
|
||||
if(f->proc && (f->flags&SF_READ) && (f->mode&SF_WRITE) &&
|
||||
_sfmode(f,SF_READ,local) < 0)
|
||||
SFMTXRETURN(f, NIL(Void_t*));
|
||||
SFMTXRETURN(f, NIL(void*));
|
||||
|
||||
/* synchronize first */
|
||||
SFLOCK(f,local); rv = SFSYNC(f); SFOPEN(f,local);
|
||||
if(rv < 0)
|
||||
SFMTXRETURN(f, NIL(Void_t*));
|
||||
SFMTXRETURN(f, NIL(void*));
|
||||
|
||||
/* turn off the SF_SYNCED bit because buffer is changing */
|
||||
f->mode &= ~SF_SYNCED;
|
||||
|
|
@ -176,7 +169,7 @@ size_t size; /* buffer size, -1 for default size */
|
|||
goto done;
|
||||
}
|
||||
else /* initialize stream as if in the default case */
|
||||
{ buf = NIL(Void_t*);
|
||||
{ buf = NIL(void*);
|
||||
size = (size_t)SF_UNBOUND;
|
||||
}
|
||||
}
|
||||
|
|
@ -356,21 +349,21 @@ setbuf:
|
|||
else if((ssize_t)(size = _Sfpage) < bufsize)
|
||||
size = bufsize;
|
||||
|
||||
buf = NIL(Void_t*);
|
||||
buf = NIL(void*);
|
||||
}
|
||||
|
||||
sf_malloc = 0;
|
||||
if(size > 0 && !buf && !(f->bits&SF_MMAP))
|
||||
{ /* try to allocate a buffer */
|
||||
if(obuf && size == (size_t)osize && init)
|
||||
{ buf = (Void_t*)obuf;
|
||||
{ buf = (void*)obuf;
|
||||
obuf = NIL(uchar*);
|
||||
sf_malloc = (oflags&SF_MALLOC);
|
||||
}
|
||||
if(!buf)
|
||||
{ /* do allocation */
|
||||
while(!buf && size > 0)
|
||||
{ if((buf = (Void_t*)malloc(size)) )
|
||||
{ if((buf = (void*)malloc(size)) )
|
||||
break;
|
||||
else size /= 2;
|
||||
}
|
||||
|
|
@ -382,7 +375,7 @@ setbuf:
|
|||
if(size == 0 && !(f->flags&SF_STRING) && !(f->bits&SF_MMAP) && (f->mode&SF_READ))
|
||||
{ /* use the internal buffer */
|
||||
size = sizeof(f->tiny);
|
||||
buf = (Void_t*)f->tiny;
|
||||
buf = (void*)f->tiny;
|
||||
}
|
||||
|
||||
/* set up new buffer */
|
||||
|
|
@ -403,7 +396,7 @@ setbuf:
|
|||
f->flags = (f->flags & ~SF_MALLOC)|sf_malloc;
|
||||
|
||||
if(obuf && obuf != f->data && osize > 0 && (oflags&SF_MALLOC))
|
||||
{ free((Void_t*)obuf);
|
||||
{ free((void*)obuf);
|
||||
obuf = NIL(uchar*);
|
||||
}
|
||||
|
||||
|
|
@ -423,5 +416,5 @@ done:
|
|||
|
||||
SFOPEN(f,local);
|
||||
|
||||
SFMTXRETURN(f, (Void_t*)obuf);
|
||||
SFMTXRETURN(f, (void*)obuf);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,13 +27,7 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
static int _sfdup(int fd, int newfd)
|
||||
#else
|
||||
static int _sfdup(fd,newfd)
|
||||
int fd;
|
||||
int newfd;
|
||||
#endif
|
||||
{
|
||||
reg int dupfd;
|
||||
|
||||
|
|
@ -56,13 +50,7 @@ int newfd;
|
|||
#endif
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
int sfsetfd(Sfio_t* f, int newfd)
|
||||
#else
|
||||
int sfsetfd(f,newfd)
|
||||
Sfio_t *f;
|
||||
int newfd;
|
||||
#endif
|
||||
{
|
||||
reg int oldfd;
|
||||
SFMTXDECL(f);
|
||||
|
|
|
|||
|
|
@ -26,12 +26,7 @@
|
|||
**
|
||||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
#if __STD_C
|
||||
Sfoff_t sfsize(Sfio_t* f)
|
||||
#else
|
||||
Sfoff_t sfsize(f)
|
||||
Sfio_t* f;
|
||||
#endif
|
||||
{
|
||||
Sfdisc_t* disc;
|
||||
reg int mode;
|
||||
|
|
|
|||
|
|
@ -26,15 +26,7 @@
|
|||
**
|
||||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
#if __STD_C
|
||||
Sfoff_t sfsk(Sfio_t* f, Sfoff_t addr, int type, Sfdisc_t* disc)
|
||||
#else
|
||||
Sfoff_t sfsk(f,addr,type,disc)
|
||||
Sfio_t* f;
|
||||
Sfoff_t addr;
|
||||
int type;
|
||||
Sfdisc_t* disc;
|
||||
#endif
|
||||
{
|
||||
Sfoff_t p;
|
||||
reg Sfdisc_t* dc;
|
||||
|
|
|
|||
|
|
@ -38,18 +38,13 @@
|
|||
return(rv); \
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
Sfio_t* sfstack(Sfio_t* f1, Sfio_t* f2)
|
||||
#else
|
||||
Sfio_t* sfstack(f1,f2)
|
||||
Sfio_t* f1; /* base of stack */
|
||||
Sfio_t* f2; /* top of stack */
|
||||
#endif
|
||||
Sfio_t* sfstack(Sfio_t* f1, /* base of stack */
|
||||
Sfio_t* f2) /* top of stack */
|
||||
{
|
||||
reg int n;
|
||||
reg Sfio_t* rf;
|
||||
reg Sfrsrv_t* rsrv;
|
||||
reg Void_t* mtx;
|
||||
reg void* mtx;
|
||||
|
||||
STKMTXLOCK(f1,f2);
|
||||
|
||||
|
|
|
|||
|
|
@ -33,12 +33,7 @@
|
|||
#define FPART 1 /* doing fractional part */
|
||||
#define EPART 2 /* doing exponent part */
|
||||
|
||||
#if __STD_C
|
||||
static Sfdouble_t sfpow10(reg int n)
|
||||
#else
|
||||
static Sfdouble_t sfpow10(n)
|
||||
reg int n;
|
||||
#endif
|
||||
{
|
||||
Sfdouble_t dval;
|
||||
|
||||
|
|
@ -66,13 +61,8 @@ reg int n;
|
|||
return dval;
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
Sfdouble_t _sfstrtod(reg const char* s, char** retp)
|
||||
#else
|
||||
Sfdouble_t _sfstrtod(s,retp)
|
||||
reg char* s; /* string to convert */
|
||||
char** retp; /* to return the remainder of string */
|
||||
#endif
|
||||
Sfdouble_t _sfstrtod(reg const char* s, /* string to convert */
|
||||
char** retp) /* to return the remainder of string */
|
||||
{
|
||||
reg int n, c, m;
|
||||
reg int mode, fexp, sign, expsign;
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@
|
|||
|
||||
#if S2F_scan
|
||||
|
||||
typedef int (*S2F_get_f)_ARG_((void*, int));
|
||||
typedef int (*S2F_get_f)(void*, int);
|
||||
|
||||
#define ERR(e)
|
||||
#define GET(p) (*get)(p,0)
|
||||
|
|
@ -171,24 +171,12 @@ extern
|
|||
#endif
|
||||
S2F_number
|
||||
#if S2F_scan
|
||||
#if __STD_C
|
||||
S2F_function(void* s, S2F_get_f get)
|
||||
#else
|
||||
S2F_function(s, get) void* s; S2F_get_f get;
|
||||
#endif
|
||||
#else
|
||||
#if S2F_size
|
||||
#if __STD_C
|
||||
S2F_function(const char* str, size_t size, char** end)
|
||||
#else
|
||||
S2F_function(str, size, end) char* str; size_t size; char** end;
|
||||
#endif
|
||||
#else
|
||||
#if __STD_C
|
||||
S2F_function(const char* str, char** end)
|
||||
#else
|
||||
S2F_function(str, end) char* str; char** end;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
{
|
||||
|
|
|
|||
|
|
@ -30,13 +30,7 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
Sfio_t* sfswap(reg Sfio_t* f1, reg Sfio_t* f2)
|
||||
#else
|
||||
Sfio_t* sfswap(f1,f2)
|
||||
reg Sfio_t* f1;
|
||||
reg Sfio_t* f2;
|
||||
#endif
|
||||
{
|
||||
Sfio_t tmp;
|
||||
int f1pool, f2pool, f1mode, f2mode, f1flags, f2flags;
|
||||
|
|
@ -89,9 +83,9 @@ reg Sfio_t* f2;
|
|||
f2flags = f2->flags;
|
||||
|
||||
/* swap image and pool entries */
|
||||
memcpy((Void_t*)(&tmp),(Void_t*)f1,sizeof(Sfio_t));
|
||||
memcpy((Void_t*)f1,(Void_t*)f2,sizeof(Sfio_t));
|
||||
memcpy((Void_t*)f2,(Void_t*)(&tmp),sizeof(Sfio_t));
|
||||
memcpy((void*)(&tmp),(void*)f1,sizeof(Sfio_t));
|
||||
memcpy((void*)f1,(void*)f2,sizeof(Sfio_t));
|
||||
memcpy((void*)f2,(void*)(&tmp),sizeof(Sfio_t));
|
||||
if(f2pool >= 0)
|
||||
f1->pool->sf[f2pool] = f1;
|
||||
if(f1pool >= 0)
|
||||
|
|
|
|||
|
|
@ -28,11 +28,7 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
static int _sfall(void)
|
||||
#else
|
||||
static int _sfall()
|
||||
#endif
|
||||
{
|
||||
reg Sfpool_t *p, *next;
|
||||
reg Sfio_t* f;
|
||||
|
|
@ -80,12 +76,7 @@ static int _sfall()
|
|||
return rv;
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
int sfsync(reg Sfio_t* f)
|
||||
#else
|
||||
int sfsync(f)
|
||||
reg Sfio_t* f; /* stream to be synchronized */
|
||||
#endif
|
||||
{
|
||||
int local, rv, mode, lock;
|
||||
Sfio_t* origf;
|
||||
|
|
@ -115,7 +106,7 @@ reg Sfio_t* f; /* stream to be synchronized */
|
|||
for(; f; f = f->push)
|
||||
{
|
||||
if((f->flags&SF_IOCHECK) && f->disc && f->disc->exceptf)
|
||||
(void)(*f->disc->exceptf)(f,SF_SYNC,(Void_t*)((int)1),f->disc);
|
||||
(void)(*f->disc->exceptf)(f,SF_SYNC,(void*)((int)1),f->disc);
|
||||
|
||||
SFLOCK(f,local);
|
||||
|
||||
|
|
@ -162,7 +153,7 @@ reg Sfio_t* f; /* stream to be synchronized */
|
|||
SFOPEN(f,local);
|
||||
|
||||
if((f->flags&SF_IOCHECK) && f->disc && f->disc->exceptf)
|
||||
(void)(*f->disc->exceptf)(f,SF_SYNC,(Void_t*)((int)0),f->disc);
|
||||
(void)(*f->disc->exceptf)(f,SF_SYNC,(void*)((int)0),f->disc);
|
||||
}
|
||||
|
||||
done:
|
||||
|
|
|
|||
|
|
@ -28,13 +28,7 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
static char* sffmtint(const char* str, int* v)
|
||||
#else
|
||||
static char* sffmtint(str, v)
|
||||
char* str;
|
||||
int* v;
|
||||
#endif
|
||||
{
|
||||
for(*v = 0; isdigit(*str); ++str)
|
||||
*v = *v * 10 + (*str - '0');
|
||||
|
|
@ -42,16 +36,8 @@ int* v;
|
|||
return (char*)str;
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
/* type>0: scanf, type==0: printf, type==-1: internal */
|
||||
static Fmtpos_t* sffmtpos(Sfio_t* f,const char* form,va_list args,Sffmt_t* ft,int type)
|
||||
#else
|
||||
static Fmtpos_t* sffmtpos(f,form,args,ft,type)
|
||||
Sfio_t* f;
|
||||
char* form;
|
||||
va_list args;
|
||||
Sffmt_t* ft;
|
||||
int type; /* >0: scanf, =0: printf, -1: internal */
|
||||
#endif
|
||||
{
|
||||
int base, fmt, flags, dot, width, precis;
|
||||
ssize_t n_str, size = 0;
|
||||
|
|
@ -374,7 +360,7 @@ int type; /* >0: scanf, =0: printf, -1: internal */
|
|||
memcpy(ft,&fp[n].ft,sizeof(Sffmt_t));
|
||||
va_copy(ft->args,args);
|
||||
ft->flags |= SFFMT_ARGPOS;
|
||||
v = (*ft->extf)(f, (Void_t*)(&fp[n].argv), ft);
|
||||
v = (*ft->extf)(f, (void*)(&fp[n].argv), ft);
|
||||
va_copy(args,ft->args);
|
||||
memcpy(&fp[n].ft,ft,sizeof(Sffmt_t));
|
||||
if(v < 0)
|
||||
|
|
@ -419,7 +405,7 @@ int type; /* >0: scanf, =0: printf, -1: internal */
|
|||
memcpy(&savft,ft,sizeof(Sffmt_t));
|
||||
}
|
||||
else if(type > 0) /* from sfvscanf */
|
||||
fp[n].argv.vp = va_arg(args, Void_t*);
|
||||
fp[n].argv.vp = va_arg(args, void*);
|
||||
else switch(_Sftype[fp[n].ft.fmt])
|
||||
{ case SFFMT_INT:
|
||||
case SFFMT_UINT:
|
||||
|
|
@ -441,7 +427,7 @@ int type; /* >0: scanf, =0: printf, -1: internal */
|
|||
fp[n].argv.d = va_arg(args,double);
|
||||
break;
|
||||
case SFFMT_POINTER:
|
||||
fp[n].argv.vp = va_arg(args,Void_t*);
|
||||
fp[n].argv.vp = va_arg(args,void*);
|
||||
break;
|
||||
case SFFMT_CHAR:
|
||||
if(fp[n].ft.base >= 0)
|
||||
|
|
|
|||
|
|
@ -27,12 +27,7 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
Sfoff_t sftell(Sfio_t* f)
|
||||
#else
|
||||
Sfoff_t sftell(f)
|
||||
Sfio_t *f;
|
||||
#endif
|
||||
{
|
||||
reg int mode;
|
||||
Sfoff_t p;
|
||||
|
|
|
|||
|
|
@ -61,15 +61,7 @@ struct _file_s
|
|||
|
||||
static File_t* File; /* list pf temp files */
|
||||
|
||||
#if __STD_C
|
||||
static int _tmprmfile(Sfio_t* f, int type, Void_t* val, Sfdisc_t* disc)
|
||||
#else
|
||||
static int _tmprmfile(f, type, val, disc)
|
||||
Sfio_t* f;
|
||||
int type;
|
||||
Void_t* val;
|
||||
Sfdisc_t* disc;
|
||||
#endif
|
||||
static int _tmprmfile(Sfio_t* f, int type, void* val, Sfdisc_t* disc)
|
||||
{
|
||||
reg File_t *ff, *last;
|
||||
|
||||
|
|
@ -96,7 +88,7 @@ Sfdisc_t* disc;
|
|||
while(sysremovef(ff->name) < 0 && errno == EINTR)
|
||||
errno = 0;
|
||||
|
||||
free((Void_t*)ff);
|
||||
free((void*)ff);
|
||||
}
|
||||
(void)vtmtxunlock(_Sfmutex);
|
||||
}
|
||||
|
|
@ -104,17 +96,13 @@ Sfdisc_t* disc;
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
static void _rmfiles(void)
|
||||
#else
|
||||
static void _rmfiles()
|
||||
#endif
|
||||
{ reg File_t *ff, *next;
|
||||
|
||||
(void)vtmtxlock(_Sfmutex);
|
||||
for(ff = File; ff; ff = next)
|
||||
{ next = ff->next;
|
||||
_tmprmfile(ff->f, SF_CLOSING, NIL(Void_t*), ff->f->disc);
|
||||
_tmprmfile(ff->f, SF_CLOSING, NIL(void*), ff->f->disc);
|
||||
}
|
||||
(void)vtmtxunlock(_Sfmutex);
|
||||
}
|
||||
|
|
@ -124,13 +112,7 @@ static Sfdisc_t Rmdisc =
|
|||
|
||||
#endif /*_tmp_rmfail*/
|
||||
|
||||
#if __STD_C
|
||||
static int _rmtmp(Sfio_t* f, char* file)
|
||||
#else
|
||||
static int _rmtmp(f, file)
|
||||
Sfio_t* f;
|
||||
char* file;
|
||||
#endif
|
||||
{
|
||||
#if _tmp_rmfail /* remove only when stream is closed */
|
||||
reg File_t* ff;
|
||||
|
|
@ -159,12 +141,7 @@ char* file;
|
|||
#define TMPDFLT "/tmp"
|
||||
static char **Tmppath, **Tmpcur;
|
||||
|
||||
#if __STD_C
|
||||
char** _sfgetpath(char* path)
|
||||
#else
|
||||
char** _sfgetpath(path)
|
||||
char* path;
|
||||
#endif
|
||||
{ reg char *p, **dirs;
|
||||
reg int n;
|
||||
|
||||
|
|
@ -205,12 +182,7 @@ char* path;
|
|||
|
||||
#endif /*!_PACKAGE_ast*/
|
||||
|
||||
#if __STD_C
|
||||
static int _tmpfd(Sfio_t* f)
|
||||
#else
|
||||
static int _tmpfd(f)
|
||||
Sfio_t* f;
|
||||
#endif
|
||||
{
|
||||
reg char* file;
|
||||
int fd;
|
||||
|
|
@ -307,15 +279,7 @@ Sfio_t* f;
|
|||
return fd;
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
static int _tmpexcept(Sfio_t* f, int type, Void_t* val, Sfdisc_t* disc)
|
||||
#else
|
||||
static int _tmpexcept(f,type,val,disc)
|
||||
Sfio_t* f;
|
||||
int type;
|
||||
Void_t* val;
|
||||
Sfdisc_t* disc;
|
||||
#endif
|
||||
static int _tmpexcept(Sfio_t* f, int type, void* val, Sfdisc_t* disc)
|
||||
{
|
||||
reg int fd, m;
|
||||
reg Sfio_t* sf;
|
||||
|
|
@ -340,7 +304,7 @@ Sfdisc_t* disc;
|
|||
/* make sure that the notify function won't be called here since
|
||||
we are only interested in creating the file, not the stream */
|
||||
_Sfnotify = 0;
|
||||
sf = sfnew(&newf,NIL(Void_t*),(size_t)SF_UNBOUND,fd,SF_READ|SF_WRITE);
|
||||
sf = sfnew(&newf,NIL(void*),(size_t)SF_UNBOUND,fd,SF_READ|SF_WRITE);
|
||||
_Sfnotify = notify;
|
||||
if(!sf)
|
||||
return -1;
|
||||
|
|
@ -357,8 +321,8 @@ Sfdisc_t* disc;
|
|||
sfset(sf, (f->mode&(SF_READ|SF_WRITE)), 1);
|
||||
|
||||
/* now remake the old stream into the new image */
|
||||
memcpy((Void_t*)(&savf), (Void_t*)f, sizeof(Sfio_t));
|
||||
memcpy((Void_t*)f, (Void_t*)sf, sizeof(Sfio_t));
|
||||
memcpy((void*)(&savf), (void*)f, sizeof(Sfio_t));
|
||||
memcpy((void*)f, (void*)sf, sizeof(Sfio_t));
|
||||
f->push = savf.push;
|
||||
f->pool = savf.pool;
|
||||
f->rsrv = savf.rsrv;
|
||||
|
|
@ -373,12 +337,12 @@ Sfdisc_t* disc;
|
|||
if(savf.data)
|
||||
{ SFSTRSIZE(&savf);
|
||||
if(!(savf.flags&SF_MALLOC) )
|
||||
(void)sfsetbuf(f,(Void_t*)savf.data,savf.size);
|
||||
(void)sfsetbuf(f,(void*)savf.data,savf.size);
|
||||
if(savf.extent > 0)
|
||||
(void)sfwrite(f,(Void_t*)savf.data,(size_t)savf.extent);
|
||||
(void)sfwrite(f,(void*)savf.data,(size_t)savf.extent);
|
||||
(void)sfseek(f,(Sfoff_t)(savf.next - savf.data),SEEK_SET);
|
||||
if((savf.flags&SF_MALLOC) )
|
||||
free((Void_t*)savf.data);
|
||||
free((void*)savf.data);
|
||||
}
|
||||
|
||||
/* announce change of status */
|
||||
|
|
@ -396,12 +360,7 @@ Sfdisc_t* disc;
|
|||
return 1;
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
Sfio_t* sftmp(size_t s)
|
||||
#else
|
||||
Sfio_t* sftmp(s)
|
||||
size_t s;
|
||||
#endif
|
||||
{
|
||||
Sfio_t *f;
|
||||
int rv;
|
||||
|
|
@ -427,7 +386,7 @@ size_t s;
|
|||
|
||||
if(s == 0) /* make the file now */
|
||||
{ _Sfnotify = 0; /* local computation so no notification */
|
||||
rv = _tmpexcept(f,SF_DPOP,NIL(Void_t*),f->disc);
|
||||
rv = _tmpexcept(f,SF_DPOP,NIL(void*),f->disc);
|
||||
_Sfnotify = notify;
|
||||
if(rv < 0)
|
||||
{ sfclose(f);
|
||||
|
|
|
|||
|
|
@ -26,15 +26,7 @@
|
|||
**
|
||||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
#if __STD_C
|
||||
static int _uexcept(Sfio_t* f, int type, Void_t* val, Sfdisc_t* disc)
|
||||
#else
|
||||
static int _uexcept(f,type,val,disc)
|
||||
Sfio_t *f;
|
||||
int type;
|
||||
Void_t* val;
|
||||
Sfdisc_t *disc;
|
||||
#endif
|
||||
static int _uexcept(Sfio_t* f, int type, void* val, Sfdisc_t* disc)
|
||||
{
|
||||
NOTUSED(val);
|
||||
|
||||
|
|
@ -49,13 +41,8 @@ Sfdisc_t *disc;
|
|||
return 1;
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
int sfungetc(Sfio_t* f, int c)
|
||||
#else
|
||||
int sfungetc(f,c)
|
||||
Sfio_t* f; /* push back one byte to this stream */
|
||||
int c; /* the value to be pushed back */
|
||||
#endif
|
||||
int sfungetc(Sfio_t* f, /* push back one byte to this stream */
|
||||
int c) /* the value to be pushed back */
|
||||
{
|
||||
reg Sfio_t* uf;
|
||||
SFMTXDECL(f);
|
||||
|
|
|
|||
|
|
@ -53,13 +53,7 @@
|
|||
#endif /* _chr_ebcdic */
|
||||
#endif /* _PACKAGE_ast */
|
||||
|
||||
#if __STD_C
|
||||
static int chr2str(char* buf, int v)
|
||||
#else
|
||||
static int chr2str(buf, v)
|
||||
char* buf;
|
||||
int v;
|
||||
#endif
|
||||
{
|
||||
if(isprint(v) && v != '\\')
|
||||
{ *buf++ = v;
|
||||
|
|
@ -93,14 +87,9 @@ int v;
|
|||
#define _sffmt_small 1
|
||||
#endif
|
||||
|
||||
#if __STD_C
|
||||
int sfvprintf(Sfio_t* f, const char* form, va_list args)
|
||||
#else
|
||||
int sfvprintf(f,form,args)
|
||||
Sfio_t* f; /* file to print to */
|
||||
char* form; /* format to use */
|
||||
va_list args; /* arg list if !argf */
|
||||
#endif
|
||||
int sfvprintf(Sfio_t* f, /* file to print to */
|
||||
const char* form, /* format to use */
|
||||
va_list args) /* arg list if !argf */
|
||||
{
|
||||
int n, v=0, w, k, n_s, base, fmt, flags;
|
||||
Sflong_t lv;
|
||||
|
|
@ -111,7 +100,7 @@ va_list args; /* arg list if !argf */
|
|||
#endif
|
||||
ssize_t size;
|
||||
Sfdouble_t dval;
|
||||
Void_t* valp;
|
||||
void* valp;
|
||||
char *tls[2], **ls; /* for %..[separ]s */
|
||||
char* t_str; /* stuff between () */
|
||||
ssize_t n_str; /* its length */
|
||||
|
|
@ -147,7 +136,7 @@ va_list args; /* arg list if !argf */
|
|||
#define SMnputc(f,c,n) { if((o = SFNPUTC(f,c,n)) > 0 ) n_output += 1; \
|
||||
if(o != n) { SFBUF(f); goto done; } \
|
||||
}
|
||||
#define SMwrite(f,s,n) { if((o = SFWRITE(f,(Void_t*)s,n)) > 0 ) n_output += o; \
|
||||
#define SMwrite(f,s,n) { if((o = SFWRITE(f,(void*)s,n)) > 0 ) n_output += o; \
|
||||
if(o != n) { SFBUF(f); goto done; } \
|
||||
}
|
||||
#if _sffmt_small /* these macros are made smaller at some performance cost */
|
||||
|
|
@ -280,7 +269,7 @@ loop_fmt :
|
|||
LEFTP, 0, 0, 0,0,0,
|
||||
NIL(char*),0);
|
||||
n = (*ft->extf)
|
||||
(f,(Void_t*)&argv,ft);
|
||||
(f,(void*)&argv,ft);
|
||||
if(n < 0)
|
||||
goto pop_fmt;
|
||||
if(!(ft->flags&SFFMT_VALUE) )
|
||||
|
|
@ -385,7 +374,7 @@ loop_fmt :
|
|||
v = fp[n].argv.i;
|
||||
else if(ft && ft->extf)
|
||||
{ FMTSET(ft, form,args, '.',dot, 0, 0,0,0, NIL(char*), 0);
|
||||
if((*ft->extf)(f, (Void_t*)(&argv), ft) < 0)
|
||||
if((*ft->extf)(f, (void*)(&argv), ft) < 0)
|
||||
goto pop_fmt;
|
||||
fmt = ft->fmt;
|
||||
flags = (flags&~SFFMT_TYPES) | (ft->flags&SFFMT_TYPES);
|
||||
|
|
@ -443,7 +432,7 @@ loop_fmt :
|
|||
else if(ft && ft->extf)
|
||||
{ FMTSET(ft, form,args, 'I',sizeof(int), 0, 0,0,0,
|
||||
NIL(char*), 0);
|
||||
if((*ft->extf)(f, (Void_t*)(&argv), ft) < 0)
|
||||
if((*ft->extf)(f, (void*)(&argv), ft) < 0)
|
||||
goto pop_fmt;
|
||||
if(ft->flags&SFFMT_VALUE)
|
||||
size = argv.i;
|
||||
|
|
@ -546,7 +535,7 @@ loop_fmt :
|
|||
{ FMTSET(ft, form,args, fmt, size,flags, width,precis,base,
|
||||
t_str,n_str);
|
||||
SFEND(f); SFOPEN(f,0);
|
||||
v = (*ft->extf)(f, (Void_t*)(&argv), ft);
|
||||
v = (*ft->extf)(f, (void*)(&argv), ft);
|
||||
SFLOCK(f,0); SFBUF(f);
|
||||
|
||||
if(v < 0) /* no further processing */
|
||||
|
|
@ -605,7 +594,7 @@ loop_fmt :
|
|||
argv.d = va_arg(args,double);
|
||||
break;
|
||||
case SFFMT_POINTER:
|
||||
argv.vp = va_arg(args,Void_t*);
|
||||
argv.vp = va_arg(args,void*);
|
||||
break;
|
||||
case SFFMT_CHAR:
|
||||
if(base >= 0)
|
||||
|
|
@ -640,7 +629,7 @@ loop_fmt :
|
|||
goto pop_fmt;
|
||||
if(!argv.ft->form && ft ) /* change extension functions */
|
||||
{ if(ft->eventf &&
|
||||
(*ft->eventf)(f,SF_DPOP,(Void_t*)form,ft) < 0)
|
||||
(*ft->eventf)(f,SF_DPOP,(void*)form,ft) < 0)
|
||||
continue;
|
||||
fmstk->ft = ft = argv.ft;
|
||||
}
|
||||
|
|
@ -1404,8 +1393,8 @@ pop_fmt:
|
|||
while((fm = fmstk) ) /* pop the format stack and continue */
|
||||
{ if(fm->eventf)
|
||||
{ if(!form || !form[0])
|
||||
(*fm->eventf)(f,SF_FINAL,NIL(Void_t*),ft);
|
||||
else if((*fm->eventf)(f,SF_DPOP,(Void_t*)form,ft) < 0)
|
||||
(*fm->eventf)(f,SF_FINAL,NIL(void*),ft);
|
||||
else if((*fm->eventf)(f,SF_DPOP,(void*)form,ft) < 0)
|
||||
goto loop_fmt;
|
||||
}
|
||||
|
||||
|
|
@ -1429,7 +1418,7 @@ done:
|
|||
free(fp);
|
||||
while((fm = fmstk) )
|
||||
{ if(fm->eventf)
|
||||
(*fm->eventf)(f,SF_FINAL,NIL(Void_t*),fm->ft);
|
||||
(*fm->eventf)(f,SF_FINAL,NIL(void*),fm->ft);
|
||||
fmstk = fm->next;
|
||||
free(fm);
|
||||
}
|
||||
|
|
@ -1443,7 +1432,7 @@ done:
|
|||
|
||||
if((((flags = f->flags)&SF_SHARE) && !(flags&SF_PUBLIC) ) ||
|
||||
(n > 0 && (sp == data || (flags&SF_LINE) ) ) )
|
||||
(void)SFWRITE(f,(Void_t*)sp,n);
|
||||
(void)SFWRITE(f,(void*)sp,n);
|
||||
else f->next += n;
|
||||
|
||||
SFOPEN(f,0);
|
||||
|
|
|
|||
|
|
@ -36,13 +36,7 @@
|
|||
#include "sfstrtof.h"
|
||||
|
||||
/* refresh stream buffer - taking care of unseekable/share streams too */
|
||||
#if __STD_C
|
||||
static void _sfbuf(Sfio_t* f, int* peek)
|
||||
#else
|
||||
static void _sfbuf(f, peek)
|
||||
Sfio_t* f;
|
||||
int* peek;
|
||||
#endif
|
||||
{
|
||||
if(f->next >= f->endb)
|
||||
{ if(*peek) /* try peeking for a share stream if possible */
|
||||
|
|
@ -79,13 +73,7 @@ typedef struct _scan_s
|
|||
d = (sc)->d, endd = (sc)->endd, data = (sc)->data, \
|
||||
peek = (sc)->peek, n_input = (sc)->n_input)
|
||||
|
||||
#if __STD_C
|
||||
static int _scgetc(void* arg, int flag)
|
||||
#else
|
||||
static int _scgetc(arg, flag)
|
||||
void* arg;
|
||||
int flag;
|
||||
#endif
|
||||
{
|
||||
Scan_t *sc = (Scan_t*)arg;
|
||||
|
||||
|
|
@ -131,14 +119,9 @@ typedef struct _accept_s
|
|||
#endif
|
||||
} Accept_t;
|
||||
|
||||
#if __STD_C
|
||||
static char* _sfsetclass(const char* form, Accept_t* ac, int flags)
|
||||
#else
|
||||
static char* _sfsetclass(form, ac, flags)
|
||||
char* form; /* format string */
|
||||
Accept_t* ac; /* values of accepted characters */
|
||||
int flags; /* SFFMT_LONG for wchar_t */
|
||||
#endif
|
||||
static char* _sfsetclass(const char* form, /* format string */
|
||||
Accept_t* ac, /* values of accepted characters */
|
||||
int flags) /* SFFMT_LONG for wchar_t */
|
||||
{
|
||||
int c, endc, n;
|
||||
SFMBDCL(mbs)
|
||||
|
|
@ -190,13 +173,7 @@ int flags; /* SFFMT_LONG for wchar_t */
|
|||
}
|
||||
|
||||
#if _has_multibyte
|
||||
#if __STD_C
|
||||
static int _sfwaccept(wchar_t wc, Accept_t* ac)
|
||||
#else
|
||||
static int _sfwaccept(wc, ac)
|
||||
wchar_t wc;
|
||||
Accept_t* ac;
|
||||
#endif
|
||||
{
|
||||
int endc, c, n;
|
||||
wchar_t fwc;
|
||||
|
|
@ -226,21 +203,16 @@ Accept_t* ac;
|
|||
}
|
||||
|
||||
#if _has_multibyte == 1
|
||||
#define SFgetwc(sc,wc,fmt,ac,mbs) _sfgetwc(sc,wc,fmt,ac,(Void_t*)(mbs))
|
||||
#define SFgetwc(sc,wc,fmt,ac,mbs) _sfgetwc(sc,wc,fmt,ac,(void*)(mbs))
|
||||
#else
|
||||
#define SFgetwc(sc,wc,fmt,ac,mbs) _sfgetwc(sc,wc,fmt,ac,NIL(Void_t*))
|
||||
#define SFgetwc(sc,wc,fmt,ac,mbs) _sfgetwc(sc,wc,fmt,ac,NIL(void*))
|
||||
#endif
|
||||
|
||||
#if __STD_C
|
||||
static int _sfgetwc(Scan_t* sc, wchar_t* wc, int fmt, Accept_t* ac, Void_t *mbs)
|
||||
#else
|
||||
static int _sfgetwc(sc, wc, fmt, ac, mbs)
|
||||
Scan_t* sc; /* the scanning handle */
|
||||
wchar_t* wc; /* to return a scanned wchar_t */
|
||||
int fmt; /* %s, %c, %[ */
|
||||
Accept_t* ac; /* accept handle for %[ */
|
||||
Void_t* mbs; /* multibyte parsing state */
|
||||
#endif
|
||||
static int _sfgetwc(Scan_t* sc, /* the scanning handle */
|
||||
wchar_t* wc, /* to return a scanned wchar_t */
|
||||
int fmt, /* %s, %c, %[ */
|
||||
Accept_t* ac, /* accept handle for %[ */
|
||||
void* mbs) /* multibyte parsing state */
|
||||
{
|
||||
int n, v;
|
||||
char b[16]; /* assuming that SFMBMAX <= 16! */
|
||||
|
|
@ -260,7 +232,7 @@ Void_t* mbs; /* multibyte parsing state */
|
|||
}
|
||||
|
||||
for(n = 0; n < SFMBMAX; )
|
||||
{ if((v = _scgetc((Void_t*)sc, 0)) <= 0)
|
||||
{ if((v = _scgetc((void*)sc, 0)) <= 0)
|
||||
goto no_match;
|
||||
else b[n++] = v;
|
||||
|
||||
|
|
@ -297,14 +269,9 @@ no_match: /* this unget is lossy on a stream with small buffer */
|
|||
#endif /*_has_multibyte*/
|
||||
|
||||
|
||||
#if __STD_C
|
||||
int sfvscanf(Sfio_t* f, reg const char* form, va_list args)
|
||||
#else
|
||||
int sfvscanf(f,form,args)
|
||||
Sfio_t* f; /* file to be scanned */
|
||||
reg char* form; /* scanning format */
|
||||
va_list args;
|
||||
#endif
|
||||
int sfvscanf(Sfio_t* f, /* file to be scanned */
|
||||
reg const char* form, /* scanning format */
|
||||
va_list args)
|
||||
{
|
||||
reg int inp, shift, base, width;
|
||||
ssize_t size;
|
||||
|
|
@ -330,7 +297,7 @@ va_list args;
|
|||
SFMBDCL(mbs)
|
||||
#endif
|
||||
|
||||
Void_t* value; /* location to assign scanned value */
|
||||
void* value; /* location to assign scanned value */
|
||||
char* t_str;
|
||||
ssize_t n_str;
|
||||
|
||||
|
|
@ -342,7 +309,7 @@ va_list args;
|
|||
#define SFlen(f) (d - data)
|
||||
#define SFinit(f) ((peek = f->extent < 0 && (f->flags&SF_SHARE)), SFbuf(f) )
|
||||
#define SFend(f) ((n_input += SFlen(f)), \
|
||||
(peek ? SFREAD(f,(Void_t*)data,SFlen(f)) : ((f->next = d),0)) )
|
||||
(peek ? SFREAD(f,(void*)data,SFlen(f)) : ((f->next = d),0)) )
|
||||
#define SFgetc(f,c) ((c) = (d < endd || (SFend(f), SFbuf(f), d < endd)) ? \
|
||||
(int)(*d++) : -1 )
|
||||
#define SFungetc(f,c) (d -= 1)
|
||||
|
|
@ -433,7 +400,7 @@ loop_fmt:
|
|||
base = 10; size = -1;
|
||||
width = dot = 0;
|
||||
t_str = NIL(char*); n_str = 0;
|
||||
value = NIL(Void_t*);
|
||||
value = NIL(void*);
|
||||
argp = -1;
|
||||
|
||||
loop_flags: /* LOOP FOR FLAGS, WIDTH, BASE, TYPE */
|
||||
|
|
@ -476,7 +443,7 @@ loop_fmt:
|
|||
LEFTP, 0, 0, 0,0,0,
|
||||
NIL(char*),0);
|
||||
n = (*ft->extf)
|
||||
(f,(Void_t*)&argv,ft);
|
||||
(f,(void*)&argv,ft);
|
||||
if(n < 0)
|
||||
goto pop_fmt;
|
||||
if(!(ft->flags&SFFMT_VALUE) )
|
||||
|
|
@ -521,7 +488,7 @@ loop_fmt:
|
|||
else if(ft && ft->extf )
|
||||
{ FMTSET(ft, form,args, '.',dot, 0, 0,0,0,
|
||||
NIL(char*), 0);
|
||||
if((*ft->extf)(f, (Void_t*)(&argv), ft) < 0)
|
||||
if((*ft->extf)(f, (void*)(&argv), ft) < 0)
|
||||
goto pop_fmt;
|
||||
if(ft->flags&SFFMT_VALUE)
|
||||
v = argv.i;
|
||||
|
|
@ -574,7 +541,7 @@ loop_fmt:
|
|||
else if(ft && ft->extf )
|
||||
{ FMTSET(ft, form,args, 'I',sizeof(int), 0, 0,0,0,
|
||||
NIL(char*), 0);
|
||||
if((*ft->extf)(f, (Void_t*)(&argv), ft) < 0)
|
||||
if((*ft->extf)(f, (void*)(&argv), ft) < 0)
|
||||
goto pop_fmt;
|
||||
if(ft->flags&SFFMT_VALUE)
|
||||
size = argv.i;
|
||||
|
|
@ -682,7 +649,7 @@ loop_fmt:
|
|||
else if(ft && ft->extf)
|
||||
{ FMTSET(ft, form,args, fmt, size,flags, width,0,base, t_str,n_str);
|
||||
SFend(f); SFOPEN(f,0);
|
||||
v = (*ft->extf)(f, (Void_t*)&argv, ft);
|
||||
v = (*ft->extf)(f, (void*)&argv, ft);
|
||||
SFLOCK(f,0); SFbuf(f);
|
||||
|
||||
if(v < 0)
|
||||
|
|
@ -713,7 +680,7 @@ loop_fmt:
|
|||
continue;
|
||||
if(!argv.ft->form && ft ) /* change extension functions */
|
||||
{ if(ft->eventf &&
|
||||
(*ft->eventf)(f,SF_DPOP,(Void_t*)form,ft) < 0)
|
||||
(*ft->eventf)(f,SF_DPOP,(void*)form,ft) < 0)
|
||||
continue;
|
||||
fmstk->ft = ft = argv.ft;
|
||||
}
|
||||
|
|
@ -750,7 +717,7 @@ loop_fmt:
|
|||
|
||||
/* get the address to assign value */
|
||||
if(!value && !(flags&SFFMT_SKIP) )
|
||||
value = va_arg(args,Void_t*);
|
||||
value = va_arg(args,void*);
|
||||
|
||||
if(fmt == 'n') /* return length of consumed input */
|
||||
{
|
||||
|
|
@ -785,7 +752,7 @@ loop_fmt:
|
|||
|
||||
if(_Sftype[fmt] == SFFMT_FLOAT)
|
||||
{ SFungetc(f,inp); SCinit(&scd,1);
|
||||
argv.ld = _sfdscan((Void_t*)(&scd), _scgetc);
|
||||
argv.ld = _sfdscan((void*)(&scd), _scgetc);
|
||||
SCend(&scd,1);
|
||||
|
||||
if(scd.error >= 0)
|
||||
|
|
@ -931,9 +898,9 @@ loop_fmt:
|
|||
|
||||
if(fmt == 'p')
|
||||
#if _more_void_int
|
||||
*((Void_t**)value) = (Void_t*)((ulong)argv.lu);
|
||||
*((void**)value) = (void*)((ulong)argv.lu);
|
||||
#else
|
||||
*((Void_t**)value) = (Void_t*)((uint)argv.lu);
|
||||
*((void**)value) = (void*)((uint)argv.lu);
|
||||
#endif
|
||||
#if !_ast_intmax_long
|
||||
else if(size == sizeof(Sflong_t))
|
||||
|
|
@ -1057,8 +1024,8 @@ pop_fmt:
|
|||
while((fm = fmstk) ) /* pop the format stack and continue */
|
||||
{ if(fm->eventf)
|
||||
{ if(!form || !form[0])
|
||||
(*fm->eventf)(f,SF_FINAL,NIL(Void_t*),ft);
|
||||
else if((*fm->eventf)(f,SF_DPOP,(Void_t*)form,ft) < 0)
|
||||
(*fm->eventf)(f,SF_FINAL,NIL(void*),ft);
|
||||
else if((*fm->eventf)(f,SF_DPOP,(void*)form,ft) < 0)
|
||||
goto loop_fmt;
|
||||
}
|
||||
|
||||
|
|
@ -1082,7 +1049,7 @@ done:
|
|||
free(fp);
|
||||
while((fm = fmstk) )
|
||||
{ if(fm->eventf)
|
||||
(*fm->eventf)(f,SF_FINAL,NIL(Void_t*),fm->ft);
|
||||
(*fm->eventf)(f,SF_FINAL,NIL(void*),fm->ft);
|
||||
fmstk = fm->next;
|
||||
free(fm);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,14 +27,9 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
int sfwalk(Sfwalk_f walkf, Void_t* data, int type)
|
||||
#else
|
||||
int sfwalk(walkf, data, type)
|
||||
Sfwalk_f walkf; /* return <0: stop, >=0: continue */
|
||||
Void_t* data;
|
||||
int type; /* walk streams with all given flags */
|
||||
#endif
|
||||
int sfwalk(Sfwalk_f walkf, /* return <0: stop, >=0: continue */
|
||||
void* data,
|
||||
int type) /* walk streams with all given flags */
|
||||
{
|
||||
Sfpool_t *p;
|
||||
Sfio_t *f;
|
||||
|
|
|
|||
|
|
@ -31,14 +31,7 @@
|
|||
*/
|
||||
|
||||
/* hole preserving writes */
|
||||
#if __STD_C
|
||||
static ssize_t sfoutput(Sfio_t* f, char* buf, size_t n)
|
||||
#else
|
||||
static ssize_t sfoutput(f,buf,n)
|
||||
Sfio_t* f;
|
||||
char* buf;
|
||||
size_t n;
|
||||
#endif
|
||||
{ reg char *sp, *wbuf, *endbuf;
|
||||
reg ssize_t s, w, wr;
|
||||
|
||||
|
|
@ -125,15 +118,7 @@ size_t n;
|
|||
return w > 0 ? w : -1;
|
||||
}
|
||||
|
||||
#if __STD_C
|
||||
ssize_t sfwr(Sfio_t* f, const Void_t* buf, size_t n, Sfdisc_t* disc)
|
||||
#else
|
||||
ssize_t sfwr(f,buf,n,disc)
|
||||
Sfio_t* f;
|
||||
Void_t* buf;
|
||||
size_t n;
|
||||
Sfdisc_t* disc;
|
||||
#endif
|
||||
ssize_t sfwr(Sfio_t* f, const void* buf, size_t n, Sfdisc_t* disc)
|
||||
{
|
||||
reg ssize_t w;
|
||||
reg Sfdisc_t* dc;
|
||||
|
|
|
|||
|
|
@ -27,14 +27,9 @@
|
|||
** Written by Kiem-Phong Vo.
|
||||
*/
|
||||
|
||||
#if __STD_C
|
||||
ssize_t sfwrite(Sfio_t* f, const Void_t* buf, size_t n)
|
||||
#else
|
||||
ssize_t sfwrite(f,buf,n)
|
||||
Sfio_t* f; /* write to this stream. */
|
||||
Void_t* buf; /* buffer to be written. */
|
||||
size_t n; /* number of bytes. */
|
||||
#endif
|
||||
ssize_t sfwrite(Sfio_t* f, /* write to this stream. */
|
||||
const void* buf, /* buffer to be written. */
|
||||
size_t n) /* number of bytes. */
|
||||
{
|
||||
reg uchar *s, *begs, *next;
|
||||
reg ssize_t w;
|
||||
|
|
|
|||
|
|
@ -91,30 +91,26 @@ typedef struct _vtmutex_s Vtmutex_t;
|
|||
typedef struct _vtonce_s Vtonce_t;
|
||||
typedef struct _vthread_s Vthread_t;
|
||||
|
||||
_BEGIN_EXTERNS_
|
||||
extern Vthread_t* vtopen(Vthread_t*, int);
|
||||
extern int vtclose(Vthread_t*);
|
||||
extern int vtset(Vthread_t*, int, void*);
|
||||
extern int vtrun(Vthread_t*, void*(*)(void*), void*);
|
||||
extern int vtkill(Vthread_t*);
|
||||
extern int vtwait(Vthread_t*);
|
||||
|
||||
extern Vthread_t* vtopen _ARG_((Vthread_t*, int));
|
||||
extern int vtclose _ARG_((Vthread_t*));
|
||||
extern int vtset _ARG_((Vthread_t*, int, Void_t*));
|
||||
extern int vtrun _ARG_((Vthread_t*, void*(*)(void*), void*));
|
||||
extern int vtkill _ARG_((Vthread_t*));
|
||||
extern int vtwait _ARG_((Vthread_t*));
|
||||
extern int vtonce(Vtonce_t*, void(*)() );
|
||||
|
||||
extern int vtonce _ARG_((Vtonce_t*, void(*)() ));
|
||||
extern Vtmutex_t* vtmtxopen(Vtmutex_t*, int);
|
||||
extern int vtmtxclose(Vtmutex_t*);
|
||||
extern int vtmtxlock(Vtmutex_t*);
|
||||
extern int vtmtxtrylock(Vtmutex_t*);
|
||||
extern int vtmtxunlock(Vtmutex_t*);
|
||||
extern int vtmtxclrlock(Vtmutex_t*);
|
||||
|
||||
extern Vtmutex_t* vtmtxopen _ARG_((Vtmutex_t*, int));
|
||||
extern int vtmtxclose _ARG_((Vtmutex_t*));
|
||||
extern int vtmtxlock _ARG_((Vtmutex_t*));
|
||||
extern int vtmtxtrylock _ARG_((Vtmutex_t*));
|
||||
extern int vtmtxunlock _ARG_((Vtmutex_t*));
|
||||
extern int vtmtxclrlock _ARG_((Vtmutex_t*));
|
||||
|
||||
extern Void_t* vtstatus _ARG_((Vthread_t*));
|
||||
extern int vterror _ARG_((Vthread_t*));
|
||||
extern int vtmtxerror _ARG_((Vtmutex_t*));
|
||||
extern int vtonceerror _ARG_((Vtonce_t*));
|
||||
|
||||
_END_EXTERNS_
|
||||
extern void* vtstatus(Vthread_t*);
|
||||
extern int vterror(Vthread_t*);
|
||||
extern int vtmtxerror(Vtmutex_t*);
|
||||
extern int vtonceerror(Vtonce_t*);
|
||||
|
||||
#if vt_threaded
|
||||
|
||||
|
|
@ -135,7 +131,7 @@ struct _vthread_s
|
|||
size_t stack; /* stack size */
|
||||
int state; /* execution state */
|
||||
int error; /* error status */
|
||||
Void_t* exit; /* exit value */
|
||||
void* exit; /* exit value */
|
||||
};
|
||||
|
||||
/* structure for exactly once execution */
|
||||
|
|
@ -197,7 +193,7 @@ typedef int _vtattr_t;
|
|||
#define vtmtxunlock(mtx) (-1)
|
||||
#define vtmtxclrlock(mtx) (-1)
|
||||
|
||||
#define vtstatus(vt) ((Void_t*)0)
|
||||
#define vtstatus(vt) ((void*)0)
|
||||
#define vterror(vt) (0)
|
||||
#define vtmtxerror(mtx) (0)
|
||||
#define vtonceerror(once) (0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue