diff --git a/src/lib/libast/Mamfile b/src/lib/libast/Mamfile index 4b8c56267..f6930f03a 100644 --- a/src/lib/libast/Mamfile +++ b/src/lib/libast/Mamfile @@ -1608,12 +1608,6 @@ make install done ast_tty.h dontcare generated prev ast_time.h implicit prev include/ast.h implicit - make sfio/vthread.h implicit - prev windows.h implicit - prev std/endian.h implicit - prev include/error.h implicit - prev ast_common.h implicit - done sfio/vthread.h dontcare make include/sfio_t.h implicit prev include/sfio.h implicit done include/sfio_t.h dontcare @@ -4498,14 +4492,6 @@ make install prev sfio/sfgetm.c exec - ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} -I. -Icomp -Iport -Isfio -Iinclude -Istd -I${INSTALLROOT}/include -D_PACKAGE_ast -c sfio/sfgetm.c done sfgetm.o generated - make sfmutex.o - make sfio/sfmutex.c - prev sfio/sfhdr.h implicit - done sfio/sfmutex.c - meta sfmutex.o %.c>%.o sfio/sfmutex.c sfmutex - prev sfio/sfmutex.c - exec - ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} -I. -Icomp -Iport -Isfio -Iinclude -Istd -I${INSTALLROOT}/include -D_PACKAGE_ast -c sfio/sfmutex.c - done sfmutex.o generated make sfputm.o make sfio/sfputm.c prev sfio/sfhdr.h implicit @@ -6069,7 +6055,7 @@ make install exec - ${AR} rc libast.a streval.o strexpr.o strmatch.o strcopy.o modei.o modex.o strmode.o strlcat.o strlcpy.o strlook.o strncopy.o strsearch.o strpsearch.o stresc.o stropt.o strtape.o strpcmp.o strnpcmp.o strvcmp.o strnvcmp.o tok.o tokline.o tokscan.o pathaccess.o pathcat.o pathcanon.o pathcheck.o pathpath.o pathexists.o pathfind.o pathicase.o pathkey.o pathprobe.o pathrepl.o pathnative.o pathposix.o pathtemp.o pathtmp.o pathstat.o pathgetlink.o pathsetlink.o pathbin.o pathshell.o pathcd.o pathprog.o ftwalk.o ftwflags.o fts.o astintercept.o conformance.o getenv.o setenviron.o optget.o optjoin.o optesc.o optctx.o strsort.o struniq.o magic.o mime.o mimetype.o signal.o sigflag.o systrace.o error.o errorf.o errormsg.o errorx.o localeconv.o setlocale.o translate.o catopen.o iconv.o lc.o lctab.o mc.o base64.o recfmt.o recstr.o reclen.o fmtrec.o fmtbase.o fmtbuf.o fmtclock.o fmtdev.o fmtelapsed.o fmterror.o fmtesc.o fmtfmt.o fmtfs.o fmtident.o fmtint.o fmtip4.o fmtip6.o fmtls.o fmtmatch.o fmtmode.o fmtnum.o fmtperm.o fmtre.o fmttime.o exec - ${AR} rc libast.a fmtuid.o fmtgid.o fmtsignal.o fmtscale.o fmttmx.o fmttv.o fmtversion.o strelapsed.o strperm.o struid.o strgid.o strtoip4.o strtoip6.o stack.o stk.o swapget.o swapmem.o swapop.o swapput.o sigdata.o sigcrit.o sigunblock.o procopen.o procclose.o procrun.o procfree.o tmdate.o tmequiv.o tmfix.o tmfmt.o tmform.o tmgoff.o tminit.o tmleap.o tmlex.o tmlocale.o tmmake.o tmpoff.o tmscan.o tmsleep.o tmtime.o tmtype.o tmweek.o tmword.o tmzone.o tmxdate.o tmxduration.o tmxfmt.o tmxgettime.o tmxleap.o tmxmake.o tmxscan.o tmxsettime.o tmxsleep.o tmxtime.o tmxtouch.o tvcmp.o tvgettime.o tvsettime.o tvsleep.o tvtouch.o cmdarg.o vecargs.o vecfile.o vecfree.o vecload.o vecstring.o univdata.o touch.o mnt.o debug.o memccpy.o memchr.o memcmp.o memcpy.o memdup.o memmove.o memset.o mkdir.o mkfifo.o mknod.o rmdir.o remove.o rename.o link.o unlink.o strdup.o strchr.o strrchr.o strstr.o strtod.o strtold.o strtol.o strtoll.o strtoul.o strtoull.o strton.o strtonll.o strntod.o strntold.o strnton.o exec - ${AR} rc libast.a strntonll.o strntol.o strntoll.o strntoul.o strntoull.o strcasecmp.o strncasecmp.o strerror.o mktemp.o tmpnam.o fsync.o execlp.o execve.o execvp.o execvpe.o spawnveg.o vfork.o killpg.o hsearch.o tsearch.o getlogin.o putenv.o setenv.o unsetenv.o lstat.o statvfs.o eaccess.o gross.o omitted.o readlink.o symlink.o getpgrp.o setpgid.o setsid.o waitpid.o fcntl.o open.o atexit.o getdents.o getwd.o dup2.o errno.o getpreroot.o ispreroot.o realopen.o setpreroot.o getgroups.o mount.o system.o iblocks.o modedata.o tmdata.o memfatal.o sfkeyprintf.o sfdcdio.o sfdcdos.o sfdcfilter.o sfdcseekable.o sfdcslow.o sfdcsubstr.o sfdctee.o sfdcunion.o sfdcmore.o sfdcprefix.o wc.o wc2utf8.o basename.o closelog.o dirname.o fmtmsglib.o fnmatch.o ftw.o getdate.o getsubopt.o glob.o nftw.o openlog.o re_comp.o resolvepath.o realpath.o regcmp.o regexp.o setlogmask.o strftime.o strptime.o swab.o syslog.o tempnam.o wordexp.o mktime.o regalloc.o regclass.o regcoll.o regcomp.o regcache.o regdecomp.o regerror.o regexec.o regfatal.o reginit.o - exec - ${AR} rc libast.a regnexec.o regsubcomp.o regsubexec.o regsub.o regrecord.o regrexec.o regstat.o dtclose.o dtdisc.o dthash.o dtlist.o dtmethod.o dtopen.o dtstat.o dtstrhash.o dttree.o dtuser.o dtview.o dtwalk.o dtnew.o dtcomp.o sfclose.o sfclrlock.o sfdisc.o sfdlen.o sfexcept.o sfgetl.o sfgetu.o sfcvt.o sfecvt.o sffcvt.o sfextern.o sffilbuf.o sfflsbuf.o sfprints.o sfgetd.o sfgetr.o sfllen.o sfmode.o sfmove.o sfnew.o sfpkrd.o sfnotify.o sfnputc.o sfopen.o sfpeek.o sfpoll.o sfpool.o sfpopen.o sfprintf.o sfputd.o sfputl.o sfputr.o sfputu.o sfrd.o sfread.o sfreserve.o sfscanf.o sfseek.o sfset.o sfsetbuf.o sfsetfd.o sfsize.o sfsk.o sfstack.o sfstrtod.o sfsync.o sfswap.o sftable.o sftell.o sftmp.o sfungetc.o sfvprintf.o sfvscanf.o sfwr.o sfwrite.o sfpurge.o sfraise.o sfwalk.o sfgetm.o sfmutex.o sfputm.o sfresize.o _sfclrerr.o _sfeof.o _sferror.o _sffileno.o _sfopen.o _sfstacked.o _sfvalue.o _sfgetc.o _sfgetl.o _sfgetl2.o _sfgetu.o _sfgetu2.o _sfdlen.o _sfllen.o _sfslen.o _sfulen.o _sfputc.o _sfputd.o _sfputl.o _sfputm.o + exec - ${AR} rc libast.a regnexec.o regsubcomp.o regsubexec.o regsub.o regrecord.o regrexec.o regstat.o dtclose.o dtdisc.o dthash.o dtlist.o dtmethod.o dtopen.o dtstat.o dtstrhash.o dttree.o dtuser.o dtview.o dtwalk.o dtnew.o dtcomp.o sfclose.o sfclrlock.o sfdisc.o sfdlen.o sfexcept.o sfgetl.o sfgetu.o sfcvt.o sfecvt.o sffcvt.o sfextern.o sffilbuf.o sfflsbuf.o sfprints.o sfgetd.o sfgetr.o sfllen.o sfmode.o sfmove.o sfnew.o sfpkrd.o sfnotify.o sfnputc.o sfopen.o sfpeek.o sfpoll.o sfpool.o sfpopen.o sfprintf.o sfputd.o sfputl.o sfputr.o sfputu.o sfrd.o sfread.o sfreserve.o sfscanf.o sfseek.o sfset.o sfsetbuf.o sfsetfd.o sfsize.o sfsk.o sfstack.o sfstrtod.o sfsync.o sfswap.o sftable.o sftell.o sftmp.o sfungetc.o sfvprintf.o sfvscanf.o sfwr.o sfwrite.o sfpurge.o sfraise.o sfwalk.o sfgetm.o sfputm.o sfresize.o _sfclrerr.o _sfeof.o _sferror.o _sffileno.o _sfopen.o _sfstacked.o _sfvalue.o _sfgetc.o _sfgetl.o _sfgetl2.o _sfgetu.o _sfgetu2.o _sfdlen.o _sfllen.o _sfslen.o _sfulen.o _sfputc.o _sfputd.o _sfputl.o _sfputm.o exec - ${AR} rc libast.a _sfputu.o clearerr.o fclose.o fdopen.o feof.o ferror.o fflush.o fgetc.o fgetpos.o fgets.o fileno.o fopen.o fprintf.o fpurge.o fputc.o fputs.o fread.o freopen.o fscanf.o fseek.o fseeko.o fsetpos.o ftell.o ftello.o fwrite.o flockfile.o ftrylockfile.o funlockfile.o getc.o getchar.o getw.o pclose.o popen.o printf.o putc.o putchar.o puts.o putw.o rewind.o scanf.o setbuf.o setbuffer.o setlinebuf.o setvbuf.o snprintf.o sprintf.o sscanf.o asprintf.o vasprintf.o tmpfile.o ungetc.o vfprintf.o vfscanf.o vprintf.o vscanf.o vsnprintf.o vsprintf.o vsscanf.o _doprnt.o _doscan.o _filbuf.o _flsbuf.o _stdfun.o _stdopen.o _stdprintf.o _stdscanf.o _stdsprnt.o _stdvbuf.o _stdvsnprnt.o _stdvsprnt.o _stdvsscn.o fgetwc.o fwprintf.o putwchar.o vfwscanf.o wprintf.o fgetws.o fwscanf.o swprintf.o vswprintf.o wscanf.o fputwc.o getwc.o swscanf.o vswscanf.o fputws.o getwchar.o ungetwc.o vwprintf.o fwide.o putwc.o vfwprintf.o vwscanf.o stdio_c99.o fcloseall.o fmemopen.o getdelim.o getline.o frexp.o frexpl.o astcopy.o exec - ${AR} rc libast.a astconf.o astdynamic.o astquery.o astwinsize.o conftab.o aststatic.o getopt.o getoptl.o aso.o asolock.o asometh.o asorelax.o aso-sem.o aso-fcntl.o vmbest.o vmclear.o vmclose.o vmdcheap.o vmdebug.o vmdisc.o vmexit.o vmlast.o vmopen.o vmpool.o vmprivate.o vmprofile.o vmregion.o vmsegment.o vmset.o vmstat.o vmstrdup.o vmtrace.o vmwalk.o vmmopen.o malloc.o vmgetmem.o a64l.o acosh.o asinh.o atanh.o cbrt.o crypt.o erf.o err.o exp.o exp__E.o expm1.o gamma.o getpass.o lgamma.o log.o log1p.o log__L.o rand48.o random.o rcmd.o rint.o support.o exec - (ranlib libast.a) >/dev/null 2>&1 || true diff --git a/src/lib/libast/include/sfio.h b/src/lib/libast/include/sfio.h index 5f20507dd..a8169e5f8 100644 --- a/src/lib/libast/include/sfio.h +++ b/src/lib/libast/include/sfio.h @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -23,7 +23,7 @@ #ifndef _SFIO_H #define _SFIO_H 1 -#define SFIO_VERSION 20090915L +#define SFIO_VERSION 20220212L /* Public header file for the sfio library ** @@ -72,7 +72,7 @@ struct _sffmt_s Sffmtevent_f eventf; /* process events */ char* form; /* format string to stack */ - va_list args; /* corresponding arg list */ + va_list args; /* corresponding arg list */ int fmt; /* format character */ ssize_t size; /* object size */ @@ -92,7 +92,7 @@ struct _sffmt_s ((type) ? ((fe)->version = SFIO_VERSION) : (fe)->version) #define SFFMT_SSHORT 000000010 /* 'hh' flag, char */ -#define SFFMT_TFLAG 000000020 /* 't' flag, ptrdiff_t */ +#define SFFMT_TFLAG 000000020 /* 't' flag, ptrdiff_t */ #define SFFMT_ZFLAG 000000040 /* 'z' flag, size_t */ #define SFFMT_LEFT 000000100 /* left-justification */ @@ -114,12 +114,6 @@ struct _sffmt_s #define SFFMT_CHOP 020000000 /* chop long string values from left */ #define SFFMT_SET 037777770 /* flags settable on calling extf */ -/* for sfmutex() call */ -#define SFMTX_LOCK 0 /* up mutex count */ -#define SFMTX_TRYLOCK 1 /* try to up mutex count */ -#define SFMTX_UNLOCK 2 /* down mutex count */ -#define SFMTX_CLRLOCK 3 /* clear mutex count */ - /* various constants */ #ifndef NULL #define NULL 0 @@ -146,7 +140,6 @@ struct _sffmt_s #define SF_STATIC 0001000 /* a stream that cannot be freed */ #define SF_IOCHECK 0002000 /* call exceptf before doing IO */ #define SF_PUBLIC 0004000 /* SF_SHARE and follow physical seek */ -#define SF_MTSAFE 0010000 /* need thread safety */ #define SF_WHOLE 0020000 /* preserve wholeness of sfwrite/sfputr */ #define SF_IOINTR 0040000 /* return on interrupts */ #define SF_WCWIDTH 0100000 /* wcwidth display stream */ @@ -187,7 +180,6 @@ struct _sffmt_s /* for the notify function and discipline exception */ #define SF_NEW 0 /* new stream */ #define SF_SETFD (-1) /* about to set the file descriptor */ -#define SF_MTACCESS (-2) /* starting a multi-threaded stream */ #define SF_BUFSIZE 8192 /* default buffer size */ #define SF_UNBOUND (-1) /* unbounded buffer size */ @@ -271,9 +263,6 @@ extern int sfsscanf(const char*, const char*, ...); extern int sfvsscanf(const char*, const char*, va_list); extern int sfvscanf(Sfio_t*, const char*, va_list); -/* mutex locking for thread-safety */ -extern int sfmutex(Sfio_t*, int); - /* io functions with discipline continuation */ extern ssize_t sfrd(Sfio_t*, void*, size_t, Sfdisc_t*); extern ssize_t sfwr(Sfio_t*, const void*, size_t, Sfdisc_t*); diff --git a/src/lib/libast/include/sfio_t.h b/src/lib/libast/include/sfio_t.h index d15fa0643..fc1f1f91a 100644 --- a/src/lib/libast/include/sfio_t.h +++ b/src/lib/libast/include/sfio_t.h @@ -43,7 +43,6 @@ struct _sfpool_s* pool; /* the pool containing this */ \ struct _sfrsrv_s* rsrv; /* reserved buffer */ \ struct _sfproc_s* proc; /* coprocess ID, etc. */ \ - void* mutex; /* mutex for thread-safety */ \ void* stdio; /* stdio FILE if any */ \ Sfoff_t lpos; /* last seek position */ \ size_t iosz; /* preferred size for I/O */ \ @@ -70,7 +69,7 @@ #define SF_RDWRSTR (SF_RDWR|SF_STRING) /* for static initialization of an Sfio_t structure */ -#define SFNEW(data,size,file,type,disc,mutex) \ +#define SFNEW(data,size,file,type,disc) \ { (unsigned char*)(data), /* next */ \ (unsigned char*)(data), /* endw */ \ (unsigned char*)(data), /* endr */ \ @@ -91,7 +90,6 @@ (struct _sfpool_s*)0, /* pool */ \ (struct _sfrsrv_s*)0, /* rsrv */ \ (struct _sfproc_s*)0, /* proc */ \ - (mutex), /* mutex */ \ (void*)0, /* stdio */ \ (Sfoff_t)0, /* lpos */ \ (size_t)0, /* iosz */ \ @@ -99,7 +97,7 @@ } /* function to clear an Sfio_t structure */ -#define SFCLEAR(f,mtx) \ +#define SFCLEAR(f) \ ( (f)->next = (unsigned char*)0, /* next */ \ (f)->endw = (unsigned char*)0, /* endw */ \ (f)->endr = (unsigned char*)0, /* endr */ \ @@ -120,7 +118,6 @@ (f)->pool = (struct _sfpool_s*)0, /* pool */ \ (f)->rsrv = (struct _sfrsrv_s*)0, /* rsrv */ \ (f)->proc = (struct _sfproc_s*)0, /* proc */ \ - (f)->mutex = (mtx), /* mutex */ \ (f)->stdio = (void*)0, /* stdio */ \ (f)->lpos = (Sfoff_t)0, /* lpos */ \ (f)->iosz = (size_t)0, /* iosz */ \ diff --git a/src/lib/libast/man/sfio.3 b/src/lib/libast/man/sfio.3 index 6f45db5fc..bb3d41694 100644 --- a/src/lib/libast/man/sfio.3 +++ b/src/lib/libast/man/sfio.3 @@ -1,5 +1,5 @@ .fp 5 CW -.TH SFIO 3 "01 June 2008" +.TH SFIO 3 "12 February 2022" .SH NAME \fBsfio\fR \- safe/fast string/file input/output .SH SYNOPSIS @@ -63,7 +63,6 @@ SF_MALLOC SF_STATIC SF_IOCHECK SF_WHOLE -SF_MTSAFE SF_IOINTR .ft 1 .fi @@ -76,18 +75,6 @@ Sfio_t* sfpopen(Sfio_t* f, const char* cmd, const char* mode); Sfio_t* sftmp(size_t size); int sfclose(Sfio_t* f); - -.ft 1 -.fi -.Ss "THREAD SAFETY" -.nf -.ft 5 -int sfmutex(Sfio_t* f, int type); - -SFMTX_LOCK -SFMTX_TRYLOCK -SFMTX_UNLOCK -SFMTX_CLRLOCK .ft 1 .fi .Ss "INPUT/OUTPUT OPERATIONS" @@ -306,19 +293,8 @@ There are three \fIstandard streams\fP: \f3sfstdout\fP for normal output (file descriptor \f31\fP), and \f3sfstderr\fP for error output (file descriptor \f32\fP). -.Ss "LIBRARIES" .PP -This version of Sfio can be built and used for both single-threaded and multi-threaded -environments. In the former case, streams are not protected from -simultaneous accesses by different threads. In the latter case, a stream -is typically locked with a mutex during access so that another thread -trying to access the same stream will block until the mutex is released. - -A program that does not use multiple threads can link with \fBlibsfio.a\fP -while a program that uses multiple threads should link with \fBlibsfio-mt.a\fP. -The libraries \fBlibstdio.a\fP and \fBlibstdio-mt.a\fP provide -corresponding Stdio functions to link with code already compiled using the -native header \fBstdio.h\fP instead of the one provided by Sfio. +This version of Sfio does not support threads. .Ss "DATA TYPES" .Ss " void*" @@ -355,9 +331,9 @@ of extension functions definable in \f3Sffmt_t\fP. See \f3Sffmt_t\fP below for more details. .Ss " SFIO_VERSION" This is a macro value of type \f3long int\fP that defines -the current version number of Sfio. For example, the Sfio2000's -version number is \f320000515L\fP -(which also indicates its latest version date: 05/15/2000). +the current version number of Sfio. It is composed of a year, +month and day. For example, \f320220212L\fP indicates the +version from February 12, 2022. .Ss "BIT FLAGS" A number of bit flags control stream operations. @@ -436,15 +412,6 @@ This is useful in certain applications (e.g., networking) where a complex object must be output without being split in different system calls. Note that the respective stream still buffers data as much as the buffer can accommodate. .Tp -\f3SF_MTSAFE\fP: -This flag indicates that the respective stream may be accessed by more than one threads. -A mutex lock will be used to ensure that only one thread at a time can access -the stream. Note that this flag can only be set at stream opening time -(see \f3sfopen()\fP, \f3sfpopen()\fP and \f3sfnew()\fP). -Certain fast macro functions such as \f3sfgetc()\fP and \f3sfputc()\fP will -no longer behave as macros. Thus, an application that requires such fast macro functions -should leave \f3SF_MTSAFE\fP off and performs explicit locking with \f3sfmutex()\fP. -.Tp \f3SF_IOINTR\fP: This flag indicates that I/O system calls should not be resumed after being interrupted by signals. It is useful for @@ -481,9 +448,6 @@ opened for both read and write, e.g., sockets. \f3flags\fP: This is composed from \f3SF_EOF\fP and bit values defined in the \fBBIT FLAGS\fP section. -Note, in particular, that a multi-threaded application should -set the bit \f3SF_MTSAFE\fP to protect the new stream from -being simultaneously accessed by multiple threads. .Ss " Sfio_t* sfopen(Sfio_t* f, const char* string, const char* mode)" @@ -530,14 +494,6 @@ The \f3+\fP modifier indicates that the stream is opened for both read and write \f3x\fP specifies exclusive mode, i.e., a file opened for writing should not already exist. -\f3m\fP specifies that the stream needs to be protected from -simultaneous accesses by multiple threads. -This turns on the bit flag \f3SF_MTSAFE\fP. - -\f3u\fP specifies that the stream is guaranteed to be accessed -by only one thread at a time. The bit flag \f3SF_MTSAFE\fP is left off. -The absence of option \f3m\fP is the same as the presence of option \f3u\fP. - .Ss " Sfio_t* sfpopen(Sfio_t* f, const char* cmd, const char* mode)" This function opens a stream that corresponds to the coprocess \f3cmd\fP. The argument \f3mode\fP should be composed from \f3r\fP, \f3w\fP, and \f3+\fP. @@ -611,73 +567,6 @@ In either case, if the exception handler returns a negative value, If the exception handler returns a positive value, \f3sfclose()\fP will immediately return a zero value. -.Ss "THREAD SAFETY" -.PP -The libraries \f3libsfio.a\fP and \f3libstdio.a\fP (providing binary -compatibility to Stdio-based code) only support single-threaded code. -Multi-threaded applications should link with -\f3libsfio-mt.a\fP and \f3libstdio-mt.a\fP. -When this is done, certain platforms may require additional -thread libraries for linkage. For example, Linux, IRIX and Solaris -require \f3-lpthread\fP while HPUX requires \f3-lcma\fP. -Aside from linkage differences, the Sfio API remains identical in all cases. - -Note that unlike Stdio streams which are in thread-safe mode by default. -Sfio streams can be opened in either single-threaded or multi-threaded mode. -A single-threaded stream is more efficient than a multi-threaded one. -For example, functions such as \f3sfgetc()\fP and \f3sfputc()\fP -remain as macro or inline functions for a single-threaded stream while -they will act as full function calls in a multi-threaded case. -The three standard streams \f3sfstdin/sfstdout/sfstderr\fP -are in multi-threaded mode by default -(however, see \f3sfopen()\fP for how this may be changed). -Other Sfio streams are normally opened single-threaded unless -the flag \f3SF_MTSAFE\fP or the option \f3m\fP were specified. -Stdio-based code can also make a Stdio stream single-threaded by -using the option \f3u\fP when opening a file. - -.Ss "int sfmutex(Sfio_t* f, int type)" -This function acquires or releases a mutex -(mutually exclusive) lock on the stream \f3f\fP. -It can be used by a thread to serialize a sequence of I/O operations -executed together in some critical section. -\f3sfmutex()\fP is implicitly used by -all Sfio operations on a stream with the flag \f3SF_MTSAFE\fP to -protect it from concurrent accesses via multiple threads. -\f3sfmutex()\fP returns \f30\fP on success and some non-zero value on failure. - -Each stream has a lock count which starts at \f30\fP. -When the count is positive, a single thread holds the stream. -Only this thread can further lock or unlock the stream. -A different thread attempting to acquire such a locked stream will suspend -until the lock count returns to \f30\fP. -Each successful locking operation increases the lock count -while each successful unlocking operation decreases it, -thus, allowing nesting of matching lock/unlock operations. - -The \f3type\fP argument of \f3sfmutex()\fP takes on the below values: -.Tp -\f3SFMTX_LOCK\fP: -Locking a stream if it is unlocked or increasing the lock count of the stream -if it is already locked by the same thread. This call will block until it is -possible to lock the stream. -.Tp -\f3SFMTX_TRYLOCK\fP: -This is the non-blocking version of \f3SFMTX_LOCK\fP. -If the stream is already locked by a different thread, \f3sfmutex()\fP will -immediately return with an error status. -.Tp -\f3SFMTX_UNLOCK\fP: -Decreasing the lock count and releasing the stream when the lock count reaches 0. -An attempt to unlock a stream without a previously successful lock may -result in undefined behavior in certain implementations. -The current Sfio implementation returns an error status. -.Tp -\f3SFMTX_CLRLOCK\fP: -Resetting the lock count to \f30\fP and releasing the stream. -As with \f3SFMTX_LOCK\fP, -an attempt to clear the lock count without a previously successful lock -may result in undefined behavior. .Ss "INPUT/OUTPUT OPERATIONS" .Ss " int sfgetc(Sfio_t* f)" .Ss " int sfputc(Sfio_t* f, int c)" @@ -1767,12 +1656,8 @@ The argument \f3type\fP of \f3(*exceptf)()\fP identifies the particular exceptional event: .Tp \f3SF_LOCKED\fP: -The stream cannot be accessed. -Note that this lock state is not related to the mutex lock -that protects a stream from multiple accesses by different threads -(see section THREAD SAFETY). Rather, the stream was frozen by +The stream cannot be accessed because it was frozen by certain operations such as \f3sfreserve()\fP or \f3sfstack()\fP. -Thus, a stream can be in this state even if the application is single-threaded. .Tp \f3SF_READ\fP, \f3SF_WRITE\fP: These events are raised around reading and writing operations. @@ -2018,21 +1903,6 @@ An attempt to change \f3f\fP to read mode failed. \f3SF_WRITE\fP: An attempt to change \f3f\fP to write mode failed. \f3data\fP is the file descriptor of the stream. -.Tp -\f3SF_MTACCESS\fP: -When a notifying function was registered (see \f3sfnotify()\fP), -every Sfio call on a stream with flag \f3SF_MTSAFE\fP will -invoke the notifying function -once on entry after the stream is locked -as \f3(*notify)(f, SF_MTACCESS, Sfio_t** fp), and -once on return before unlocking as -as \f3(*notify)(f, SF_MTACCESS, (Sfio_t**)0). -In the call entry case, -the notification function could use the argument \f3fp\fP -to set a stream that would be used for performing the actual I/O operation. -In this way, certain global streams such as the standard streams \f3sfstdin\fP, -\f3sfstdout\fP and \f3sfstderr\fP could be made to act differently when used -in different streams. .Ss " int sfwalk(Sfwalk_f walkf, void* data, int type)" This function invokes \f3(*walkf)(f, data)\fP on every open stream \f3f\fP @@ -2172,18 +2042,18 @@ the Unix \fBcompress\fP program. This creates a discipline for reading/writing data compressed by zlib. The argument \f3opt\fP defines the optimization level. -.Ss "STDIO-COMPATIBILITY" +.Ss "STDIO COMPATIBILITY" .PP Sfio provides compatibility functions for all various popular Stdio implementations at source and binary level. -The source Stdio-compatibility interface +The source Stdio compatibility interface provides the header file \f3stdio.h\fP that defines a set of macros or inlined functions to map Stdio calls to Sfio ones. This mapping may benignly extend or change the meaning of certain -original Stdio operations. For example, the Sfio's version of +original Stdio operations. For example, Sfio's version of \f3popen()\fP allows a coprocess to be opened for both reading and writing unlike the original call which only allows a coprocess to be opened for a single mode. -Similarly, the Sfio's \f3fopen()\fP call can be used to create +Similarly, Sfio's \f3fopen()\fP call can be used to create string streams in addition to file streams. .PP The standard streams \f3stdin\fP, \f3stdout\fP and \f3stderr\fP @@ -2271,69 +2141,6 @@ int clearerr(FILE* stream); .ft 1 .fi -.Ss "RECENT CHANGES" -.PP -A few exception types have been added. In particular, exception handlers shall -be raised with \f3SF_LOCKED\fP on accessing a stream frozen either by -an ongoing operation or a previous operation (e.g., \f3sfgetr()\fP). -Before a process exits, the event \f3SF_ATEXIT\fP is raised for each open stream. -.PP -A number of disciplines were added for various processing functions. -Of interests are disciplines to use the direct I/O feature on IRIX 6.2, -read DOS text files, and decompress files compressed by Unix \fIcompress\fP. -.PP -Various new stream and function flags have been added. For example, -the third argument of \f3sfgetr()\fP is now a set of bit flags and not -just a three-value object. However, the old semantics of this argument -of \f3sfgetr()\fP is still supported. -.PP -The \f3sfopen()\fP call has been extended so that sfopen(f,NULL,mode) can be -used to changed the mode of a file stream before any I/O operations. -This is most useful for changing the modes of the standard streams. -.PP -The buffering strategy has been significantly enhanced for streams -that perform many seek operations. Also, the handling of stream and -file positions have been better clarified so that applications that -share file descriptors across streams and/or processes can be sure that -the file states will be consistent. -.PP -The strategy for mapping between Sfio and Stdio streams in the binary -compatibility package has been significantly enhanced for efficiency. -For most platforms, the mapping is now constant time per look-up. -.PP -The \f3SF_BUFCONST\fP flag was deleted. This is largely unused anyway. -.PP -The library can be built for thread-safety. This is based largely on -POSIX pthread mutexes except for on UWIN where native Windows APIs -are used. -.PP -The functions \f3sfgetm()\fP and \f3sfputm()\fP were added to encode -unsigned integer values with known ranges. -.PP -The flag \f3SF_APPEND\fP is identical to \f3SF_APPENDWR\fP. -However it conflicts with a different token of the same name -defined in the system header \f3stat.h\fP of BSDI Unix systems. -On such systems, we shall not define \f3SF_APPEND\fP and this -symbol may be removed in a future release. -.PP -Similarly, the exception \f3SF_CLOSE\fP is identical to \f3SF_CLOSING\fP. -However it conflicts with a different token of the same name -defined in the system header \f3socket.h\fP of AIX Unix systems. -On such systems, we shall not define \f3SF_CLOSE\fP and this -symbol may be removed in a future release. -.PP -The printing and scanning functions were extended to handle multibyte characters -and to conform to the C99 standard. -.PP -The function \f3sfpoll()\fP was overhauled to make it useful -for writing servers that must communicate with multiple streams -without blocking. -.PP -The formatting pattern \f3%c\fP for \f3sf*printf\fP was extended -to allow the flag \f3#\fP to print unprintable character values -using the C convention. For example, \f3%#c\fP prints the octal value 012 -as \f3\\n\fP. - .SH AUTHORS Kiem-Phong Vo, kpv@research.att.com, .br diff --git a/src/lib/libast/misc/stk.c b/src/lib/libast/misc/stk.c index dc7467231..cd9ad2549 100644 --- a/src/lib/libast/misc/stk.c +++ b/src/lib/libast/misc/stk.c @@ -61,7 +61,7 @@ typedef char* (*_stk_overflow_)(int); static int stkexcept(Sfio_t*,int,void*,Sfdisc_t*); static Sfdisc_t stkdisc = { 0, 0, 0, stkexcept }; -Sfio_t _Stak_data = SFNEW((char*)0,0,-1,SF_STATIC|SF_WRITE|SF_STRING,&stkdisc,0); +Sfio_t _Stak_data = SFNEW((char*)0,0,-1,SF_STATIC|SF_WRITE|SF_STRING,&stkdisc); __EXTERN__(Sfio_t, _Stak_data); diff --git a/src/lib/libast/sfio/_sfopen.c b/src/lib/libast/sfio/_sfopen.c index 04602c8cb..fb469fa2b 100644 --- a/src/lib/libast/sfio/_sfopen.c +++ b/src/lib/libast/sfio/_sfopen.c @@ -40,17 +40,14 @@ Sfio_t* _sfopen(Sfio_t* f, /* old stream structure */ const char* mode) /* mode of the stream */ { int fd, oldfd, oflags, fflags, sflags; - SFMTXDECL(f); /* get the control flags */ - if((sflags = _sftype(mode,&oflags,&fflags,NIL(int*))) == 0) + if((sflags = _sftype(mode,&oflags,&fflags)) == 0) return NIL(Sfio_t*); /* changing the control flags */ if(f && !file && !((f->flags|sflags)&SF_STRING) ) - { SFMTXENTER(f, NIL(Sfio_t*)); - - if(f->mode&SF_INIT ) /* stream uninitialized, ok to set flags */ + { if(f->mode&SF_INIT ) /* stream uninitialized, ok to set flags */ { f->flags |= (sflags & (SFIO_FLAGS & ~SF_RDWR)); if((sflags &= SF_RDWR) != 0) /* reset read/write modes */ @@ -67,7 +64,7 @@ Sfio_t* _sfopen(Sfio_t* f, /* old stream structure */ } else /* make sure there is no buffered data */ { if(sfsync(f) < 0) - SFMTXRETURN(f,NIL(Sfio_t*)); + return NIL(Sfio_t*); } if(f->file >= 0 ) @@ -83,7 +80,7 @@ Sfio_t* _sfopen(Sfio_t* f, /* old stream structure */ #endif } - SFMTXRETURN(f,f); + return f; } if(sflags&SF_STRING) @@ -138,15 +135,15 @@ Sfio_t* _sfopen(Sfio_t* f, /* old stream structure */ return f; } -int _sftype(reg const char* mode, int* oflagsp, int* fflagsp, int* uflagp) +int _sftype(reg const char* mode, int* oflagsp, int* fflagsp) { - reg int sflags, oflags, fflags, uflag; + reg int sflags, oflags, fflags; if(!mode) return 0; /* construct the open flags */ - sflags = oflags = fflags = uflag = 0; + sflags = oflags = fflags = 0; while(1) switch(*mode++) { case 'a' : @@ -160,10 +157,6 @@ int _sftype(reg const char* mode, int* oflagsp, int* fflagsp, int* uflagp) oflags |= O_cloexec; fflags |= SF_FD_CLOEXEC; continue; - case 'm' : - sflags |= SF_MTSAFE; - uflag = 0; - continue; case 'r' : sflags |= SF_READ; oflags |= O_RDONLY; @@ -174,10 +167,6 @@ int _sftype(reg const char* mode, int* oflagsp, int* fflagsp, int* uflagp) case 't' : oflags |= O_TEXT; continue; - case 'u' : - sflags &= ~SF_MTSAFE; - uflag = 1; - continue; case 'w' : sflags |= SF_WRITE; oflags |= O_WRONLY | O_CREAT; @@ -192,7 +181,6 @@ int _sftype(reg const char* mode, int* oflagsp, int* fflagsp, int* uflagp) continue; case 'W' : sflags |= SF_WCWIDTH; - uflag = 0; continue; case '+' : if(sflags) @@ -211,8 +199,6 @@ int _sftype(reg const char* mode, int* oflagsp, int* fflagsp, int* uflagp) *oflagsp = oflags; if(fflagsp) *fflagsp = fflags; - if(uflagp) - *uflagp = uflag; if((sflags&(SF_STRING|SF_RDWR)) == SF_STRING) sflags |= SF_READ; return sflags; diff --git a/src/lib/libast/sfio/_sfputd.c b/src/lib/libast/sfio/_sfputd.c index 29acd96b0..bd78b0216 100644 --- a/src/lib/libast/sfio/_sfputd.c +++ b/src/lib/libast/sfio/_sfputd.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -35,12 +35,9 @@ int _sfputd(Sfio_t* f, Sfdouble_t v) int exp; uchar c[N_ARRAY]; Sfdouble_t x; - SFMTXDECL(f); - SFMTXENTER(f,-1); - - if(f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0) - SFMTXRETURN(f, -1); + if(!f || (f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0)) + return -1; SFLOCK(f,0); /* get the sign of v */ @@ -64,7 +61,7 @@ int _sfputd(Sfio_t* f, Sfdouble_t v) /* write out the signs and the exp */ SFOPEN(f,0); if(sfputc(f,n) < 0 || (w = sfputu(f,w)) < 0) - SFMTXRETURN(f, -1); + return -1; SFLOCK(f,0); w += 1; @@ -87,5 +84,5 @@ int _sfputd(Sfio_t* f, Sfdouble_t v) w = SFWRITE(f,(void*)s,n) == n ? w+n : -1; SFOPEN(f,0); - SFMTXRETURN(f,w); + return w; } diff --git a/src/lib/libast/sfio/_sfputl.c b/src/lib/libast/sfio/_sfputl.c index 05ed19298..ee5d7260c 100644 --- a/src/lib/libast/sfio/_sfputl.c +++ b/src/lib/libast/sfio/_sfputl.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -34,11 +34,9 @@ int _sfputl(Sfio_t* f, /* write a portable long to this stream */ reg uchar *s, *ps; reg ssize_t n, p; uchar c[N_ARRAY]; - SFMTXDECL(f); - SFMTXENTER(f,-1); - if(f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0) - SFMTXRETURN(f, -1); + if(!f || (f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0)) + return -1; SFLOCK(f,0); s = ps = &(c[N_ARRAY-1]); @@ -81,5 +79,5 @@ int _sfputl(Sfio_t* f, /* write a portable long to this stream */ } SFOPEN(f,0); - SFMTXRETURN(f, n); + return n; } diff --git a/src/lib/libast/sfio/_sfputm.c b/src/lib/libast/sfio/_sfputm.c index 1d98cc9b7..4237b9a7d 100644 --- a/src/lib/libast/sfio/_sfputm.c +++ b/src/lib/libast/sfio/_sfputm.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -35,12 +35,9 @@ int _sfputm(Sfio_t* f, /* write a portable ulong to this stream */ reg uchar *s, *ps; reg ssize_t n, p; uchar c[N_ARRAY]; - SFMTXDECL(f); - SFMTXENTER(f, -1); - - if(v > m || (f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0) ) - SFMTXRETURN(f, -1); + if(!f || v > m || (f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0)) + return -1; SFLOCK(f,0); /* code v as integers in base SF_UBASE */ @@ -77,5 +74,5 @@ int _sfputm(Sfio_t* f, /* write a portable ulong to this stream */ } SFOPEN(f,0); - SFMTXRETURN(f, (int)n); + return (int)n; } diff --git a/src/lib/libast/sfio/_sfputu.c b/src/lib/libast/sfio/_sfputu.c index aac5c7804..abad5136f 100644 --- a/src/lib/libast/sfio/_sfputu.c +++ b/src/lib/libast/sfio/_sfputu.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -34,12 +34,9 @@ int _sfputu(Sfio_t* f, /* write a portable ulong to this stream */ reg uchar *s, *ps; reg ssize_t n, p; uchar c[N_ARRAY]; - SFMTXDECL(f); - SFMTXENTER(f, -1); - - if(f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0) - SFMTXRETURN(f, -1); + if(!f || (f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0)) + return -1; SFLOCK(f,0); /* code v as integers in base SF_UBASE */ @@ -74,5 +71,5 @@ int _sfputu(Sfio_t* f, /* write a portable ulong to this stream */ } SFOPEN(f,0); - SFMTXRETURN(f, (int)n); + return (int)n; } diff --git a/src/lib/libast/sfio/sfclose.c b/src/lib/libast/sfio/sfclose.c index 1f754592e..469c51133 100644 --- a/src/lib/libast/sfio/sfclose.c +++ b/src/lib/libast/sfio/sfclose.c @@ -31,9 +31,9 @@ int sfclose(Sfio_t* f) { reg int local, ex, rv; void* data = NIL(void*); - SFMTXDECL(f); /* declare a local stream variable for multithreading */ - SFMTXENTER(f, -1); + if(!f) + return -1; GETLOCAL(f,local); @@ -41,18 +41,18 @@ int sfclose(Sfio_t* f) SFMODE(f,local) != (f->mode&SF_RDWR) && SFMODE(f,local) != (f->mode&(SF_READ|SF_SYNCED)) && _sfmode(f,SF_SYNCED,local) < 0) - SFMTXRETURN(f,-1); + return -1; /* closing a stack of streams */ while(f->push) { reg Sfio_t* pop; if(!(pop = (*_Sfstack)(f,NIL(Sfio_t*))) ) - SFMTXRETURN(f,-1); + return -1; if(sfclose(pop) < 0) { (*_Sfstack)(f,pop); - SFMTXRETURN(f,-1); + return -1; } } @@ -68,14 +68,13 @@ int sfclose(Sfio_t* f) /* raise discipline exceptions */ if(f->disc && (ex = SFRAISE(f,local ? SF_NEW : SF_CLOSING,NIL(void*))) != 0) - SFMTXRETURN(f,ex); + return ex; if(!local && f->pool) { /* remove from pool */ if(f->pool == &_Sfpool) { reg int n; - POOLMTXLOCK(&_Sfpool); for(n = 0; n < _Sfpool.n_sf; ++n) { if(_Sfpool.sf[n] != f) continue; @@ -85,13 +84,12 @@ int sfclose(Sfio_t* f) _Sfpool.sf[n] = _Sfpool.sf[n+1]; break; } - POOLMTXUNLOCK(&_Sfpool); } else { f->mode &= ~SF_LOCK; /**/ASSERT(_Sfpmove); if((*_Sfpmove)(f,-1) < 0) { SFOPEN(f,0); - SFMTXRETURN(f,-1); + return -1; } f->mode |= SF_LOCK; } @@ -143,15 +141,6 @@ int sfclose(Sfio_t* f) if(f->proc) rv = _sfpclose(f); - /* destroy the mutex */ - if(f->mutex) - { (void)vtmtxclrlock(f->mutex); - if(f != sfstdin && f != sfstdout && f != sfstderr) - { (void)vtmtxclose(f->mutex); - f->mutex = NIL(Vtmutex_t*); - } - } - if(!local) { if(f->disc && (ex = SFRAISE(f,SF_FINAL,NIL(void*))) != 0 ) { rv = ex; diff --git a/src/lib/libast/sfio/sfclrlock.c b/src/lib/libast/sfio/sfclrlock.c index 37bc5f5c3..21a5885fd 100644 --- a/src/lib/libast/sfio/sfclrlock.c +++ b/src/lib/libast/sfio/sfclrlock.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -31,14 +31,11 @@ int sfclrlock(Sfio_t* f) { int rv; - SFMTXDECL(f); /* declare a local stream variable for multithreading */ /* already closed */ - if(f && (f->mode&SF_AVAIL)) + if(f && (f->mode&SF_AVAIL) || !f) return 0; - SFMTXENTER(f,0); - /* clear error bits */ f->flags &= ~(SF_ERROR|SF_EOF); @@ -55,5 +52,5 @@ int sfclrlock(Sfio_t* f) rv = (f->mode&SF_PUSH) ? 0 : (f->flags&SFIO_FLAGS); - SFMTXRETURN(f, rv); + return rv; } diff --git a/src/lib/libast/sfio/sfdisc.c b/src/lib/libast/sfio/sfdisc.c index 5840d1ec3..b3b3db36b 100644 --- a/src/lib/libast/sfio/sfdisc.c +++ b/src/lib/libast/sfio/sfdisc.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -96,21 +96,21 @@ Sfdisc_t* sfdisc(Sfio_t* f, Sfdisc_t* disc) Sfseek_f oseekf; ssize_t n; Dccache_t *dcca = NIL(Dccache_t*); - SFMTXDECL(f); /* declare a local stream variable for multithreading */ - SFMTXENTER(f, NIL(Sfdisc_t*)); + if(!f) + return NIL(Sfdisc_t*); if((Sfio_t*)disc == f) /* special case to get the top discipline */ - SFMTXRETURN(f,f->disc); + return f->disc; if((f->flags&SF_READ) && f->proc && (f->mode&SF_WRITE) ) { /* make sure in read mode to check for read-ahead data */ if(_sfmode(f,SF_READ,0) < 0) - SFMTXRETURN(f, NIL(Sfdisc_t*)); + return NIL(Sfdisc_t*); } else { if((f->mode&SF_RDWR) != f->mode && _sfmode(f,0,0) < 0) - SFMTXRETURN(f, NIL(Sfdisc_t*)); + return NIL(Sfdisc_t*); } SFLOCK(f,0); @@ -246,5 +246,5 @@ Sfdisc_t* sfdisc(Sfio_t* f, Sfdisc_t* disc) done : SFOPEN(f,0); - SFMTXRETURN(f, rdisc); + return rdisc; } diff --git a/src/lib/libast/sfio/sfexcept.c b/src/lib/libast/sfio/sfexcept.c index 5db43f16f..0f918b276 100644 --- a/src/lib/libast/sfio/sfexcept.c +++ b/src/lib/libast/sfio/sfexcept.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -34,9 +34,9 @@ int _sfexcept(Sfio_t* f, /* stream where the exception happened */ reg int ev, local, lock; reg ssize_t size; reg uchar* data; - SFMTXDECL(f); /* declare a local stream variable for multithreading */ - SFMTXENTER(f,-1); + if(!f) + return -1; GETLOCAL(f,local); lock = f->mode&SF_LOCK; @@ -58,18 +58,18 @@ int _sfexcept(Sfio_t* f, /* stream where the exception happened */ SFLOCK(f,0); if(io > 0 && !(f->flags&SF_STRING) ) - SFMTXRETURN(f, ev); + return ev; if(ev < 0) - SFMTXRETURN(f, SF_EDONE); + return SF_EDONE; if(ev > 0) - SFMTXRETURN(f, SF_EDISC); + return SF_EDISC; } if(f->flags&SF_STRING) { if(type == SF_READ) goto chk_stack; else if(type != SF_WRITE && type != SF_SEEK) - SFMTXRETURN(f, SF_EDONE); + return SF_EDONE; if(local && io >= 0) { if(f->size >= 0 && !(f->flags&SF_MALLOC)) goto chk_stack; @@ -89,18 +89,18 @@ int _sfexcept(Sfio_t* f, /* stream where the exception happened */ f->endr = f->endw = f->data = data; f->size = size; } - SFMTXRETURN(f, SF_EDISC); + return SF_EDISC; } if(errno == EINTR) { if(_Sfexiting || (f->bits&SF_ENDING) || /* stop being a hero */ (f->flags&SF_IOINTR) ) /* application requests to return */ - SFMTXRETURN(f, SF_EDONE); + return SF_EDONE; /* a normal interrupt, we can continue */ errno = 0; f->flags &= ~(SF_EOF|SF_ERROR); - SFMTXRETURN(f, SF_ECONT); + return SF_ECONT; } chk_stack: @@ -125,5 +125,5 @@ chk_stack: } else ev = SF_EDONE; - SFMTXRETURN(f, ev); + return ev; } diff --git a/src/lib/libast/sfio/sfextern.c b/src/lib/libast/sfio/sfextern.c index 6a649cba5..e7a932c5e 100644 --- a/src/lib/libast/sfio/sfextern.c +++ b/src/lib/libast/sfio/sfextern.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -26,18 +26,6 @@ ** Written by Kiem-Phong Vo */ -/* code to initialize mutexes */ -static Vtmutex_t Sfmutex; -static Vtonce_t Sfonce = VTONCE_INITDATA; -static void _sfoncef() -{ (void)vtmtxopen(_Sfmutex, VT_INIT); - (void)vtmtxopen(&_Sfpool.mutex, VT_INIT); - (void)vtmtxopen(sfstdin->mutex, VT_INIT); - (void)vtmtxopen(sfstdout->mutex, VT_INIT); - (void)vtmtxopen(sfstderr->mutex, VT_INIT); - _Sfdone = 1; -} - /* global variables used internally to the package */ Sfextern_t _Sfextern = { 0, /* _Sfpage */ @@ -55,33 +43,17 @@ Sfextern_t _Sfextern = NIL(void(*)(void)), /* _Sfcleanup */ 0, /* _Sfexiting */ 0, /* _Sfdone */ - &Sfonce, /* _Sfonce */ - _sfoncef, /* _Sfoncef */ - &Sfmutex /* _Sfmutex */ }; ssize_t _Sfi = -1; /* value for a few fast macro functions */ ssize_t _Sfmaxr = 0; /* default (unlimited) max record size */ -#if vt_threaded -static Vtmutex_t _Sfmtxin, _Sfmtxout, _Sfmtxerr; -#define SFMTXIN (&_Sfmtxin) -#define SFMTXOUT (&_Sfmtxout) -#define SFMTXERR (&_Sfmtxerr) -#define SF_STDSAFE SF_MTSAFE -#else -#define SFMTXIN (0) -#define SFMTXOUT (0) -#define SFMTXERR (0) -#define SF_STDSAFE (0) -#endif - Sfio_t _Sfstdin = SFNEW(NIL(char*),-1,0, - (SF_READ |SF_STATIC|SF_STDSAFE),NIL(Sfdisc_t*),SFMTXIN); + (SF_READ |SF_STATIC),NIL(Sfdisc_t*)); Sfio_t _Sfstdout = SFNEW(NIL(char*),-1,1, - (SF_WRITE|SF_STATIC|SF_STDSAFE),NIL(Sfdisc_t*),SFMTXOUT); + (SF_WRITE|SF_STATIC),NIL(Sfdisc_t*)); Sfio_t _Sfstderr = SFNEW(NIL(char*),-1,2, - (SF_WRITE|SF_STATIC|SF_STDSAFE),NIL(Sfdisc_t*),SFMTXERR); + (SF_WRITE|SF_STATIC),NIL(Sfdisc_t*)); #undef sfstdin #undef sfstdout diff --git a/src/lib/libast/sfio/sffilbuf.c b/src/lib/libast/sfio/sffilbuf.c index 4c51e5471..be11e2498 100644 --- a/src/lib/libast/sfio/sffilbuf.c +++ b/src/lib/libast/sfio/sffilbuf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -37,9 +37,9 @@ int _sffilbuf(Sfio_t* f, /* fill the read buffer of this stream */ { reg ssize_t r; reg int first, local, rcrv, rc, justseek; - SFMTXDECL(f); /* declare a local stream variable for multithreading */ - SFMTXENTER(f,-1); + if(!f) + return -1; GETLOCAL(f,local); @@ -52,7 +52,7 @@ int _sffilbuf(Sfio_t* f, /* fill the read buffer of this stream */ for(first = 1;; first = 0, (f->mode &= ~SF_LOCK) ) { /* check mode */ if(SFMODE(f,local) != SF_READ && _sfmode(f,SF_READ,local) < 0) - SFMTXRETURN(f,-1); + return -1; SFLOCK(f,local); /* current extent of available data */ @@ -108,5 +108,5 @@ int _sffilbuf(Sfio_t* f, /* fill the read buffer of this stream */ rcrv = (n == 0) ? (r > 0 ? (int)(*f->next++) : EOF) : (int)r; - SFMTXRETURN(f,rcrv); + return rcrv; } diff --git a/src/lib/libast/sfio/sfflsbuf.c b/src/lib/libast/sfio/sfflsbuf.c index adb23240f..a6c3606d3 100644 --- a/src/lib/libast/sfio/sfflsbuf.c +++ b/src/lib/libast/sfio/sfflsbuf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -36,16 +36,16 @@ int _sfflsbuf(Sfio_t* f, /* write out the buffered content of this stream */ uchar outc; int local, isall; int inpc = c; - SFMTXDECL(f); /* declare a local stream variable for multithreading */ - SFMTXENTER(f,-1); + if(!f) + return -1; GETLOCAL(f,local); for(written = 0;; f->mode &= ~SF_LOCK) { /* check stream mode */ if(SFMODE(f,local) != SF_WRITE && _sfmode(f,SF_WRITE,local) < 0) - SFMTXRETURN(f, -1); + return -1; SFLOCK(f,local); /* current data extent */ @@ -62,7 +62,7 @@ int _sfflsbuf(Sfio_t* f, /* write out the buffered content of this stream */ n = f->next - (data = f->data); else { SFOPEN(f,local); - SFMTXRETURN(f, -1); + return -1; } } @@ -103,7 +103,7 @@ int _sfflsbuf(Sfio_t* f, /* write out the buffered content of this stream */ break; /* do normal exit below */ else /* nothing was done, returning failure */ { SFOPEN(f,local); - SFMTXRETURN(f, -1); + return -1; } } else /* w < 0 means SF_EDISC or SF_ESTACK in sfwr() */ @@ -118,5 +118,5 @@ int _sfflsbuf(Sfio_t* f, /* write out the buffered content of this stream */ if(inpc < 0) inpc = f->endb-f->next; - SFMTXRETURN(f,inpc); + return inpc; } diff --git a/src/lib/libast/sfio/sfgetd.c b/src/lib/libast/sfio/sfgetd.c index e429dc5c0..f1cf33e3f 100644 --- a/src/lib/libast/sfio/sfgetd.c +++ b/src/lib/libast/sfio/sfgetd.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -32,15 +32,12 @@ Sfdouble_t sfgetd(Sfio_t* f) reg uchar *s, *ends, c; reg int p, sign, exp; Sfdouble_t v; - SFMTXDECL(f); /* declare a local stream variable for multithreading */ - SFMTXENTER(f,-1.); - - if((sign = sfgetc(f)) < 0 || (exp = (int)sfgetu(f)) < 0) - SFMTXRETURN(f, -1.); + if(!f || (sign = sfgetc(f)) < 0 || (exp = (int)sfgetu(f)) < 0) + return -1.; if(f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0) - SFMTXRETURN(f, -1.); + return -1.; SFLOCK(f,0); @@ -71,5 +68,5 @@ done: v = -v; SFOPEN(f,0); - SFMTXRETURN(f, v); + return v; } diff --git a/src/lib/libast/sfio/sfgetl.c b/src/lib/libast/sfio/sfgetl.c index b500fbda0..d0bff24d3 100644 --- a/src/lib/libast/sfio/sfgetl.c +++ b/src/lib/libast/sfio/sfgetl.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -32,12 +32,9 @@ Sflong_t sfgetl(Sfio_t* f) Sflong_t v; uchar *s, *ends, c; int p; - SFMTXDECL(f); /* declare a local stream variable for multithreading */ - SFMTXENTER(f,(Sflong_t)(-1)); - - if(f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0) - SFMTXRETURN(f, (Sflong_t)(-1)); + if(!f || (f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0)) + return (Sflong_t)(-1); SFLOCK(f,0); for(v = 0;;) @@ -62,5 +59,5 @@ Sflong_t sfgetl(Sfio_t* f) } done : SFOPEN(f,0); - SFMTXRETURN(f, v); + return v; } diff --git a/src/lib/libast/sfio/sfgetm.c b/src/lib/libast/sfio/sfgetm.c index cfc565620..72666f2eb 100644 --- a/src/lib/libast/sfio/sfgetm.c +++ b/src/lib/libast/sfio/sfgetm.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -32,12 +32,9 @@ Sfulong_t sfgetm(Sfio_t* f, Sfulong_t m) Sfulong_t v; reg uchar *s, *ends, c; reg int p; - SFMTXDECL(f); - SFMTXENTER(f, (Sfulong_t)(-1)); - - if(f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0) - SFMTXRETURN(f, (Sfulong_t)(-1)); + if(!f || (f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0)) + return (Sfulong_t)(-1); SFLOCK(f,0); @@ -59,5 +56,5 @@ Sfulong_t sfgetm(Sfio_t* f, Sfulong_t m) } done: SFOPEN(f,0); - SFMTXRETURN(f, v); + return v; } diff --git a/src/lib/libast/sfio/sfgetr.c b/src/lib/libast/sfio/sfgetr.c index 792f887f1..98fcc81e8 100644 --- a/src/lib/libast/sfio/sfgetr.c +++ b/src/lib/libast/sfio/sfgetr.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -36,12 +36,9 @@ char* sfgetr(Sfio_t* f, /* stream to read from */ uchar *s, *ends, *us; int found; Sfrsrv_t* rsrv; - SFMTXDECL(f); /* declare a local stream variable for multithreading */ - SFMTXENTER(f, NIL(char*)); - - if(rc < 0 || (f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0) ) - SFMTXRETURN(f, NIL(char*)); + if(!f || rc < 0 || (f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0)) + return NIL(char*); SFLOCK(f,0); /* buffer to be returned */ @@ -161,5 +158,5 @@ done: f->endr = f->data; } - SFMTXRETURN(f, (char*)us); + return (char*)us; } diff --git a/src/lib/libast/sfio/sfgetu.c b/src/lib/libast/sfio/sfgetu.c index e65144073..0215f8b66 100644 --- a/src/lib/libast/sfio/sfgetu.c +++ b/src/lib/libast/sfio/sfgetu.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -32,12 +32,9 @@ Sfulong_t sfgetu(Sfio_t* f) Sfulong_t v; uchar *s, *ends, c; int p; - SFMTXDECL(f); /* declare a local stream variable for multithreading */ - SFMTXENTER(f, (Sfulong_t)(-1)); - - if(f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0) - SFMTXRETURN(f, (Sfulong_t)(-1)); + if(!f || (f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0)) + return (Sfulong_t)(-1); SFLOCK(f,0); @@ -59,5 +56,5 @@ Sfulong_t sfgetu(Sfio_t* f) } done: SFOPEN(f,0); - SFMTXRETURN(f, v); + return v; } diff --git a/src/lib/libast/sfio/sfhdr.h b/src/lib/libast/sfio/sfhdr.h index 8c3cadeec..f86894911 100644 --- a/src/lib/libast/sfio/sfhdr.h +++ b/src/lib/libast/sfio/sfhdr.h @@ -57,9 +57,6 @@ #include "sfio_t.h" -/* note that the macro vt_threaded has effect on vthread.h */ -#include - /* file system info */ #if _PACKAGE_ast @@ -242,77 +239,6 @@ #define SFMBLEN(s,mb) (*(s) ? 1 : 0) #endif /* _has_multibyte */ -/* dealing with streams that might be accessed concurrently */ -#if vt_threaded - -#define SFMTXdecl(ff,_mf_) Sfio_t* _mf_ = (ff) -#define SFMTXbegin(ff,_mf_,rv) \ - { if((ff)->_flags&SF_MTSAFE) \ - { (_mf_) = (ff); \ - if(sfmutex((ff), SFMTX_LOCK) != 0) return(rv); \ - if(_Sfnotify) \ - { (*_Sfnotify)((_mf_), SF_MTACCESS, (void*)(&(ff)) ); \ - if(!(ff)) (ff) = (_mf_); \ - } \ - } \ - } -#define SFMTXend(ff,_mf_) \ - { if((ff)->_flags&SF_MTSAFE) \ - { if(_Sfnotify) \ - (*_Sfnotify)((_mf_), SF_MTACCESS, NIL(void*) ); \ - sfmutex((ff), SFMTX_UNLOCK); \ - (ff) = (_mf_); \ - } \ - } - -#define SFONCE() (_Sfdone ? 0 : vtonce(_Sfonce,_Sfoncef)) - -#define SFMTXLOCK(f) (((f)->flags&SF_MTSAFE) ? sfmutex(f,SFMTX_LOCK) : 0) -#define SFMTXUNLOCK(f) (((f)->flags&SF_MTSAFE) ? sfmutex(f,SFMTX_UNLOCK) : 0) - -#define SFMTXDECL(ff) SFMTXdecl((ff), _mtxf1_) -#define SFMTXBEGIN(ff,v) { SFMTXbegin((ff), _mtxf1_, (v) ); } -#define SFMTXEND(ff) { SFMTXend(ff, _mtxf1_); } -#define SFMTXENTER(ff,v) { if(!(ff)) return(v); SFMTXBEGIN((ff), (v)); } -#define SFMTXRETURN(ff,v) { SFMTXEND(ff); return(v); } - -#define SFMTXDECL2(ff) SFMTXdecl((ff), _mtxf2_) -#define SFMTXBEGIN2(ff,v) { SFMTXbegin((ff), _mtxf2_, (v) ); } -#define SFMTXEND2(ff) { SFMTXend((ff), _mtxf2_); } - -#define POOLMTXLOCK(p) ( vtmtxlock(&(p)->mutex) ) -#define POOLMTXUNLOCK(p) ( vtmtxunlock(&(p)->mutex) ) -#define POOLMTXENTER(p) { POOLMTXLOCK(p); } -#define POOLMTXRETURN(p,rv) { POOLMTXUNLOCK(p); return(rv); } - -#else /*!vt_threaded*/ - -#undef SF_MTSAFE /* no need to worry about thread-safety */ -#define SF_MTSAFE 0 - -#define SFONCE() /*(0)*/ - -#define SFMTXLOCK(f) /*(0)*/ -#define SFMTXUNLOCK(f) /*(0)*/ - -#define SFMTXDECL(ff) /*(0)*/ -#define SFMTXBEGIN(ff,v) /*(0)*/ -#define SFMTXEND(ff) /*(0)*/ -#define SFMTXENTER(ff,v) { if(!(ff)) return(v); } -#define SFMTXRETURN(ff,v) { return(v); } - -#define SFMTXDECL2(ff) /*(0)*/ -#define SFMTXBEGIN2(ff,v) /*(0)*/ -#define SFMTXEND2(ff) /*(0)*/ - -#define POOLMTXLOCK(p) -#define POOLMTXUNLOCK(p) -#define POOLMTXENTER(p) -#define POOLMTXRETURN(p,v) { return(v); } - -#endif /*vt_threaded*/ - - /* functions for polling readiness of streams */ #if _lib_select #undef _lib_poll @@ -375,7 +301,7 @@ #define SF_NULL 00000010 /* stream is /dev/null */ #define SF_SEQUENTIAL 00000020 /* sequential access */ #define SF_JUSTSEEK 00000040 /* just did a sfseek */ -#define SF_PRIVATE 00000100 /* private stream to Sfio, no mutex */ +#define SF_PRIVATE 00000100 /* private stream to Sfio */ #define SF_ENDING 00000200 /* no re-io on interrupts at closing */ #define SF_WIDE 00000400 /* in wide mode - stdio only */ #define SF_PUTR 00001000 /* in sfputr() */ @@ -541,7 +467,6 @@ struct _sfpool_s int n_sf; /* number currently in pool */ Sfio_t** sf; /* array of streams */ Sfio_t* array[3]; /* start with 3 */ - Vtmutex_t mutex; /* mutex lock object */ }; /* reserve buffer structure */ @@ -669,9 +594,6 @@ typedef void (*Sfnotify_f)(Sfio_t*, int, void*); #define _Sfcleanup (_Sfextern.sf_cleanup) #define _Sfexiting (_Sfextern.sf_exiting) #define _Sfdone (_Sfextern.sf_done) -#define _Sfonce (_Sfextern.sf_once) -#define _Sfoncef (_Sfextern.sf_oncef) -#define _Sfmutex (_Sfextern.sf_mutex) typedef struct _sfextern_s { ssize_t sf_page; struct _sfpool_s sf_pool; @@ -683,9 +605,6 @@ typedef struct _sfextern_s void (*sf_cleanup)(void); int sf_exiting; int sf_done; - Vtonce_t* sf_once; - void (*sf_oncef)(void); - Vtmutex_t* sf_mutex; } Sfextern_t; /* get the real value of a byte in a coded long or ulong */ @@ -780,8 +699,8 @@ typedef struct _sfextern_s /* lock/open a stream */ #define SFMODE(f,l) ((f)->mode & ~(SF_RV|SF_RC|((l) ? SF_LOCK : 0)) ) #define SFLOCK(f,l) (void)((f)->mode |= SF_LOCK, (f)->endr = (f)->endw = (f)->data) -#define _SFOPENRD(f) ((f)->endr = ((f)->flags&SF_MTSAFE) ? (f)->data : (f)->endb) -#define _SFOPENWR(f) ((f)->endw = ((f)->flags&(SF_MTSAFE|SF_LINE)) ? (f)->data : (f)->endb) +#define _SFOPENRD(f) ((f)->endr = (f)->endb) +#define _SFOPENWR(f) ((f)->endw = ((f)->flags&SF_LINE) ? (f)->data : (f)->endb) #define _SFOPEN(f) ((f)->mode == SF_READ ? _SFOPENRD(f) : \ (f)->mode == SF_WRITE ? _SFOPENWR(f) : \ ((f)->endw = (f)->endr = (f)->data) ) @@ -1064,7 +983,7 @@ extern char** _sfgetpath(char*); extern Sfextern_t _Sfextern; extern int _sfmode(Sfio_t*, int, int); -extern int _sftype(const char*, int*, int*, int*); +extern int _sftype(const char*, int*, int*); #undef extern diff --git a/src/lib/libast/sfio/sfmode.c b/src/lib/libast/sfio/sfmode.c index 9f61c0085..d0c0626e1 100644 --- a/src/lib/libast/sfio/sfmode.c +++ b/src/lib/libast/sfio/sfmode.c @@ -84,7 +84,6 @@ static void _sfcleanup(void) continue; SFLOCK(f,0); - SFMTXLOCK(f); /* let application know that we are leaving */ (void)SFRAISE(f, SF_ATEXIT, NIL(void*)); @@ -103,7 +102,6 @@ static void _sfcleanup(void) (void)SFSETBUF(f,NIL(void*),0); f->mode |= pool; - SFMTXUNLOCK(f); SFOPEN(f,0); } } @@ -124,7 +122,6 @@ int _sfsetpool(Sfio_t* f) if(!(p = f->pool) ) p = f->pool = &_Sfpool; - POOLMTXENTER(p); rv = -1; @@ -155,7 +152,7 @@ int _sfsetpool(Sfio_t* f) rv = 0; done: - POOLMTXRETURN(p, rv); + return rv; } /* create an auxiliary buffer for sfgetr/sfreserve/sfputr */ @@ -213,12 +210,10 @@ int _sfpopen(reg Sfio_t* f, int fd, int pid, int stdio) /* stdio popen() does no if(p->sigp) { Sfsignal_f handler; - (void)vtmtxlock(_Sfmutex); if((handler = signal(SIGPIPE, ignoresig)) != SIG_DFL && handler != ignoresig) signal(SIGPIPE, handler); /* honor user handler */ _Sfsigp += 1; - (void)vtmtxunlock(_Sfmutex); } #endif @@ -261,7 +256,6 @@ int _sfpclose(reg Sfio_t* f) #endif #ifdef SIGPIPE - (void)vtmtxlock(_Sfmutex); if(p->sigp && (_Sfsigp -= 1) <= 0) { Sfsignal_f handler; if((handler = signal(SIGPIPE,SIG_DFL)) != SIG_DFL && @@ -269,7 +263,6 @@ int _sfpclose(reg Sfio_t* f) signal(SIGPIPE,handler); /* honor user handler */ _Sfsigp = 0; } - (void)vtmtxunlock(_Sfmutex); #endif } @@ -330,7 +323,6 @@ int _sfmode(reg Sfio_t* f, /* change r/w mode and sync file pointer for this str Sfoff_t addr; reg int rv = 0; - SFONCE(); /* initialize mutexes */ if(wanted&SF_SYNCED) /* for (SF_SYNCED|SF_READ) stream, just junk data */ { wanted &= ~SF_SYNCED; diff --git a/src/lib/libast/sfio/sfmove.c b/src/lib/libast/sfio/sfmove.c index 9684d9c1f..6b6b1a755 100644 --- a/src/lib/libast/sfio/sfmove.c +++ b/src/lib/libast/sfio/sfmove.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -43,12 +43,9 @@ Sfoff_t sfmove(Sfio_t* fr, /* moving data from this stream */ Sfoff_t n_move, sk, cur; uchar *rbuf = NIL(uchar*); ssize_t rsize = 0; - SFMTXDECL(fr); /* declare a shadow stream variable for from stream */ - SFMTXDECL2(fw); /* declare a shadow stream variable for to stream */ - SFMTXENTER(fr, (Sfoff_t)0); + if(!(fr)) return (Sfoff_t)0; if(fw) - SFMTXBEGIN2(fw, (Sfoff_t)0); for(n_move = 0; n != 0; ) { @@ -234,9 +231,8 @@ Sfoff_t sfmove(Sfio_t* fr, /* moving data from this stream */ if(fw) { SFOPEN(fw,0); - SFMTXEND2(fw); } SFOPEN(fr,0); - SFMTXRETURN(fr, n_move); + return n_move; } diff --git a/src/lib/libast/sfio/sfmutex.c b/src/lib/libast/sfio/sfmutex.c deleted file mode 100644 index fe8443733..000000000 --- a/src/lib/libast/sfio/sfmutex.c +++ /dev/null @@ -1,64 +0,0 @@ -/*********************************************************************** -* * -* This software is part of the ast package * -* Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * -* and is licensed under the * -* Eclipse Public License, Version 1.0 * -* by AT&T Intellectual Property * -* * -* A copy of the License is available at * -* http://www.eclipse.org/org/documents/epl-v10.html * -* (with md5 checksum b35adb5213ca9657e911e9befb180842) * -* * -* Information and Software Systems Research * -* AT&T Research * -* Florham Park NJ * -* * -* Glenn Fowler * -* David Korn * -* Phong Vo * -* * -***********************************************************************/ -#include "sfhdr.h" - -/* Obtain/release exclusive use of a stream. -** -** Written by Kiem-Phong Vo. -*/ - -/* the main locking/unlocking interface */ -int sfmutex(Sfio_t* f, int type) -{ -#if !vt_threaded - NOTUSED(f); NOTUSED(type); - return 0; -#else - - SFONCE(); - - if(!f) - return -1; - - if(!f->mutex) - { if(f->bits&SF_PRIVATE) - return 0; - - vtmtxlock(_Sfmutex); - f->mutex = vtmtxopen(NIL(Vtmutex_t*), VT_INIT); - vtmtxunlock(_Sfmutex); - if(!f->mutex) - return -1; - } - - if(type == SFMTX_LOCK) - return vtmtxlock(f->mutex); - else if(type == SFMTX_TRYLOCK) - return vtmtxtrylock(f->mutex); - else if(type == SFMTX_UNLOCK) - return vtmtxunlock(f->mutex); - else if(type == SFMTX_CLRLOCK) - return vtmtxclrlock(f->mutex); - else return -1; -#endif /*vt_threaded*/ -} diff --git a/src/lib/libast/sfio/sfnew.c b/src/lib/libast/sfio/sfnew.c index 0d0fc7376..2ab7d6b9e 100644 --- a/src/lib/libast/sfio/sfnew.c +++ b/src/lib/libast/sfio/sfnew.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -38,7 +38,6 @@ Sfio_t* sfnew(Sfio_t* oldf, /* old stream to be reused */ reg Sfio_t* f; reg int sflags; - SFONCE(); /* initialize mutexes */ if(!(flags&SF_RDWR)) return NIL(Sfio_t*); @@ -46,9 +45,7 @@ Sfio_t* sfnew(Sfio_t* oldf, /* old stream to be reused */ sflags = 0; if((f = oldf) ) { if(flags&SF_EOF) - { if(f != sfstdin && f != sfstdout && f != sfstderr) - f->mutex = NIL(Vtmutex_t*); - SFCLEAR(f, f->mutex); + { SFCLEAR(f); oldf = NIL(Sfio_t*); } else if(f->mode&SF_AVAIL) @@ -83,7 +80,7 @@ Sfio_t* sfnew(Sfio_t* oldf, /* old stream to be reused */ if(f) { if(f->mode&SF_AVAIL) { sflags = f->flags; - SFCLEAR(f, f->mutex); + SFCLEAR(f); } else f = NIL(Sfio_t*); } @@ -92,14 +89,10 @@ Sfio_t* sfnew(Sfio_t* oldf, /* old stream to be reused */ if(!f) { if(!(f = (Sfio_t*)malloc(sizeof(Sfio_t))) ) return NIL(Sfio_t*); - SFCLEAR(f, NIL(Vtmutex_t*)); + SFCLEAR(f); } } - /* create a mutex */ - if(!f->mutex) - f->mutex = vtmtxopen(NIL(Vtmutex_t*), VT_INIT); - /* stream type */ f->mode = (flags&SF_READ) ? SF_READ : SF_WRITE; f->flags = (flags&SFIO_FLAGS) | (sflags&(SF_MALLOC|SF_STATIC)); diff --git a/src/lib/libast/sfio/sfnputc.c b/src/lib/libast/sfio/sfnputc.c index 1f47293bb..12027b44b 100644 --- a/src/lib/libast/sfio/sfnputc.c +++ b/src/lib/libast/sfio/sfnputc.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -35,13 +35,13 @@ ssize_t sfnputc(Sfio_t* f, /* file to write */ reg ssize_t p, w; uchar buf[128]; reg int local; - SFMTXDECL(f); /* declare a local stream variable for multithreading */ - SFMTXENTER(f,-1); + if(!f) + return -1; GETLOCAL(f,local); if(SFMODE(f,local) != SF_WRITE && _sfmode(f,SF_WRITE,local) < 0) - SFMTXRETURN(f, -1); + return -1; SFLOCK(f,local); @@ -73,5 +73,5 @@ ssize_t sfnputc(Sfio_t* f, /* file to write */ } done : SFOPEN(f,local); - SFMTXRETURN(f, w); + return w; } diff --git a/src/lib/libast/sfio/sfpool.c b/src/lib/libast/sfio/sfpool.c index a85f48146..d6dbf175d 100644 --- a/src/lib/libast/sfio/sfpool.c +++ b/src/lib/libast/sfio/sfpool.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -37,13 +37,12 @@ */ static int delpool(reg Sfpool_t* p) { - POOLMTXENTER(p); if(p->s_sf && p->sf != p->array) free((void*)p->sf); p->mode = SF_AVAIL; - POOLMTXRETURN(p,0); + return 0; } static Sfpool_t* newpool(reg int mode) @@ -59,30 +58,22 @@ static Sfpool_t* newpool(reg int mode) } if(!p) - { POOLMTXLOCK(last); - - if(!(p = (Sfpool_t*) malloc(sizeof(Sfpool_t))) ) - { POOLMTXUNLOCK(last); + { if(!(p = (Sfpool_t*) malloc(sizeof(Sfpool_t))) ) return NIL(Sfpool_t*); - } - - (void)vtmtxopen(&p->mutex, VT_INIT); /* initialize mutex */ p->mode = 0; p->n_sf = 0; p->next = NIL(Sfpool_t*); last->next = p; - POOLMTXUNLOCK(last); } - POOLMTXENTER(p); p->mode = mode&SF_SHARE; p->s_sf = sizeof(p->array)/sizeof(p->array[0]); p->sf = p->array; - POOLMTXRETURN(p,p); + return p; } /* move a stream to head */ @@ -94,14 +85,13 @@ static int _sfphead(Sfpool_t* p, /* the pool */ reg ssize_t k, w, v; reg int rv; - POOLMTXENTER(p); if(n == 0) - POOLMTXRETURN(p,0); + return 0; head = p->sf[0]; if(SFFROZEN(head) ) - POOLMTXRETURN(p,-1); + return -1; SFLOCK(head,0); rv = -1; @@ -148,7 +138,7 @@ static int _sfphead(Sfpool_t* p, /* the pool */ done: head->mode &= ~SF_LOCK; /* partially unlock because it's no longer head */ - POOLMTXRETURN(p,rv); + return rv; } /* delete a stream from its pool */ @@ -156,7 +146,6 @@ static int _sfpdelete(Sfpool_t* p, /* the pool */ Sfio_t* f, /* the stream */ int n) /* position in pool */ { - POOLMTXENTER(p); p->n_sf -= 1; for(; n < p->n_sf; ++n) @@ -194,7 +183,7 @@ static int _sfpdelete(Sfpool_t* p, /* the pool */ } done: - POOLMTXRETURN(p,0); + return 0; } static int _sfpmove(reg Sfio_t* f, @@ -235,35 +224,21 @@ Sfio_t* sfpool(reg Sfio_t* f, reg Sfio_t* pf, reg int mode) } if(f) /* check for permissions */ - { SFMTXLOCK(f); - if((f->mode&SF_RDWR) != f->mode && _sfmode(f,0,0) < 0) - { SFMTXUNLOCK(f); + { if((f->mode&SF_RDWR) != f->mode && _sfmode(f,0,0) < 0) return NIL(Sfio_t*); - } if(f->disc == _Sfudisc) (void)sfclose((*_Sfstack)(f,NIL(Sfio_t*))); } if(pf) - { SFMTXLOCK(pf); - if((pf->mode&SF_RDWR) != pf->mode && _sfmode(pf,0,0) < 0) - { if(f) - SFMTXUNLOCK(f); - SFMTXUNLOCK(pf); + { if((pf->mode&SF_RDWR) != pf->mode && _sfmode(pf,0,0) < 0) return NIL(Sfio_t*); - } if(pf->disc == _Sfudisc) (void)sfclose((*_Sfstack)(pf,NIL(Sfio_t*))); } /* f already in the same pool with pf */ if(f == pf || (pf && f->pool == pf->pool && f->pool != &_Sfpool) ) - { - if(f) - SFMTXUNLOCK(f); - if(pf) - SFMTXUNLOCK(pf); return pf; - } /* lock streams before internal manipulations */ rv = NIL(Sfio_t*); @@ -329,11 +304,9 @@ Sfio_t* sfpool(reg Sfio_t* f, reg Sfio_t* pf, reg int mode) done: if(f) { SFOPEN(f,0); - SFMTXUNLOCK(f); } if(pf) { SFOPEN(pf,0); - SFMTXUNLOCK(pf); } return rv; } diff --git a/src/lib/libast/sfio/sfpopen.c b/src/lib/libast/sfio/sfpopen.c index 9a2fd86be..4c4cd412e 100644 --- a/src/lib/libast/sfio/sfpopen.c +++ b/src/lib/libast/sfio/sfpopen.c @@ -138,7 +138,7 @@ Sfio_t* sfpopen(Sfio_t* f, if (!command || !command[0] || !mode) return 0; - sflags = _sftype(mode, NIL(int*), NIL(int*), NIL(int*)); + sflags = _sftype(mode, NIL(int*), NIL(int*)); if(f == (Sfio_t*)(-1)) { /* stdio compatibility mode */ @@ -186,7 +186,7 @@ Sfio_t* sfpopen(Sfio_t* f, /* sanity check */ if(!command || !command[0] || !mode) return NIL(Sfio_t*); - sflags = _sftype(mode,NIL(int*),NIL(int*),NIL(int*)); + sflags = _sftype(mode,NIL(int*),NIL(int*)); /* make pipes */ parent[0] = parent[1] = child[0] = child[1] = -1; diff --git a/src/lib/libast/sfio/sfpurge.c b/src/lib/libast/sfio/sfpurge.c index 36d8a92f9..438b5e46f 100644 --- a/src/lib/libast/sfio/sfpurge.c +++ b/src/lib/libast/sfio/sfpurge.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -30,12 +30,9 @@ int sfpurge(Sfio_t* f) { reg int mode; - SFMTXDECL(f); - SFMTXENTER(f,-1); - - if((mode = f->mode&SF_RDWR) != (int)f->mode && _sfmode(f,mode|SF_SYNCED,0) < 0) - SFMTXRETURN(f, -1); + if(!f || (mode = f->mode&SF_RDWR) != (int)f->mode && _sfmode(f,mode|SF_SYNCED,0) < 0) + return -1; if((f->flags&SF_IOCHECK) && f->disc && f->disc->exceptf) (void)(*f->disc->exceptf)(f,SF_PURGE,(void*)((int)1),f->disc); @@ -58,7 +55,7 @@ int sfpurge(Sfio_t* f) (void)SFSK(f,f->here,SEEK_SET,f->disc); } SFOPEN(f,0); - SFMTXRETURN(f, 0); + return 0; } #endif @@ -66,7 +63,7 @@ int sfpurge(Sfio_t* f) { default : SFOPEN(f,0); - SFMTXRETURN(f, -1); + return -1; case SF_WRITE : f->next = f->data; if(!f->proc || !(f->flags&SF_READ) || !(f->mode&SF_WRITE) ) @@ -90,5 +87,5 @@ done: if((f->flags&SF_IOCHECK) && f->disc && f->disc->exceptf) (void)(*f->disc->exceptf)(f,SF_PURGE,(void*)((int)0),f->disc); - SFMTXRETURN(f, 0); + return 0; } diff --git a/src/lib/libast/sfio/sfputr.c b/src/lib/libast/sfio/sfputr.c index 0c8b87bc4..8f898552f 100644 --- a/src/lib/libast/sfio/sfputr.c +++ b/src/lib/libast/sfio/sfputr.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -33,12 +33,9 @@ ssize_t sfputr(Sfio_t* f, /* write to this stream */ ssize_t p, n, w, sn; uchar *ps; char *ss; - SFMTXDECL(f); - SFMTXENTER(f,-1); - - if(f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0) - SFMTXRETURN(f, -1); + if(!f || (f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0)) + return -1; SFLOCK(f,0); @@ -127,5 +124,5 @@ ssize_t sfputr(Sfio_t* f, /* write to this stream */ } SFOPEN(f,0); - SFMTXRETURN(f, w); + return w; } diff --git a/src/lib/libast/sfio/sfraise.c b/src/lib/libast/sfio/sfraise.c index 88881a2f9..1f595d800 100644 --- a/src/lib/libast/sfio/sfraise.c +++ b/src/lib/libast/sfio/sfraise.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -49,31 +49,23 @@ static int _sfraiseall(int type, /* type of event */ return rv; } -#if __STD_C -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* data; /* associated data */ -#endif +int sfraise(Sfio_t* f, /* stream */ + int type, /* type of event */ + void* data) /* associated data */ { reg Sfdisc_t *disc, *next, *d; reg int local, rv; - SFMTXDECL(f); if(!f) return _sfraiseall(type,data); - SFMTXENTER(f, -1); - GETLOCAL(f,local); if(!SFKILLED(f) && !(local && (type == SF_NEW || type == SF_CLOSING || type == SF_FINAL || type == SF_ATEXIT)) && SFMODE(f,local) != (f->mode&SF_RDWR) && _sfmode(f,0,local) < 0) - SFMTXRETURN(f, -1); + return -1; SFLOCK(f,local); for(disc = f->disc; disc; ) @@ -84,7 +76,7 @@ void* data; /* associated data */ if(disc->exceptf) { SFOPEN(f,0); if((rv = (*disc->exceptf)(f,type,data,disc)) != 0 ) - SFMTXRETURN(f, rv); + return rv; SFLOCK(f,0); } @@ -99,5 +91,5 @@ void* data; /* associated data */ } SFOPEN(f,local); - SFMTXRETURN(f, 0); + return 0; } diff --git a/src/lib/libast/sfio/sfrd.c b/src/lib/libast/sfio/sfrd.c index 63b311d92..55ef94e26 100644 --- a/src/lib/libast/sfio/sfrd.c +++ b/src/lib/libast/sfio/sfrd.c @@ -59,9 +59,9 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc) Sfoff_t r; reg Sfdisc_t* dc; reg int local, rcrv, dosync, oerrno; - SFMTXDECL(f); - SFMTXENTER(f,-1); + if(!f) + return -1; GETLOCAL(f,local); if((rcrv = f->mode & (SF_RC|SF_RV)) ) @@ -69,14 +69,14 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc) f->bits &= ~SF_JUSTSEEK; if(f->mode&SF_PKRD) - SFMTXRETURN(f, -1); + return -1; if(!local && !(f->bits&SF_DCDOWN)) /* an external user's call */ { if(f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0) - SFMTXRETURN(f, -1); + return -1; if(f->next < f->endb) { if(SFSYNC(f) < 0) - SFMTXRETURN(f, -1); + return -1; if((f->mode&(SF_SYNCED|SF_READ)) == (SF_SYNCED|SF_READ) ) { f->endb = f->next = f->endr = f->data; f->mode &= ~SF_SYNCED; @@ -94,7 +94,7 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc) for(dosync = 0;;) { /* stream locked by sfsetfd() */ if(!(f->flags&SF_STRING) && f->file < 0) - SFMTXRETURN(f, 0); + return 0; f->flags &= ~(SF_EOF|SF_ERROR); @@ -104,7 +104,7 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc) r = 0; if(r <= 0) goto do_except; - SFMTXRETURN(f, (ssize_t)r); + return (ssize_t)r; } /* warn that a read is about to happen */ @@ -117,7 +117,7 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc) n = rv; else if(rv < 0) { f->flags |= SF_ERROR; - SFMTXRETURN(f, (ssize_t)rv); + return (ssize_t)rv; } } @@ -195,7 +195,7 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc) } else n = f->endb - f->next; - SFMTXRETURN(f, n); + return n; } else { r = -1; @@ -276,7 +276,7 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc) f->endb = f->endr = ((uchar*)buf) + r; } - SFMTXRETURN(f, (ssize_t)r); + return (ssize_t)r; } do_except: @@ -288,13 +288,13 @@ ssize_t sfrd(Sfio_t* f, void* buf, size_t n, Sfdisc_t* disc) goto do_continue; case SF_EDONE : n = local ? 0 : (ssize_t)r; - SFMTXRETURN(f,n); + return n; case SF_EDISC : if(!local && !(f->flags&SF_STRING)) goto do_continue; /* FALLTHROUGH */ case SF_ESTACK : - SFMTXRETURN(f, -1); + return -1; } do_continue: diff --git a/src/lib/libast/sfio/sfread.c b/src/lib/libast/sfio/sfread.c index 3349c9eb3..53d804d57 100644 --- a/src/lib/libast/sfio/sfread.c +++ b/src/lib/libast/sfio/sfread.c @@ -34,31 +34,31 @@ ssize_t sfread(Sfio_t* f, /* read from this stream. */ reg uchar *s, *begs; reg ssize_t r; reg int local, justseek; - SFMTXDECL(f); - SFMTXENTER(f, (ssize_t)(-1)); + if(!f) + return (ssize_t)(-1); GETLOCAL(f,local); justseek = f->bits&SF_JUSTSEEK; f->bits &= ~SF_JUSTSEEK; if(!buf) - SFMTXRETURN(f, (ssize_t)(n == 0 ? 0 : -1) ); + return (ssize_t)(n == 0 ? 0 : -1) ; /* release peek lock */ if(f->mode&SF_PEEK) { if(!(f->mode&SF_READ) ) - SFMTXRETURN(f, (ssize_t)(-1)); + return (ssize_t)(-1); if(f->mode&SF_GETR) { if(((uchar*)buf + f->val) != f->next && (!f->rsrv || f->rsrv->data != (uchar*)buf) ) - SFMTXRETURN(f, (ssize_t)(-1)); + return (ssize_t)(-1); f->mode &= ~SF_PEEK; - SFMTXRETURN(f, 0); + return 0; } else { if((uchar*)buf != f->next) - SFMTXRETURN(f, (ssize_t)(-1)); + return (ssize_t)(-1); f->mode &= ~SF_PEEK; if(f->mode&SF_PKRD) { /* actually read the data now */ @@ -70,7 +70,7 @@ ssize_t sfread(Sfio_t* f, /* read from this stream. */ } f->next += n; f->endr = f->endb; - SFMTXRETURN(f, n); + return n; } } @@ -79,7 +79,7 @@ ssize_t sfread(Sfio_t* f, /* read from this stream. */ { /* check stream mode */ if(SFMODE(f,local) != SF_READ && _sfmode(f,SF_READ,local) < 0) { n = s > begs ? s-begs : (size_t)(-1); - SFMTXRETURN(f, (ssize_t)n); + return (ssize_t)n; } SFLOCK(f,local); @@ -132,5 +132,5 @@ ssize_t sfread(Sfio_t* f, /* read from this stream. */ SFOPEN(f,local); r = s-begs; - SFMTXRETURN(f, r); + return r; } diff --git a/src/lib/libast/sfio/sfreserve.c b/src/lib/libast/sfio/sfreserve.c index 015fcd467..74df325cf 100644 --- a/src/lib/libast/sfio/sfreserve.c +++ b/src/lib/libast/sfio/sfreserve.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -35,9 +35,9 @@ void* sfreserve(Sfio_t* f, /* file to peek */ reg Sfrsrv_t* rsrv; reg void* data; reg int mode, local; - SFMTXDECL(f); - SFMTXENTER(f,NIL(void*)); + if(!f) + return NIL(void*); sz = size < 0 ? -size : size; @@ -63,19 +63,19 @@ void* sfreserve(Sfio_t* f, /* file to peek */ data = NIL(void*); } - SFMTXRETURN(f, data); + return data; } if(type > 0) { if(type == 1 ) /* upward compatibility mode */ type = SF_LOCKR; else if(type != SF_LOCKR) - SFMTXRETURN(f, NIL(void*)); + return 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*)); + return NIL(void*); SFLOCK(f,0); if((n = f->endb - f->next) < 0) @@ -92,7 +92,7 @@ void* sfreserve(Sfio_t* f, /* file to peek */ mode = SF_WRITE; if((int)f->mode != mode && _sfmode(f,mode,local) < 0) { SFOPEN(f,0); - SFMTXRETURN(f, NIL(void*)); + return NIL(void*); } SFLOCK(f,local); @@ -202,5 +202,5 @@ done: /* compute the buffer to be returned */ _Sfi = f->val = n; /* return true buffer size */ - SFMTXRETURN(f, data); + return data; } diff --git a/src/lib/libast/sfio/sfresize.c b/src/lib/libast/sfio/sfresize.c index 9d61b851f..0d87c1757 100644 --- a/src/lib/libast/sfio/sfresize.c +++ b/src/lib/libast/sfio/sfresize.c @@ -28,13 +28,10 @@ int sfresize(Sfio_t* f, Sfoff_t size) { - SFMTXDECL(f); - - SFMTXENTER(f, -1); if(size < 0 || f->extent < 0 || - (f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0) ) - SFMTXRETURN(f, -1); + !f || (f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0)) + return -1; SFLOCK(f,0); @@ -55,7 +52,7 @@ int sfresize(Sfio_t* f, Sfoff_t size) } else { if(SFSK(f, size, SEEK_SET, f->disc) != size) - SFMTXRETURN(f, -1); + return -1; memclear((char*)(f->data+f->extent), (int)(size-f->extent)); } } @@ -64,9 +61,9 @@ int sfresize(Sfio_t* f, Sfoff_t size) SFSYNC(f); #if _lib_ftruncate if(ftruncate(f->file, (off_t)size) < 0) - SFMTXRETURN(f, -1); + return -1; #else - SFMTXRETURN(f, -1); + return -1; #endif } @@ -74,5 +71,5 @@ int sfresize(Sfio_t* f, Sfoff_t size) SFOPEN(f, 0); - SFMTXRETURN(f, 0); + return 0; } diff --git a/src/lib/libast/sfio/sfscanf.c b/src/lib/libast/sfio/sfscanf.c index e8c0930ec..26737abd7 100644 --- a/src/lib/libast/sfio/sfscanf.c +++ b/src/lib/libast/sfio/sfscanf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -45,7 +45,7 @@ int sfvsscanf(const char* s, const char* form, va_list args) return -1; /* make a fake stream */ - SFCLEAR(&f,NIL(Vtmutex_t*)); + SFCLEAR(&f); f.flags = SF_STRING|SF_READ; f.bits = SF_PRIVATE; f.mode = SF_READ; diff --git a/src/lib/libast/sfio/sfseek.c b/src/lib/libast/sfio/sfseek.c index 3cda4243d..651cdee3e 100644 --- a/src/lib/libast/sfio/sfseek.c +++ b/src/lib/libast/sfio/sfseek.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -49,9 +49,9 @@ Sfoff_t sfseek(Sfio_t* f, /* seek to a new location in this stream */ { Sfoff_t r, s; int mode, local, hardseek, mustsync; - SFMTXDECL(f); - SFMTXENTER(f, (Sfoff_t)(-1)); + if(!f) + return (Sfoff_t)(-1); GETLOCAL(f,local); @@ -73,7 +73,7 @@ Sfoff_t sfseek(Sfio_t* f, /* seek to a new location in this stream */ f->flags = flags; if(mode < 0) - SFMTXRETURN(f, (Sfoff_t)(-1)); + return (Sfoff_t)(-1); } mustsync = (type&SF_SHARE) && !(type&SF_PUBLIC) && @@ -83,13 +83,13 @@ Sfoff_t sfseek(Sfio_t* f, /* seek to a new location in this stream */ if((type &= (SEEK_SET|SEEK_CUR|SEEK_END)) != SEEK_SET && type != SEEK_CUR && type != SEEK_END ) { errno = EINVAL; - SFMTXRETURN(f, (Sfoff_t)(-1)); + return (Sfoff_t)(-1); } if(f->extent < 0) { /* let system call set errno */ (void)SFSK(f,(Sfoff_t)0,SEEK_CUR,f->disc); - SFMTXRETURN(f, (Sfoff_t)(-1)); + return (Sfoff_t)(-1); } /* throw away ungetc data */ @@ -267,5 +267,5 @@ done : if(mustsync) sfsync(f); - SFMTXRETURN(f, p); + return p; } diff --git a/src/lib/libast/sfio/sfset.c b/src/lib/libast/sfio/sfset.c index ca87975a4..65e2814c8 100644 --- a/src/lib/libast/sfio/sfset.c +++ b/src/lib/libast/sfio/sfset.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -30,12 +30,12 @@ int sfset(Sfio_t* f, int flags, int set) { reg int oflags, tflags, rv; - SFMTXDECL(f); - SFMTXENTER(f,0); + if(!f) + return 0; if(flags == 0 && set == 0) - SFMTXRETURN(f, (f->flags&SFIO_FLAGS)); + return (f->flags&SFIO_FLAGS); if((oflags = (f->mode&SF_RDWR)) != (int)f->mode) { /* avoid sfsetbuf() isatty() call if user sets (SF_LINE|SF_WCWIDTH) */ @@ -48,10 +48,10 @@ int sfset(Sfio_t* f, int flags, int set) if(tflags) f->flags &= ~tflags; if(rv < 0) - SFMTXRETURN(f, 0); + return 0; } if(flags == 0) - SFMTXRETURN(f, (f->flags&SFIO_FLAGS)); + return (f->flags&SFIO_FLAGS); SFLOCK(f,0); @@ -89,5 +89,5 @@ int sfset(Sfio_t* f, int flags, int set) f->flags &= ~SF_PUBLIC; SFOPEN(f,0); - SFMTXRETURN(f, (oflags&SFIO_FLAGS)); + return (oflags&SFIO_FLAGS); } diff --git a/src/lib/libast/sfio/sfsetbuf.c b/src/lib/libast/sfio/sfsetbuf.c index d1d09958a..f91faafbf 100644 --- a/src/lib/libast/sfio/sfsetbuf.c +++ b/src/lib/libast/sfio/sfsetbuf.c @@ -110,18 +110,17 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ struct stat st; uchar* obuf = NIL(uchar*); ssize_t osize = 0; - SFMTXDECL(f); - SFONCE(); - SFMTXENTER(f,NIL(void*)); + if(!f) + return 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*)f->data); + return (void*)f->data; } /* cleanup actions already done, don't allow write buffering any more */ @@ -132,10 +131,10 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ if((init = f->mode&SF_INIT) ) { if(!f->pool && _sfsetpool(f) < 0) - SFMTXRETURN(f, NIL(void*)); + return NIL(void*); } else if((f->mode&SF_RDWR) != SFMODE(f,local) && _sfmode(f,0,local) < 0) - SFMTXRETURN(f, NIL(void*)); + return NIL(void*); if(init) f->mode = (f->mode&SF_RDWR)|SF_LOCK; @@ -145,12 +144,12 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ /* 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*)); + return NIL(void*); /* synchronize first */ SFLOCK(f,local); rv = SFSYNC(f); SFOPEN(f,local); if(rv < 0) - SFMTXRETURN(f, NIL(void*)); + return NIL(void*); /* turn off the SF_SYNCED bit because buffer is changing */ f->mode &= ~SF_SYNCED; @@ -416,5 +415,5 @@ done: SFOPEN(f,local); - SFMTXRETURN(f, (void*)obuf); + return (void*)obuf; } diff --git a/src/lib/libast/sfio/sfsetfd.c b/src/lib/libast/sfio/sfsetfd.c index ed729d9fc..9b262248c 100644 --- a/src/lib/libast/sfio/sfsetfd.c +++ b/src/lib/libast/sfio/sfsetfd.c @@ -53,22 +53,22 @@ static int _sfdup(int fd, int newfd) int sfsetfd(Sfio_t* f, int newfd) { reg int oldfd; - SFMTXDECL(f); - SFMTXENTER(f, -1); + if(!f) + return -1; if(f->flags&SF_STRING) - SFMTXRETURN(f, -1); + return -1; if((f->mode&SF_INIT) && f->file < 0) { /* restoring file descriptor after a previous freeze */ if(newfd < 0) - SFMTXRETURN(f, -1); + return -1; } else { /* change file descriptor */ if((f->mode&SF_RDWR) != f->mode && _sfmode(f,0,0) < 0) - SFMTXRETURN(f, -1); + return -1; SFLOCK(f,0); oldfd = f->file; @@ -76,7 +76,7 @@ int sfsetfd(Sfio_t* f, int newfd) { if(newfd >= 0) { if((newfd = _sfdup(oldfd,newfd)) < 0) { SFOPEN(f,0); - SFMTXRETURN(f, -1); + return -1; } CLOSE(oldfd); } @@ -86,7 +86,7 @@ int sfsetfd(Sfio_t* f, int newfd) (f->mode&SF_READ) || f->disc == _Sfudisc) { if(SFSYNC(f) < 0) { SFOPEN(f,0); - SFMTXRETURN(f, -1); + return -1; } } @@ -94,7 +94,7 @@ int sfsetfd(Sfio_t* f, int newfd) ((f->mode&SF_READ) && f->extent < 0 && f->next < f->endb) ) { SFOPEN(f,0); - SFMTXRETURN(f, -1); + return -1; } #ifdef MAP_TYPE @@ -121,5 +121,5 @@ int sfsetfd(Sfio_t* f, int newfd) f->file = newfd; - SFMTXRETURN(f,newfd); + return newfd; } diff --git a/src/lib/libast/sfio/sfsize.c b/src/lib/libast/sfio/sfsize.c index 4827acbaa..e308e615a 100644 --- a/src/lib/libast/sfio/sfsize.c +++ b/src/lib/libast/sfio/sfsize.c @@ -31,16 +31,13 @@ Sfoff_t sfsize(Sfio_t* f) Sfdisc_t* disc; reg int mode; Sfoff_t s; - SFMTXDECL(f); - SFMTXENTER(f, (Sfoff_t)(-1)); - - if((mode = f->mode&SF_RDWR) != (int)f->mode && _sfmode(f,mode,0) < 0) - SFMTXRETURN(f, (Sfoff_t)(-1)); + if(!f || ((mode = f->mode&SF_RDWR) != (int)f->mode && _sfmode(f,mode,0) < 0)) + return (Sfoff_t)(-1); if(f->flags&SF_STRING) { SFSTRSIZE(f); - SFMTXRETURN(f, f->extent); + return f->extent; } SFLOCK(f,0); @@ -101,5 +98,5 @@ Sfoff_t sfsize(Sfio_t* f) } SFOPEN(f,0); - SFMTXRETURN(f, s); + return s; } diff --git a/src/lib/libast/sfio/sfsk.c b/src/lib/libast/sfio/sfsk.c index ef8160180..566c27eef 100644 --- a/src/lib/libast/sfio/sfsk.c +++ b/src/lib/libast/sfio/sfsk.c @@ -32,16 +32,16 @@ Sfoff_t sfsk(Sfio_t* f, Sfoff_t addr, int type, Sfdisc_t* disc) reg Sfdisc_t* dc; reg ssize_t s; reg int local, mode; - SFMTXDECL(f); - SFMTXENTER(f, (Sfoff_t)(-1)); + if(!f) + return (Sfoff_t)(-1); GETLOCAL(f,local); if(!local && !(f->bits&SF_DCDOWN)) { if((mode = f->mode&SF_RDWR) != (int)f->mode && _sfmode(f,mode,0) < 0) - SFMTXRETURN(f, (Sfoff_t)(-1)); + return (Sfoff_t)(-1); if(SFSYNC(f) < 0) - SFMTXRETURN(f, (Sfoff_t)(-1)); + return (Sfoff_t)(-1); #ifdef MAP_TYPE if(f->mode == SF_READ && (f->bits&SF_MMAP) && f->data) { SFMUNMAP(f, f->data, f->endb-f->data); @@ -52,7 +52,7 @@ Sfoff_t sfsk(Sfio_t* f, Sfoff_t addr, int type, Sfdisc_t* disc) } if((type &= (SEEK_SET|SEEK_CUR|SEEK_END)) > SEEK_END) - SFMTXRETURN(f, (Sfoff_t)(-1)); + return (Sfoff_t)(-1); for(;;) { dc = disc; @@ -73,7 +73,7 @@ Sfoff_t sfsk(Sfio_t* f, Sfoff_t addr, int type, Sfdisc_t* disc) { p = lseek(f->file,(off_t)addr,type); } if(p >= 0) - SFMTXRETURN(f,p); + return p; s = -1; } @@ -84,10 +84,10 @@ Sfoff_t sfsk(Sfio_t* f, Sfoff_t addr, int type, Sfdisc_t* disc) case SF_EDISC: case SF_ECONT: if(f->flags&SF_STRING) - SFMTXRETURN(f, (Sfoff_t)s); + return (Sfoff_t)s; goto do_continue; default: - SFMTXRETURN(f, (Sfoff_t)(-1)); + return (Sfoff_t)(-1); } do_continue: diff --git a/src/lib/libast/sfio/sfstack.c b/src/lib/libast/sfio/sfstack.c index 839571a13..c500374a3 100644 --- a/src/lib/libast/sfio/sfstack.c +++ b/src/lib/libast/sfio/sfstack.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -28,44 +28,31 @@ ** Written by Kiem-Phong Vo. */ -#define STKMTXLOCK(f1,f2) \ - { if(f1) SFMTXLOCK(f1); \ - if(f2) SFMTXLOCK(f2); \ - } -#define STKMTXRETURN(f1,f2,rv) \ - { if(f1) SFMTXUNLOCK(f1); \ - if(f2) SFMTXUNLOCK(f2); \ - return(rv); \ - } - Sfio_t* sfstack(Sfio_t* f1, /* base of stack */ - Sfio_t* f2) /* top of stack */ + Sfio_t* f2) /* top of stack */ { reg int n; reg Sfio_t* rf; reg Sfrsrv_t* rsrv; - reg void* mtx; - - STKMTXLOCK(f1,f2); if(f1 && (f1->mode&SF_RDWR) != f1->mode && _sfmode(f1,0,0) < 0) - STKMTXRETURN(f1,f2, NIL(Sfio_t*)); + return NIL(Sfio_t*); if(f2 && (f2->mode&SF_RDWR) != f2->mode && _sfmode(f2,0,0) < 0) - STKMTXRETURN(f1,f2, NIL(Sfio_t*)); + return NIL(Sfio_t*); if(!f1) - STKMTXRETURN(f1,f2, f2); + return f2; /* give access to other internal functions */ _Sfstack = sfstack; if(f2 == SF_POPSTACK) { if(!(f2 = f1->push)) - STKMTXRETURN(f1,f2, NIL(Sfio_t*)); + return NIL(Sfio_t*); f2->mode &= ~SF_PUSH; } else { if(f2->push) - STKMTXRETURN(f1,f2, NIL(Sfio_t*)); + return NIL(Sfio_t*); if(f1->pool && f1->pool != &_Sfpool && f1->pool != f2->pool && f1 == f1->pool->sf[0]) { /* get something else to pool front since f1 will be locked */ @@ -84,9 +71,8 @@ Sfio_t* sfstack(Sfio_t* f1, /* base of stack */ /* swap streams */ sfswap(f1,f2); - /* but the reserved buffer and mutex must remain the same */ + /* but the reserved buffer must remain the same */ rsrv = f1->rsrv; f1->rsrv = f2->rsrv; f2->rsrv = rsrv; - mtx = f1->mutex; f1->mutex = f2->mutex; f2->mutex = mtx; SFLOCK(f1,0); SFLOCK(f2,0); @@ -107,5 +93,5 @@ Sfio_t* sfstack(Sfio_t* f1, /* base of stack */ SFOPEN(f1,0); SFOPEN(f2,0); - STKMTXRETURN(f1,f2, rf); + return rf; } diff --git a/src/lib/libast/sfio/sfswap.c b/src/lib/libast/sfio/sfswap.c index ec853906d..5c9537b32 100644 --- a/src/lib/libast/sfio/sfswap.c +++ b/src/lib/libast/sfio/sfswap.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -62,7 +62,7 @@ Sfio_t* sfswap(reg Sfio_t* f1, reg Sfio_t* f2) return NIL(Sfio_t*); } - SFCLEAR(f2,NIL(Vtmutex_t*)); + SFCLEAR(f2); } f2->mode = SF_AVAIL|SF_LOCK; f2mode = SF_AVAIL; diff --git a/src/lib/libast/sfio/sfsync.c b/src/lib/libast/sfio/sfsync.c index 1f02c79eb..734edadb2 100644 --- a/src/lib/libast/sfio/sfsync.c +++ b/src/lib/libast/sfio/sfsync.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -80,12 +80,11 @@ int sfsync(reg Sfio_t* f) { int local, rv, mode, lock; Sfio_t* origf; - SFMTXDECL(f); if(!(origf = f) ) return _sfall(); - SFMTXENTER(origf,-1); + if(!(origf)) return -1; GETLOCAL(origf,local); @@ -160,5 +159,5 @@ done: if(!local && f && (f->mode&SF_POOL) && f->pool && f != f->pool->sf[0]) SFSYNC(f->pool->sf[0]); - SFMTXRETURN(origf, rv); + return rv; } diff --git a/src/lib/libast/sfio/sftell.c b/src/lib/libast/sfio/sftell.c index f69acb05b..fc064df15 100644 --- a/src/lib/libast/sfio/sftell.c +++ b/src/lib/libast/sfio/sftell.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -31,25 +31,22 @@ Sfoff_t sftell(Sfio_t* f) { reg int mode; Sfoff_t p; - SFMTXDECL(f); - - SFMTXENTER(f, (Sfoff_t)(-1)); /* set the stream to the right mode */ - if((mode = f->mode&SF_RDWR) != (int)f->mode && _sfmode(f,mode,0) < 0) - SFMTXRETURN(f, (Sfoff_t)(-1)); + if(!f || ((mode = f->mode&SF_RDWR) != (int)f->mode && _sfmode(f,mode,0) < 0)) + return (Sfoff_t)(-1); /* throw away ungetc data */ if(f->disc == _Sfudisc) (void)sfclose((*_Sfstack)(f,NIL(Sfio_t*))); if(f->flags&SF_STRING) - SFMTXRETURN(f, (Sfoff_t)(f->next-f->data)); + return (Sfoff_t)(f->next-f->data); /* let sfseek() handle the hard case */ if(f->extent >= 0 && (f->flags&(SF_SHARE|SF_APPENDWR)) ) p = sfseek(f,(Sfoff_t)0,SEEK_CUR); else p = f->here + ((f->mode&SF_WRITE) ? f->next-f->data : f->next-f->endb); - SFMTXRETURN(f,p); + return p; } diff --git a/src/lib/libast/sfio/sftmp.c b/src/lib/libast/sfio/sftmp.c index f0c9ceefb..0ab5fa682 100644 --- a/src/lib/libast/sfio/sftmp.c +++ b/src/lib/libast/sfio/sftmp.c @@ -72,7 +72,6 @@ static int _tmprmfile(Sfio_t* f, int type, void* val, Sfdisc_t* disc) if(type == SF_CLOSING) { - (void)vtmtxlock(_Sfmutex); for(last = NIL(File_t*), ff = File; ff; last = ff, ff = ff->next) if(ff->f == f) break; @@ -90,7 +89,6 @@ static int _tmprmfile(Sfio_t* f, int type, void* val, Sfdisc_t* disc) free((void*)ff); } - (void)vtmtxunlock(_Sfmutex); } return 0; @@ -99,12 +97,10 @@ static int _tmprmfile(Sfio_t* f, int type, void* val, Sfdisc_t* disc) static void _rmfiles(void) { reg File_t *ff, *next; - (void)vtmtxlock(_Sfmutex); for(ff = File; ff; ff = next) { next = ff->next; _tmprmfile(ff->f, SF_CLOSING, NIL(void*), ff->f->disc); } - (void)vtmtxunlock(_Sfmutex); } static Sfdisc_t Rmdisc = @@ -122,12 +118,10 @@ static int _rmtmp(Sfio_t* f, char* file) if(!(ff = (File_t*)malloc(sizeof(File_t)+strlen(file))) ) return -1; - (void)vtmtxlock(_Sfmutex); ff->f = f; strcpy(ff->name,file); ff->next = File; File = ff; - (void)vtmtxunlock(_Sfmutex); #else /* can remove now */ while(remove(file) < 0 && errno == EINTR) @@ -292,7 +286,7 @@ static int _tmpexcept(Sfio_t* f, int type, void* val, Sfdisc_t* disc) return 0; /* try to create the temp file */ - SFCLEAR(&newf,NIL(Vtmutex_t*)); + SFCLEAR(&newf); newf.flags = SF_STATIC; newf.mode = SF_AVAIL; @@ -307,12 +301,6 @@ static int _tmpexcept(Sfio_t* f, int type, void* val, Sfdisc_t* disc) if(!sf) return -1; - if(newf.mutex) /* don't need a mutex for this stream */ - { (void)vtmtxclrlock(newf.mutex); - (void)vtmtxclose(newf.mutex); - newf.mutex = NIL(Vtmutex_t*); - } - /* make sure that new stream has the same mode */ if((m = f->flags&(SF_READ|SF_WRITE)) != (SF_READ|SF_WRITE)) sfset(sf, ((~m)&(SF_READ|SF_WRITE)), 0); @@ -325,7 +313,6 @@ static int _tmpexcept(Sfio_t* f, int type, void* val, Sfdisc_t* disc) f->pool = savf.pool; f->rsrv = savf.rsrv; f->proc = savf.proc; - f->mutex = savf.mutex; f->stdio = savf.stdio; /* remove the SF_STATIC bit if it was only set above in making newf */ diff --git a/src/lib/libast/sfio/sfungetc.c b/src/lib/libast/sfio/sfungetc.c index c1db1f014..bed19d236 100644 --- a/src/lib/libast/sfio/sfungetc.c +++ b/src/lib/libast/sfio/sfungetc.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -45,12 +45,9 @@ 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); - SFMTXENTER(f, -1); - - if(c < 0 || (f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0)) - SFMTXRETURN(f, -1); + if(!f || c < 0 || (f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0)) + return -1; SFLOCK(f,0); /* fast handling of the typical unget */ @@ -92,5 +89,5 @@ int sfungetc(Sfio_t* f, /* push back one byte to this stream */ *--f->next = (uchar)c; done: SFOPEN(f,0); - SFMTXRETURN(f, c); + return c; } diff --git a/src/lib/libast/sfio/sfvprintf.c b/src/lib/libast/sfio/sfvprintf.c index 6e25232ad..23b74d815 100644 --- a/src/lib/libast/sfio/sfvprintf.c +++ b/src/lib/libast/sfio/sfvprintf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -162,18 +162,15 @@ int sfvprintf(Sfio_t* f, /* file to print to */ } #endif /* _sffmt_small */ - SFMTXDECL(f); SFCVINIT(); /* initialize conversion tables */ - SFMTXENTER(f,-1); - - if(!form) - SFMTXRETURN(f, -1); + if(!f || !form) + return -1; /* make sure stream is in write mode and buffer is not NULL */ if(f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0) - SFMTXRETURN(f, -1); + return -1; SFLOCK(f,0); @@ -1436,5 +1433,5 @@ done: else f->next += n; SFOPEN(f,0); - SFMTXRETURN(f, n_output); + return n_output; } diff --git a/src/lib/libast/sfio/sfvscanf.c b/src/lib/libast/sfio/sfvscanf.c index 31e8d26b8..e67cee4ac 100644 --- a/src/lib/libast/sfio/sfvscanf.c +++ b/src/lib/libast/sfio/sfvscanf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -314,14 +314,11 @@ int sfvscanf(Sfio_t* f, /* file to be scanned */ (int)(*d++) : -1 ) #define SFungetc(f,c) (d -= 1) - SFMTXDECL(f); SFCVINIT(); /* initialize conversion tables */ - SFMTXENTER(f,-1); - - if(!form || f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0) - SFMTXRETURN(f, -1); + if(!f || !form || (f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0)) + return -1; SFLOCK(f,0); SFinit(f); /* initialize local buffering system */ @@ -1061,5 +1058,5 @@ done: if(n_assign == 0 && inp < 0) n_assign = -1; - SFMTXRETURN(f,n_assign); + return n_assign; } diff --git a/src/lib/libast/sfio/sfwr.c b/src/lib/libast/sfio/sfwr.c index 9fe822b3e..a3156951b 100644 --- a/src/lib/libast/sfio/sfwr.c +++ b/src/lib/libast/sfio/sfwr.c @@ -123,22 +123,22 @@ ssize_t sfwr(Sfio_t* f, const void* buf, size_t n, Sfdisc_t* disc) reg ssize_t w; reg Sfdisc_t* dc; reg int local, oerrno; - SFMTXDECL(f); - SFMTXENTER(f,(ssize_t)(-1)); + if(!f) + return (ssize_t)(-1); GETLOCAL(f,local); if(!local && !(f->bits&SF_DCDOWN)) /* an external user's call */ { if(f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0 ) - SFMTXRETURN(f, (ssize_t)(-1)); + return (ssize_t)(-1); if(f->next > f->data && SFSYNC(f) < 0 ) - SFMTXRETURN(f, (ssize_t)(-1)); + return (ssize_t)(-1); } for(;;) { /* stream locked by sfsetfd() */ if(!(f->flags&SF_STRING) && f->file < 0) - SFMTXRETURN(f,(ssize_t)0); + return (ssize_t)0; /* clear current error states */ f->flags &= ~(SF_EOF|SF_ERROR); @@ -157,7 +157,7 @@ ssize_t sfwr(Sfio_t* f, const void* buf, size_t n, Sfdisc_t* disc) n = rv; else if(rv < 0) { f->flags |= SF_ERROR; - SFMTXRETURN(f, rv); + return rv; } } @@ -208,7 +208,7 @@ ssize_t sfwr(Sfio_t* f, const void* buf, size_t n, Sfdisc_t* disc) f->extent = f->here; } - SFMTXRETURN(f, (ssize_t)w); + return (ssize_t)w; } } @@ -220,13 +220,13 @@ ssize_t sfwr(Sfio_t* f, const void* buf, size_t n, Sfdisc_t* disc) goto do_continue; case SF_EDONE : w = local ? 0 : w; - SFMTXRETURN(f, (ssize_t)w); + return (ssize_t)w; case SF_EDISC : if(!local && !(f->flags&SF_STRING)) goto do_continue; /* FALLTHROUGH */ case SF_ESTACK : - SFMTXRETURN(f, (ssize_t)(-1)); + return (ssize_t)(-1); } do_continue: diff --git a/src/lib/libast/sfio/sfwrite.c b/src/lib/libast/sfio/sfwrite.c index 778f32a36..fc2ba6f61 100644 --- a/src/lib/libast/sfio/sfwrite.c +++ b/src/lib/libast/sfio/sfwrite.c @@ -34,23 +34,23 @@ ssize_t sfwrite(Sfio_t* f, /* write to this stream. */ reg uchar *s, *begs, *next; reg ssize_t w; reg int local; - SFMTXDECL(f); - SFMTXENTER(f, (ssize_t)(-1)); + if(!f) + return (ssize_t)(-1); GETLOCAL(f,local); if(!buf) - SFMTXRETURN(f, (ssize_t)(n == 0 ? 0 : -1) ); + return (ssize_t)(n == 0 ? 0 : -1) ; /* release peek lock */ if(f->mode&SF_PEEK) { if(!(f->mode&SF_WRITE) && (f->flags&SF_RDWR) != SF_RDWR) - SFMTXRETURN(f, (ssize_t)(-1)); + return (ssize_t)(-1); if((uchar*)buf != f->next && (!f->rsrv || f->rsrv->data != (uchar*)buf) ) - SFMTXRETURN(f, (ssize_t)(-1)); + return (ssize_t)(-1); f->mode &= ~SF_PEEK; @@ -83,7 +83,7 @@ ssize_t sfwrite(Sfio_t* f, /* write to this stream. */ { /* check stream mode */ if(SFMODE(f,local) != SF_WRITE && _sfmode(f,SF_WRITE,local) < 0 ) { w = s > begs ? s-begs : -1; - SFMTXRETURN(f,w); + return w; } SFLOCK(f,local); @@ -163,5 +163,5 @@ ssize_t sfwrite(Sfio_t* f, /* write to this stream. */ SFOPEN(f,local); w = s-begs; - SFMTXRETURN(f,w); + return w; } diff --git a/src/lib/libast/sfio/vthread.h b/src/lib/libast/sfio/vthread.h deleted file mode 100644 index 5c29eb3fb..000000000 --- a/src/lib/libast/sfio/vthread.h +++ /dev/null @@ -1,203 +0,0 @@ -/*********************************************************************** -* * -* This software is part of the ast package * -* Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * -* and is licensed under the * -* Eclipse Public License, Version 1.0 * -* by AT&T Intellectual Property * -* * -* A copy of the License is available at * -* http://www.eclipse.org/org/documents/epl-v10.html * -* (with md5 checksum b35adb5213ca9657e911e9befb180842) * -* * -* Information and Software Systems Research * -* AT&T Research * -* Florham Park NJ * -* * -* Glenn Fowler * -* David Korn * -* Phong Vo * -* * -***********************************************************************/ -#ifndef _VTHREAD_H -#define _VTHREAD_H 1 - -#define VTHREAD_VERSION 20001201L - -/* Header for the Vthread library. -** Note that the macro vt_threaded may be defined -** outside of vthread.h to suppress threading. -** -** Written by Kiem-Phong Vo, kpv@research.att.com -*/ - -#include -#include - -/* AST doesn't do threads yet */ -#if _PACKAGE_ast && !defined(vt_threaded) -#define vt_threaded 0 -#endif - -#if !defined(vt_threaded) || (defined(vt_threaded) && vt_threaded == 1) -#define _may_use_threads 1 -#else -#define _may_use_threads 0 -#endif -#undef vt_threaded - -#if _may_use_threads && !defined(vt_threaded) && _hdr_pthread -#define vt_threaded 1 -#include -typedef pthread_mutex_t _vtmtx_t; -typedef pthread_once_t _vtonce_t; -typedef pthread_t _vtself_t; -typedef pthread_t _vtid_t; -typedef pthread_attr_t _vtattr_t; - -#if !defined(PTHREAD_ONCE_INIT) && defined(pthread_once_init) -#define PTHREAD_ONCE_INIT pthread_once_init -#endif - -#endif - -#if _may_use_threads && !defined(vt_threaded) && _WIN32 -#define vt_threaded 1 -#include -typedef CRITICAL_SECTION _vtmtx_t; -typedef int _vtonce_t; -typedef HANDLE _vtself_t; -typedef DWORD _vtid_t; -typedef SECURITY_ATTRIBUTES _vtattr_t; -#endif - -#ifndef vt_threaded -#define vt_threaded 0 -#endif - -/* common attributes for various structures */ -#define VT_RUNNING 000000001 /* thread is running */ -#define VT_SUSPENDED 000000002 /* thread is suspended */ -#define VT_WAITED 000000004 /* thread has been waited */ -#define VT_FREE 000010000 /* object can be freed */ -#define VT_INIT 000020000 /* object was initialized */ -#define VT_BITS 000030007 /* bits that we care about */ - -/* directives for vtset() */ -#define VT_STACK 1 /* set stack size */ - -typedef struct _vtmutex_s Vtmutex_t; -typedef struct _vtonce_s Vtonce_t; -typedef struct _vthread_s Vthread_t; - -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 int vtonce(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 void* vtstatus(Vthread_t*); -extern int vterror(Vthread_t*); -extern int vtmtxerror(Vtmutex_t*); -extern int vtonceerror(Vtonce_t*); - -#if vt_threaded - -/* mutex structure */ -struct _vtmutex_s -{ _vtmtx_t lock; - int count; - _vtid_t owner; - int state; - int error; -}; - -/* structure for states of thread */ -struct _vthread_s -{ _vtself_t self; /* self-handle */ - _vtid_t id; /* thread ID */ - _vtattr_t attrs; /* attributes */ - size_t stack; /* stack size */ - int state; /* execution state */ - int error; /* error status */ - void* exit; /* exit value */ -}; - -/* structure for exactly once execution */ -struct _vtonce_s -{ int done; - _vtonce_t once; - int error; -}; - -#if _WIN32 -#define VTONCE_INITDATA {0, 0} -#else -#define VTONCE_INITDATA {0, PTHREAD_ONCE_INIT } -#endif - -#define vtstatus(vt) ((vt)->exit) -#define vterror(vt) ((vt)->error) -#define vtmtxerror(mtx) ((mtx)->error) -#define vtonceerror(once) ((once)->error) - -#endif /*vt_threaded*/ - -/* fake structures and functions */ -#if !vt_threaded -struct _vtmutex_s -{ int error; -}; -struct _vtattr_s -{ int error; -}; -struct _vthread_s -{ int error; -}; -struct _vtonce_s -{ int error; -}; - -typedef int _vtmtx_t; -typedef int _vtonce_t; -typedef int _vtself_t; -typedef int _vtid_t; -typedef int _vtattr_t; - -#define VTONCE_INITDATA {0} - -#define vtopen(vt,flgs) ((Vthread_t*)0) -#define vtclose(vt) (-1) -#define vtkill(vt) (-1) -#define vtwait(vt) (-1) -#define vtrun(vt,fn,arg) (-1) - -#define vtset(vt,t,v) (-1) -#define vtonce(on,fu) (-1) - -#define vtmtxopen(mtx,flgs) ((Vtmutex_t*)0) -#define vtmtxclose(mtx) (-1) -#define vtmtxlock(mtx) (-1) -#define vtmtxtrylock(mtx) (-1) -#define vtmtxunlock(mtx) (-1) -#define vtmtxclrlock(mtx) (-1) - -#define vtstatus(vt) ((void*)0) -#define vterror(vt) (0) -#define vtmtxerror(mtx) (0) -#define vtonceerror(once) (0) - -#endif /*!vt_threaded*/ - -#endif /*_VTHREAD_H*/ diff --git a/src/lib/libast/stdio/fdopen.c b/src/lib/libast/stdio/fdopen.c index 833b5aabc..3aae8567d 100644 --- a/src/lib/libast/stdio/fdopen.c +++ b/src/lib/libast/stdio/fdopen.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -28,7 +28,7 @@ fdopen(int fd, const char* mode) { int flags; - if (fd < 0 || !(flags = _sftype(mode, NiL, NiL, NiL))) + if (fd < 0 || !(flags = _sftype(mode, NiL, NiL))) return 0; return sfnew(NiL, NiL, (size_t)SF_UNBOUND, fd, flags); } diff --git a/src/lib/libast/stdio/flockfile.c b/src/lib/libast/stdio/flockfile.c index 4a1d0edf5..377754e33 100644 --- a/src/lib/libast/stdio/flockfile.c +++ b/src/lib/libast/stdio/flockfile.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -27,6 +27,4 @@ void flockfile(Sfio_t* f) { STDIO_VOID(f, "flockfile", void, (Sfio_t*), (f)) - - (void)sfmutex(f, SFMTX_LOCK); } diff --git a/src/lib/libast/stdio/fmemopen.c b/src/lib/libast/stdio/fmemopen.c index fa2d22813..686f04803 100644 --- a/src/lib/libast/stdio/fmemopen.c +++ b/src/lib/libast/stdio/fmemopen.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -28,5 +28,5 @@ fmemopen(void* buf, size_t size, const char* mode) { STDIO_PTR(0, "fmemopen", Sfio_t*, (void*, size_t, const char*), (buf, size, mode)) - return sfnew(NiL, buf, size, -1, SF_STRING|_sftype(mode, NiL, NiL, NiL)); + return sfnew(NiL, buf, size, -1, SF_STRING|_sftype(mode, NiL, NiL)); } diff --git a/src/lib/libast/stdio/ftrylockfile.c b/src/lib/libast/stdio/ftrylockfile.c index be32feccd..4bd20be4c 100644 --- a/src/lib/libast/stdio/ftrylockfile.c +++ b/src/lib/libast/stdio/ftrylockfile.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -28,5 +28,5 @@ ftrylockfile(Sfio_t* f) { STDIO_INT(f, "ftrylockfile", int, (Sfio_t*), (f)) - return sfmutex(f, SFMTX_TRYLOCK); + return 0; } diff --git a/src/lib/libast/stdio/funlockfile.c b/src/lib/libast/stdio/funlockfile.c index e5ebf015b..39675dc9b 100644 --- a/src/lib/libast/stdio/funlockfile.c +++ b/src/lib/libast/stdio/funlockfile.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -27,6 +27,4 @@ void funlockfile(Sfio_t* f) { STDIO_VOID(f, "funlockfile", void, (Sfio_t*), (f)) - - (void)sfmutex(f, SFMTX_UNLOCK); } diff --git a/src/lib/libast/stdio/getdelim.c b/src/lib/libast/stdio/getdelim.c index be51cca4a..d40ccd0e1 100644 --- a/src/lib/libast/stdio/getdelim.c +++ b/src/lib/libast/stdio/getdelim.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -32,17 +32,14 @@ getdelim(char** sp, size_t* np, int delim, Sfio_t* f) ssize_t p; uchar* s; uchar* ps; - SFMTXDECL(f); STDIO_INT(f, "getdelim", ssize_t, (char**, size_t*, int, Sfio_t*), (sp, np, delim, f)) - SFMTXENTER(f, -1); - if(delim < 0 || delim > 255 || !sp || !np) /* bad parameters */ - SFMTXRETURN(f, -1); + return -1; - if(f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0) - SFMTXRETURN(f, -1); + if(!f || (f->mode != SF_READ && _sfmode(f,SF_READ,0) < 0)) + return -1; SFLOCK(f,0); @@ -86,7 +83,7 @@ getdelim(char** sp, size_t* np, int delim, Sfio_t* f) } SFOPEN(f,0); - SFMTXRETURN(f,m); + return m; } ssize_t diff --git a/src/lib/libast/stdio/vswprintf.c b/src/lib/libast/stdio/vswprintf.c index 361d9129b..fdfbb111c 100644 --- a/src/lib/libast/stdio/vswprintf.c +++ b/src/lib/libast/stdio/vswprintf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -36,7 +36,7 @@ vswprintf(wchar_t* s, size_t n, const wchar_t* fmt, va_list args) * make a fake stream */ - SFCLEAR(&f, NiL); + SFCLEAR(&f); f.flags = SF_STRING|SF_WRITE; f.bits = SF_PRIVATE; f.mode = SF_WRITE; diff --git a/src/lib/libast/stdio/vswscanf.c b/src/lib/libast/stdio/vswscanf.c index 702bc534f..ea0fff70e 100644 --- a/src/lib/libast/stdio/vswscanf.c +++ b/src/lib/libast/stdio/vswscanf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2021 Contributors to ksh 93u+m * +* Copyright (c) 2020-2022 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -35,7 +35,7 @@ vswscanf(const wchar_t* s, const wchar_t* fmt, va_list args) * make a fake stream */ - SFCLEAR(&f, NiL); + SFCLEAR(&f); f.flags = SF_STRING|SF_READ; f.bits = SF_PRIVATE; f.mode = SF_READ;