newlib-2.4.0

git-svn-id: svn://kolibrios.org@6536 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2016-09-27 20:37:49 +00:00
parent 8eb81c3968
commit e6fe081453
120 changed files with 7543 additions and 1031 deletions

View File

@ -1,10 +1,11 @@
CC = kos32-gcc
AR = kos32-ar
LD = kos32-ld
CFLAGS = -c -O2 -fno-ident -fomit-frame-pointer -fexceptions -DMISSING_SYSCALL_NAMES
LDFLAGS = -shared -s -T libcdll.lds --out-implib libc.dll.a --image-base 0
INSTALLDIR:= /home/autobuild/tools/win32/lib
CFLAGS = -c -O2 -fno-builtin -fno-ident -fomit-frame-pointer -DMISSING_SYSCALL_NAMES
LDFLAGS = -shared -s -T libcdll.lds --out-implib libc.dll.a --image-base 0
#LDFLAGS+= --output-def libc.orig.def
ARFLAGS = crs
@ -15,29 +16,20 @@ LIBC_INCLUDES = $(LIBC_TOPDIR)/include
NAME:= libc
DEFINES:= -D_IEEE_LIBM -DHAVE_RENAME -DBUILD_LIBC
DEFINES:= -D_IEEE_LIBM -DHAVE_RENAME -DBUILD_LIBC -DPACKAGE_NAME=\"newlib\"
DEFINES+= -DPACKAGE_TARNAME=\"newlib\" -DPACKAGE_VERSION=\"2.4.0\"
SEFINES+= -DPACKAGE_STRING=\"newlib\ 2.4.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\"
INCLUDES:= -I $(LIBC_INCLUDES)
LIBPATH:= -L$(SDK_DIR)/lib -L/home/autobuild/tools/win32/mingw32/lib
STATIC_SRCS:= \
crt/start.S \
crt/crt1.c \
crt/crt2.c \
crt/chkstk.S \
crt/exit.S
LIBCRT_SRCS:= \
crt/start.S \
crt/crt3.c \
crt/chkstk.S \
crt/pseudo-reloc.c \
pe/crtloader.c
LIBDLL_SRCS:= \
crt/dllstart.c \
crt/chkstk.S \
crt/exit.S \
crt/pseudo-reloc.c \
crt/setjmp.S
@ -47,7 +39,6 @@ LIBCDLL_SRCS:= \
crt/crtdll.c \
crt/crt2.c \
crt/pseudo-reloc.c \
crt/chkstk.S \
crt/exit.S \
pe/loader.c
@ -55,11 +46,10 @@ CORE_SRCS:= \
argz/buf_findstr.c \
argz/envz_get.c \
crt/console.asm \
crt/emutls.c \
crt/thread.S \
crt/tls.S \
crt/setjmp.S \
crt/cpu_features.c \
crt/tls.c \
ctype/ctype_.c \
ctype/isascii.c \
ctype/isblank.c \
@ -173,14 +163,22 @@ STDLIB_SRCS= \
atof.c \
atoi.c \
atol.c \
cxa_atexit.c \
cxa_finalize.c \
div.c \
dtoa.c \
dtoastub.c \
efgcvt.c \
ecvtbuf.c \
eprintf.c \
erand48.c \
exit.c \
gdtoa-gethex.c \
gdtoa-hexnan.c \
getenv.c \
getenv_r.c \
itoa.c \
labs.c \
mprec.c \
mbtowc.c \
mbtowc_r.c \
@ -189,7 +187,7 @@ STDLIB_SRCS= \
calloc.c \
malloc.c \
mallocr.c \
rand.c \
rand.c \
rand_r.c \
rand48.c \
realloc.c \
@ -206,6 +204,7 @@ STDLIB_SRCS= \
strtoull.c \
strtoull_r.c \
system.c \
utoa.c \
wcrtomb.c \
wctomb_r.c
@ -241,56 +240,97 @@ STRING_SRCS= memcpy.c \
strtok.c \
strtok_r.c \
strupr.c \
strxfrm.c \
strcspn.c \
strspn.c \
strcpy.c \
u_strerr.c
STDIO_SRCS= \
asiprintf.c \
asniprintf.c \
asnprintf.c \
asprintf.c \
clearerr.c \
clearerr_u.c \
diprintf.c \
dprintf.c \
printf.c \
putchar.c \
fgetc.c \
fgets.c \
fopen.c \
fclose.c \
fcloseall.c \
fdopen.c \
feof.c \
feof_u.c \
ferror.c \
ferror_u.c \
fflush.c \
flags.c \
fflush_u.c \
fgetc.c \
fgetc_u.c \
fgetpos.c \
fgets.c \
fgets_u.c \
fileno.c \
fileno_u.c \
findfp.c \
fiprintf.c \
fiscanf.c \
flags.c \
fmemopen.c \
fopen.c \
fopencookie.c \
fprintf.c \
fpurge.c \
fputc.c \
fputc_u.c \
fputs.c \
fputs_u.c \
fputwc.c \
fsetpos.c \
funopen.c \
fread.c \
fread_u.c \
freopen.c \
fscanf.c \
fseek.c \
fseeko.c \
fsetlocking.c \
ftell.c \
ftello.c \
fwrite.c \
fvwrite.c \
fwalk.c \
fwide.c \
fwrite.c \
fwrite_u.c \
getc.c \
getc_u.c \
getchar.c \
getchar_u.c \
getdelim.c \
getline.c \
gets.c \
iprintf.c \
iscanf.c \
makebuf.c \
mbstowcs.c \
mktemp.c \
open_memstream.c \
perror.c \
printf.c \
putc.c \
putc_u.c \
putchar.c \
putchar_u.c \
puts.c \
refill.c \
remove.c \
rename.c \
rewind.c \
rget.c \
scanf.c \
sccl.c \
setbuf.c \
setbuffer.c \
setlinebuf.c \
setvbuf.c \
siprintf.c \
siscanf.c \
@ -299,15 +339,24 @@ STDIO_SRCS= \
sprintf.c \
sscanf.c \
stdio.c \
stdio_ext.c \
tmpfile.c \
tmpnam.c \
ungetc.c \
vasiprintf.c \
vasniprintf.c \
vasnprintf.c \
vdprintf.c \
vasprintf.c \
vdiprintf.c \
vdprintf.c \
viprintf.c \
viscanf.c \
vprintf.c \
vscanf.c \
vsiprintf.c \
vsiscanf.c \
vsprintf.c \
vsniprintf.c \
vsnprintf.c \
vsscanf.c \
wsetup.c \
@ -412,7 +461,7 @@ LIB_OBJS+= \
shared: $(NAME).dll libapp.a libdll.a
shared: $(NAME).dll libdll.a
$(NAME).dll: $(LIB_OBJS) $(SRC_DEP) Makefile
@ -421,38 +470,50 @@ $(NAME).dll: $(LIB_OBJS) $(SRC_DEP) Makefile
#sed -f cmd2.sed libc.def > mem
#sed -f newlib.sed mem > libc.inc
install: libc.dll libc.dll.a libapp.a libdll.a
install: libc.dll libc.dll.a libdll.a
mv -f libc.dll $(SDK_DIR)/bin
mv -f libc.dll.a $(SDK_DIR)/lib
mv -f libapp.a $(SDK_DIR)/lib
mv -f libdll.a $(SDK_DIR)/lib
libapp.a: $(LIBCRT_OBJS) Makefile
$(AR) $(ARFLAGS) libapp.a $(LIBCRT_OBJS)
mv -f libc.dll.a $(INSTALLDIR)
mv -f libdll.a $(INSTALLDIR)
libdll.a: $(LIBDLL_OBJS) Makefile
$(AR) $(ARFLAGS) libdll.a $(LIBDLL_OBJS)
static: $(NAME).a
$(NAME).a: $(LIB_OBJS) $(SRC_DEP) Makefile
$(AR) $(ARFLAGS) $(NAME).a $(LIB_OBJS)
mv -f libc.a $(INSTALLDIR)
crt/crt1.o: crt/crt1.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -fno-delete-null-pointer-checks crt/crt1.c -o $@
crt/crtdll.o: crt/crtdll.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -fno-delete-null-pointer-checks crt/crtdll.c -o $@
stdio/vfprintf.o: stdio/vfprintf.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -fshort-enums -DFLOATING_POINT -c stdio/vfprintf.c -o $@
pe/loader.o: pe/loader.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -fno-delete-null-pointer-checks pe/loader.c -o $@
stdio/vfiprintf.o: stdio/vfprintf.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -fshort-enums -DINTEGER_ONLY -c stdio/vfprintf.c -o $@
stdio/svfprintf.o: stdio/vfprintf.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -fshort-enums -DSTRING_ONLY -c stdio/vfprintf.c -o $@
reent/renamer.o: reent/renamer.c
$(CC) $(CFLAGS) $(DEFINES) -D_COMPILING_NEWLIB $(INCLUDES) reent/renamer.c -o $@
stdio/svfiprintf.o: stdio/vfprintf.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -fshort-enums -DINTEGER_ONLY -DSTRING_ONLY -c stdio/vfprintf.c -o $@
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -fshort-enums -DINTEGER_ONLY -DSTRING_ONLY stdio/vfprintf.c -o $@
stdio/svfprintf.o: stdio/vfprintf.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -fshort-enums -DSTRING_ONLY stdio/vfprintf.c -o $@
stdio/vfiprintf.o: stdio/vfprintf.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -fshort-enums -DINTEGER_ONLY stdio/vfprintf.c -o $@
stdio/vfprintf.o: stdio/vfprintf.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -fshort-enums stdio/vfprintf.c -o $@
stdio/svfiscanf.o: stdio/vfscanf.c
$(CC) $(CFLAGS) $(DEFINES) -DINTEGER_ONLY -DSTRING_ONLY $(INCLUDES) stdio/vfscanf.c -o $@
stdio/svscanf.o: stdio/vfscanf.c
$(CC) $(CFLAGS) $(DEFINES) -DSTRING_ONLY $(INCLUDES) stdio/vfscanf.c -o $@
stdio/vfscanf.o: stdio/vfscanf.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) stdio/vfscanf.c -o $@
@ -460,12 +521,8 @@ stdio/vfscanf.o: stdio/vfscanf.c
stdio/vfiscanf.o: stdio/vfscanf.c
$(CC) $(CFLAGS) $(DEFINES) -DINTEGER_ONLY $(INCLUDES) stdio/vfscanf.c -o $@
stdio/svscanf.o: stdio/vfscanf.c
$(CC) $(CFLAGS) $(DEFINES) -DSTRING_ONLY $(INCLUDES) stdio/vfscanf.c -o $@
stdio/svfiscanf.o: stdio/vfscanf.c
$(CC) $(CFLAGS) $(DEFINES) -DINTEGER_ONLY -DSTRING_ONLY $(INCLUDES) stdio/vfscanf.c -o $@

View File

@ -1,6 +1,6 @@
if tup.getconfig("NO_GCC") ~= "" or tup.getconfig("NO_FASM") ~= "" then return end
tup.include("../../../../../programs/use_gcc.lua")
CFLAGS = CFLAGS_OPTIMIZE_SPEED .. " -c -DBUILD_LIBC -DMISSING_SYSCALL_NAMES"
CFLAGS = CFLAGS_OPTIMIZE_SPEED .. " -c -fno-builtin -DBUILD_LIBC -DMISSING_SYSCALL_NAMES"
LDFLAGS = "-shared -s -T libcdll.lds --out-implib $(SDK_DIR)/lib/libc.dll.a --image-base 0"
-- LDFLAGS = LDFLAGS .. " --output-def libc.orig.def"
@ -21,13 +21,12 @@ if TOOLCHAIN_LIBPATH == "" then
end
end
LIBPATH = "-L$(SDK_DIR)/lib -L$(TOOLCHAIN_LIBPATH)"
STATIC_SRCS = {"crt/start.S", "crt/crt1.c", "crt/crt2.c", "crt/chkstk.S", "crt/exit.c"}
LIBCRT_SRCS = {"crt/start.S", "crt/crt3.c", "crt/chkstk.S", "crt/pseudo-reloc.c", "pe/crtloader.c"}
LIBDLL_SRCS = {"crt/dllstart.c", "crt/chkstk.S", "crt/exit.S", "crt/pseudo-reloc.c", "crt/setjmp.S"}
LIBCDLL_SRCS = {"crt/crtdll.c", "crt/crt2.c", "crt/pseudo-reloc.c", "crt/chkstk.S", "crt/exit.S", "pe/loader.c"}
STATIC_SRCS = {"crt/start.S", "crt/crt1.c", "crt/crt2.c", "crt/exit.S"}
LIBDLL_SRCS = {"crt/dllstart.c", "crt/exit.S", "crt/pseudo-reloc.c", "crt/setjmp.S"}
LIBCDLL_SRCS = {"crt/crt2.c", "crt/pseudo-reloc.c", "crt/exit.S"}
CORE_SRCS = {
"argz/buf_findstr.c", "argz/envz_get.c",
"crt/console.asm", "crt/emutls.c", "crt/thread.S", "crt/tls.S", "crt/setjmp.S", "crt/cpu_features.c",
"crt/console.asm", "crt/thread.S", "crt/cpu_features.c", "crt/tls.c",
"ctype/ctype_.c", "ctype/isascii.c", "ctype/isblank.c", "ctype/isalnum.c",
"ctype/isalpha.c", "ctype/iscntrl.c", "ctype/isdigit.c", "ctype/islower.c",
"ctype/isupper.c", "ctype/isprint.c", "ctype/ispunct.c", "ctype/isspace.c",
@ -43,7 +42,7 @@ CORE_SRCS = {
"reent/closer.c", "reent/fstatr.c", "reent/getreent.c", "reent/gettimeofdayr.c",
"reent/impure.c", "reent/init_reent.c", "reent/isattyr.c", "reent/linkr.c",
"reent/lseekr.c", "reent/mutex.c", "reent/openr.c", "reent/readr.c",
"reent/renamer.c", "reent/statr.c", "reent/timesr.c", "reent/unlinkr.c",
"reent/statr.c", "reent/timesr.c", "reent/unlinkr.c",
"reent/writer.c",
"search/qsort.c", "search/bsearch.c",
"signal/signal.c",
@ -58,39 +57,214 @@ CORE_SRCS = {
"time/timelocal.c", "time/tzlock.c", "time/tzset.c", "time/tzset_r.c", "time/tzvars.c"
}
STDLIB_SRCS = {
"__atexit.c", "__call_atexit.c", "abort.c", "abs.c", "assert.c", "atexit.c",
"atof.c", "atoi.c", "atol.c", "div.c", "dtoa.c", "dtoastub.c", "exit.c",
"gdtoa-gethex.c", "gdtoa-hexnan.c", "getenv.c", "getenv_r.c","mprec.c", "mbtowc.c",
"mbtowc_r.c", "mbrtowc.c", "mlock.c", "calloc.c", "malloc.c", "mallocr.c",
"rand.c", "rand_r.c", "rand48.c", "realloc.c", "seed48.c", "srand48.c",
"strtod.c", "strtodg.c", "strtol.c", "strtold.c", "strtoll.c", "strtoll_r.c",
"strtorx.c","strtoul.c", "strtoull.c", "strtoull_r.c", "system.c", "wcrtomb.c",
"__atexit.c",
"__call_atexit.c",
"abort.c",
"abs.c",
"assert.c",
"atexit.c",
"atof.c",
"atoi.c",
"atol.c",
"cxa_atexit.c",
"cxa_finalize.c",
"div.c",
"dtoa.c",
"dtoastub.c",
"efgcvt.c",
"ecvtbuf.c",
"eprintf.c",
"erand48.c",
"exit.c",
"gdtoa-gethex.c",
"gdtoa-hexnan.c",
"getenv.c",
"getenv_r.c",
"itoa.c",
"labs.c",
"mprec.c",
"mbtowc.c",
"mbtowc_r.c",
"mbrtowc.c",
"mlock.c",
"calloc.c",
"malloc.c",
"mallocr.c",
"rand.c",
"rand_r.c",
"rand48.c",
"realloc.c",
"seed48.c",
"srand48.c",
"strtod.c",
"strtodg.c",
"strtol.c",
"strtold.c",
"strtoll.c",
"strtoll_r.c",
"strtorx.c",
"strtoul.c",
"strtoull.c",
"strtoull_r.c",
"system.c",
"utoa.c",
"wcrtomb.c",
"wctomb_r.c"
}
STRING_SRCS = {
"memcpy.c", "memcmp.c", "memmove.c", "memset.c", "memchr.c", "stpcpy.c",
"stpncpy.c", "strcat.c", "strchr.c", "strcmp.c", "strcoll.c", "strcasecmp.c",
"strncasecmp.c", "strncat.c", "strncmp.c", "strncpy.c", "strndup.c",
"strndup_r.c", "strnlen.c", "strcasestr.c", "strdup.c", "strdup_r.c",
"strerror.c", "strlen.c", "strrchr.c", "strpbrk.c", "strsep.c", "strstr.c",
"strtok.c", "strtok_r.c", "strupr.c", "strcspn.c", "strspn.c", "strcpy.c",
"memcpy.c",
"memcmp.c",
"memmove.c",
"memset.c",
"memchr.c",
"stpcpy.c",
"stpncpy.c",
"strcat.c",
"strchr.c",
"strcmp.c",
"strcoll.c",
"strcasecmp.c",
"strncasecmp.c",
"strncat.c",
"strncmp.c",
"strncpy.c",
"strndup.c",
"strndup_r.c",
"strnlen.c",
"strcasestr.c",
"strdup.c",
"strdup_r.c",
"strerror.c",
"strlen.c",
"strrchr.c",
"strpbrk.c",
"strsep.c",
"strstr.c",
"strtok.c",
"strtok_r.c",
"strupr.c",
"strxfrm.c",
"strcspn.c",
"strspn.c",
"strcpy.c",
"u_strerr.c"
}
STDIO_SRCS = {
"clearerr.c", "diprintf.c", "dprintf.c", "printf.c", "putchar.c", "fgetc.c",
"fgets.c", "fopen.c", "fclose.c", "fdopen.c", "fflush.c", "flags.c",
"fileno.c", "findfp.c", "fiprintf.c", "fiscanf.c", "fprintf.c", "fputc.c",
"fputs.c", "fputwc.c", "fread.c", "freopen.c", "fscanf.c", "fseek.c", "fseeko.c",
"ftell.c", "ftello.c", "fwrite.c", "fvwrite.c", "fwalk.c", "makebuf.c",
"mbstowcs.c", "mktemp.c", "perror.c", "putc.c", "puts.c", "refill.c", "remove.c",
"rename.c", "rewind.c", "rget.c", "sccl.c", "setvbuf.c", "siprintf.c",
"siscanf.c", "sniprintf.c", "snprintf.c", "sprintf.c", "sscanf.c", "stdio.c",
"tmpfile.c", "tmpnam.c", "ungetc.c", "vasniprintf.c", "vasnprintf.c",
"vdprintf.c", "vdiprintf.c", "vscanf.c", "vsprintf.c", "vsnprintf.c",
"vsscanf.c", "wsetup.c", "wbuf.c"
"asiprintf.c",
"asniprintf.c",
"asnprintf.c",
"asprintf.c",
"clearerr.c",
"diprintf.c",
"dprintf.c",
"fclose.c",
"fcloseall.c",
"fdopen.c",
"feof.c",
"feof_u.c",
"ferror.c",
"ferror_u.c",
"fflush.c",
"fflush_u.c",
"fgetc.c",
"fgetc_u.c",
"fgetpos.c",
"fgets.c",
"fgets_u.c",
"fileno.c",
"fileno_u.c",
"findfp.c",
"fiprintf.c",
"fiscanf.c",
"flags.c",
"fmemopen.c",
"fopen.c",
"fopencookie.c",
"fprintf.c",
"fpurge.c",
"fputc.c",
"fputc_u.c",
"fputs.c",
"fputs_u.c",
"fputwc.c",
"fsetpos.c",
"fread.c",
"fread_u.c",
"freopen.c",
"fscanf.c",
"fseek.c",
"fseeko.c",
"fsetlocking.c",
"ftell.c",
"ftello.c",
"fvwrite.c",
"fwalk.c",
"fwide.c",
"fwrite.c",
"fwrite_u.c",
"getc.c",
"getc_u.c",
"getchar.c",
"getchar_u.c",
"getdelim.c",
"getline.c",
"gets.c",
"iprintf.c",
"iscanf.c",
"makebuf.c",
"mbstowcs.c",
"mktemp.c",
"open_memstream.c",
"perror.c",
"printf.c",
"putc.c",
"putc_u.c",
"putchar.c",
"putchar_u.c",
"puts.c",
"refill.c",
"remove.c",
"rename.c",
"rewind.c",
"rget.c",
"scanf.c",
"sccl.c",
"setbuf.c",
"setbuffer.c",
"setlinebuf.c",
"setvbuf.c",
"siprintf.c",
"siscanf.c",
"sniprintf.c",
"snprintf.c",
"sprintf.c",
"sscanf.c",
"stdio.c",
"stdio_ext.c",
"tmpfile.c",
"tmpnam.c",
"ungetc.c",
"vasiprintf.c",
"vasniprintf.c",
"vasnprintf.c",
"vasprintf.c",
"vdiprintf.c",
"vdprintf.c",
"viprintf.c",
"viscanf.c",
"vprintf.c",
"vscanf.c",
"vsiprintf.c",
"vsiscanf.c",
"vsprintf.c",
"vsniprintf.c",
"vsnprintf.c",
"vsscanf.c",
"wsetup.c",
"wbuf.c"
}
}
MATH_SRCS = {
"e_acos.c", "e_acosh.c", "e_asin.c", "e_atan2.c", "e_atanh.c", "e_cosh.c", "e_exp.c", "e_fmod.c",
@ -162,11 +336,15 @@ function compile(list)
end
LIB_OBJS = compile(LIB_SRCS)
LIBCRT_OBJS = compile(LIBCRT_SRCS)
LIB_OBJS += tup.rule("crt/crtdll.c", "kos32-gcc $(CFLAGS) $(DEFINES) $(INCLUDES) -fno-delete-null-pointer-checks -c crt/crtdll.c -o crt/crtdll.o")
LIB_OBJS += tup.rule("pe/loader.c", "kos32-gcc $(CFLAGS) $(DEFINES) $(INCLUDES) -fno-delete-null-pointer-checks -c pe/loader.c -o pe/loader.o")
LIB_OBJS += tup.rule("reent/renamer.c", "kos32-gcc $(CFLAGS) $(DEFINES) $(INCLUDES) -D_COMPILING_NEWLIB -c reent/renamer.c -o reent/renamer.o")
LIBDLL_OBJS = compile(LIBDLL_SRCS)
vfprintf_extra_objs = {
{"-DFLOATING_POINT", "stdio/vfprintf.o"},
{"", "stdio/vfprintf.o"},
{"-DINTEGER_ONLY", "stdio/vfiprintf.o"},
{"-DSTRING_ONLY", "stdio/svfprintf.o"},
{"-DINTEGER_ONLY -DSTRING_ONLY", "stdio/svfiprintf.o"},
@ -182,10 +360,9 @@ vfscanf_extra_objs = {
{"-DINTEGER_ONLY -DSTRING_ONLY", "stdio/svfiscanf.o"},
}
for i,v in ipairs(vfscanf_extra_objs) do
LIB_OBJS += tup.rule("stdio/vfscanf.c", "kos32-gcc $(CFLAGS) $(DEFINES) $(INCLUDES) -fshort-enums " .. v[1] .. " -c %f -o %o", v[2])
LIB_OBJS += tup.rule("stdio/vfscanf.c", "kos32-gcc $(CFLAGS) $(DEFINES) $(INCLUDES) " .. v[1] .. " -c %f -o %o", v[2])
end
tup.rule(LIB_OBJS, "kos32-ld " .. LDFLAGS .. " " .. LIBPATH .. " -o %o %f -lgcc --version-script libc.ver " .. tup.getconfig("KPACK_CMD"),
{SDK_DIR .. "/bin/libc.dll", extra_outputs = {SDK_DIR .. "/lib/libc.dll.a", SDK_DIR .. "/lib/<libc.dll.a>"}})
tup.rule(LIBCRT_OBJS, "kos32-ar rcs %o %f", {SDK_DIR .. "/lib/libapp.a", extra_outputs = {SDK_DIR .. "/lib/<libapp.a>"}})
tup.rule(LIBDLL_OBJS, "kos32-ar rcs %o %f", {SDK_DIR .. "/lib/libdll.a", extra_outputs = {SDK_DIR .. "/lib/<libdll.a>"}})

View File

@ -85,7 +85,7 @@ SECTIONS
*(SORT(.data$*))
*(.jcr)
__CRT_MT = .;
LONG(0);
LONG(1);
PROVIDE ( __data_end__ = .) ;
*(.data_cygwin_nocopy)
___iend = . ;

View File

@ -10,6 +10,7 @@ public _con_get_flags
public _con_set_flags@4
public _con_cls
public _con_write_string@8
public _con_getch2@0
section '.text' align 16
@ -164,6 +165,9 @@ align 4
_con_write_string@8:
jmp [con_write_string]
_con_getch2@0:
jmp [con_getch2]
_con_get_flags:
_con_set_flags@4:
_con_cls:

View File

@ -12,12 +12,7 @@
/* Hide the declaration of _fmode with dllimport attribute in stdlib.h to
avoid problems with older GCC. */
#include <newlib.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sys/kos_io.h>
struct app_hdr
{
@ -32,9 +27,12 @@ struct app_hdr
int __subsystem__;
};
void __init_conio();
void __fini_conio();
extern void init_reent();
extern void init_stdio();
extern void __init_conio();
extern void __fini_conio();
extern void tls_init(void);
extern int main (int, char **, char **);
/* NOTE: The code for initializing the _argv, _argc, and environ variables
@ -46,8 +44,6 @@ extern int main (int, char **, char **);
char* __appenv;
int __appenv_size;
extern char _tls_map[128];
char * __libc_getenv(const char *name)
{
return NULL;
@ -168,7 +164,7 @@ static int split_cmdline(char *cmdline, char **argv)
};
void __attribute__((noreturn))
__crt_startup (void)
__libc_init (void)
{
struct app_hdr *header = NULL;
int retval = 0;
@ -176,8 +172,7 @@ __crt_startup (void)
char **argv;
int argc;
memset(_tls_map, 0xFF, 32*4);
_tls_map[0] = 0xE0;
tls_init();
init_reent();
init_stdio();

View File

@ -12,7 +12,7 @@ __thread_startup (int (*entry)(void*), void *param,
__asm__ __volatile__( // save stack limits
"movl %0, %%fs:8 \n\t" // use TLS
"movl %1, %%fs:12 \n\t"
"movl %1, %%fs:12 \n\t"
::"r"(stacklow), "r"(stackhigh));
init_reent(); // initialize thread reentry structure

View File

@ -35,19 +35,21 @@ struct app_hdr
int (*main)(int argc, char **argv, char **envp);
};
void _pei386_runtime_relocator (void);
void init_loader(void *libc_image);
void init_reent();
void __init_conio();
void __fini_conio();
int link_app();
void* get_entry_point(void *raw);
int (*entry)(int, char **, char **);
extern void _pei386_runtime_relocator (void);
extern void init_loader(void *libc_image);
extern void init_reent(void);
extern void init_stdio(void);
extern void __init_conio(void);
extern void __fini_conio(void);
extern int link_app(void);
extern void* get_entry_point(void *raw);
extern void tls_init(void);
char* __appenv;
int __appenv_size;
extern char _tls_map[128];
char * __libc_getenv(const char *name)
{
@ -168,10 +170,10 @@ static int split_cmdline(char *cmdline, char **argv)
return argc;
};
void __attribute__((noreturn))
libc_crt_startup (void *libc_base)
__attribute__((noreturn))
void libc_crt_startup (void *libc_base)
{
struct app_hdr *header = NULL;
struct app_hdr *header = NULL;
int retval = 0;
char **argv;
@ -179,16 +181,13 @@ libc_crt_startup (void *libc_base)
_pei386_runtime_relocator();
memset(_tls_map, 0xFF, 32*4);
_tls_map[0] = 0xE0;
tls_init();
init_reent();
init_stdio();
if(header->__subsystem__ == 3)
__init_conio();
__do_global_ctors();
// __appenv = load_file("/sys/system.env", &__appenv_size);
init_loader(libc_base);

View File

@ -1,7 +1,7 @@
.section .init
.global __start
.global __crt_start
#tls:0 pid process id
#tls:4 tid reserved for thread slot
@ -10,7 +10,7 @@
#tls:16 reseved for libc
.align 4
__start:
__crt_start:
movl $68, %eax
movl $12, %ebx
lea __size_of_stack_reserve__, %ecx
@ -38,7 +38,7 @@ __start:
addl $1024, %esp
jmp ___crt_startup
jmp ___libc_init
1:
int3 #trap to debugger

View File

@ -0,0 +1,69 @@
#include <libsync.h>
static int tls_map[128/4];
static int *tls_scan_start = tls_map;
static mutex_t tls_mutex;
void tls_init()
{
int i;
mutex_init(&tls_mutex);
tls_map[0] = 0xE0;
for(i = 1; i < 128/4; i++)
tls_map[i] = -1;
};
int tls_free(unsigned int key)
{
int retval = -1;
if(key < 4096)
{
mutex_lock(&tls_mutex);
__asm__ volatile(
"shrl $2, %0 \n\t"
"btsl %0, (%1) \n\t"
::"r"(key),"d"(tls_map)
:"cc","memory");
tls_scan_start = &tls_map[key>>5];
mutex_unlock(&tls_mutex);
retval = 0;
}
return retval;
};
unsigned int tls_alloc()
{
unsigned int key;
mutex_lock(&tls_mutex);
__asm__ volatile(
"1: \n\t"
"bsfl (%1), %0 \n\t"
"jnz 2f \n\t"
"add $4, %1 \n\t"
"cmpl $128+_tls_map, %1 \n\t"
"jb 1b \n\t"
"xorl %0, %0 \n\t"
"notl %0 \n\t"
"jmp 3f \n\t"
"2: \n\t"
"btrl %0, (%1) \n\t"
"subl $_tls_map, %1 \n\t"
"leal (%0, %1, 8), %%eax \n\t"
"shll $2, %0 \n\t"
"3:"
:"=r"(key),"=d"(tls_scan_start)
:"d"(tls_scan_start)
:"cc","memory");
mutex_unlock(&tls_mutex);
return key;
}

View File

@ -0,0 +1,12 @@
/* _newlib_version.h. Generated from _newlib_version.hin by configure. */
/* Version macros for internal and downstream use. */
#ifndef _NEWLIB_VERSION_H__
#define _NEWLIB_VERSION_H__ 1
#define _NEWLIB_VERSION "2.4.0"
#define __NEWLIB__ 2
#define __NEWLIB_MINOR__ 4
#define __NEWLIB_PATCHLEVEL__ 0
#endif /* !_NEWLIB_VERSION_H__ */

View File

@ -108,18 +108,46 @@ long double cimagl(long double complex);
/* 7.3.9.3 The conj functions */
double complex conj(double complex);
float complex conjf(float complex);
/*long double complex conjl(long double complex); */
/* 7.3.9.4 The cproj functions */
double complex cproj(double complex);
float complex cprojf(float complex);
/*long double complex cprojl(long double complex); */
/* 7.3.9.5 The creal functions */
double creal(double complex);
float crealf(float complex);
long double creall(long double complex);
#if __GNU_VISIBLE
double complex clog10(double complex);
float complex clog10f(float complex);
#endif
#if defined(__CYGWIN__)
long double complex cacosl(long double complex);
long double complex casinl(long double complex);
long double complex catanl(long double complex);
long double complex ccosl(long double complex);
long double complex csinl(long double complex);
long double complex ctanl(long double complex);
long double complex cacoshl(long double complex);
long double complex casinhl(long double complex);
long double complex catanhl(long double complex);
long double complex ccoshl(long double complex);
long double complex csinhl(long double complex);
long double complex ctanhl(long double complex);
long double complex cexpl(long double complex);
long double complex clogl(long double complex);
long double complex cpowl(long double complex, long double complex);
long double complex csqrtl(long double complex);
long double cargl(long double complex);
long double complex conjl(long double complex);
long double complex cprojl(long double complex);
#if __GNU_VISIBLE
long double complex clog10l(long double complex);
#endif
#endif /* __CYGWIN__ */
__END_DECLS
#endif /* ! _COMPLEX_H */

View File

@ -2,6 +2,7 @@
#define _CTYPE_H_
#include "_ansi.h"
#include <sys/cdefs.h>
_BEGIN_STD_C
@ -19,11 +20,11 @@ int _EXFUN(isxdigit,(int __c));
int _EXFUN(tolower, (int __c));
int _EXFUN(toupper, (int __c));
#if !defined(__STRICT_ANSI__) || defined(__cplusplus) || __STDC_VERSION__ >= 199901L
#if __ISO_C_VISIBLE >= 1999
int _EXFUN(isblank, (int __c));
#endif
#ifndef __STRICT_ANSI__
#if __MISC_VISIBLE || __XSI_VISIBLE
int _EXFUN(isascii, (int __c));
int _EXFUN(toascii, (int __c));
#define _tolower(__c) ((unsigned char)(__c) - 'A' + 'a')
@ -40,10 +41,9 @@ int _EXFUN(toascii, (int __c));
#define _B 0200
#ifndef _MB_CAPABLE
extern _CONST __IMPORT char *__ctype_ptr__;
#else
extern __IMPORT char *__ctype_ptr__;
_CONST
#endif
extern __IMPORT char *__ctype_ptr__;
#ifndef __cplusplus
/* These macros are intentionally written in a manner that will trigger
@ -69,8 +69,7 @@ extern __IMPORT char *__ctype_ptr__;
#define isgraph(__c) (__ctype_lookup(__c)&(_P|_U|_L|_N))
#define iscntrl(__c) (__ctype_lookup(__c)&_C)
#if defined(__GNUC__) && \
(!defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901L)
#if defined(__GNUC__) && __ISO_C_VISIBLE >= 1999
#define isblank(__c) \
__extension__ ({ __typeof__ (__c) __x = (__c); \
(__ctype_lookup(__x)&_B) || (int) (__x) == '\t';})
@ -99,13 +98,14 @@ extern __IMPORT char *__ctype_ptr__;
(void) __ctype_ptr__[__x]; (tolower) (__x);})
# endif /* _MB_EXTENDED_CHARSETS* */
# endif /* __GNUC__ */
#endif /* !__cplusplus */
#ifndef __STRICT_ANSI__
#if __MISC_VISIBLE || __XSI_VISIBLE
#define isascii(__c) ((unsigned)(__c)<=0177)
#define toascii(__c) ((__c)&0177)
#endif
#endif /* !__cplusplus */
/* For C++ backward-compatibility only. */
extern __IMPORT _CONST char _ctype_[];

View File

@ -3,9 +3,10 @@
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/cdefs.h>
#include <sys/dirent.h>
#if !defined(MAXNAMLEN) && !defined(_POSIX_SOURCE)
#if !defined(MAXNAMLEN) && __BSD_VISIBLE
#define MAXNAMLEN 1024
#endif

View File

@ -33,21 +33,21 @@
#ifndef _FNMATCH_H_
#define _FNMATCH_H_
#include <sys/cdefs.h>
#define FNM_NOMATCH 1 /* Match failed. */
#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */
#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */
#define FNM_PERIOD 0x04 /* Period must be matched by period. */
#if defined(_GNU_SOURCE) || !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
#if __GNU_VISIBLE
#define FNM_LEADING_DIR 0x08 /* Ignore /<tail> after Imatch. */
#define FNM_CASEFOLD 0x10 /* Case insensitive search. */
#define FNM_IGNORECASE FNM_CASEFOLD
#define FNM_FILE_NAME FNM_PATHNAME
#endif
#include <sys/cdefs.h>
__BEGIN_DECLS
int fnmatch(const char *, const char *, int);
__END_DECLS

View File

@ -49,7 +49,7 @@
#include <cygwin/grp.h>
#endif
#if !defined(_POSIX_SOURCE) && !defined(_XOPEN_SOURCE)
#if __BSD_VISIBLE
#define _PATH_GROUP "/etc/group"
#endif
@ -67,25 +67,20 @@ extern "C" {
#ifndef __INSIDE_CYGWIN__
struct group *getgrgid (gid_t);
struct group *getgrnam (const char *);
#if __MISC_VISIBLE || __POSIX_VISIBLE
int getgrnam_r (const char *, struct group *,
char *, size_t, struct group **);
int getgrgid_r (gid_t, struct group *,
char *, size_t, struct group **);
#ifndef _POSIX_SOURCE
#endif /* __MISC_VISIBLE || __POSIX_VISIBLE */
#if __MISC_VISIBLE || __XSI_VISIBLE >= 4
struct group *getgrent (void);
void setgrent (void);
void endgrent (void);
#ifndef __CYGWIN__
void setgrfile (const char *);
#endif /* !__CYGWIN__ */
#ifndef _XOPEN_SOURCE
#ifndef __CYGWIN__
char *group_from_gid (gid_t, int);
int setgroupent (int);
#endif /* !__CYGWIN__ */
#endif /* __MISC_VISIBLE || __XSI_VISIBLE >= 4 */
#if __BSD_VISIBLE
int initgroups (const char *, gid_t);
#endif /* !_XOPEN_SOURCE */
#endif /* !_POSIX_SOURCE */
#endif /* __BSD_VISIBLE */
#endif /* !__INSIDE_CYGWIN__ */
#ifdef __cplusplus

View File

@ -1,103 +0,0 @@
/* Threads compatibility routines for libgcc2. */
/* Compile this one with gcc. */
/* Copyright (C) 1997, 1998, 2004, 2008, 2009 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
#ifndef GCC_GTHR_H
#define GCC_GTHR_H
typedef unsigned int __gthread_key_t;
typedef struct {
volatile int done;
int started;
} __gthread_once_t;
typedef struct {
volatile int counter;
} __gthread_mutex_t;
void *tls_alloc(void);
static int __gthread_mutex_lock (__gthread_mutex_t *mutex)
{
__mutex_lock(&mutex->counter);
return 0;
};
static int __gthread_mutex_unlock (__gthread_mutex_t *mutex)
{
mutex->counter = 0;
return 0;
};
static inline int __gthread_key_create (__gthread_key_t *__key,
void (*__dtor) (void *) __attribute__((unused)))
{
int __status = 0;
void *__tls_index = tls_alloc();
if (__tls_index != NULL)
{
*__key = (unsigned int)__tls_index;
#ifdef MINGW32_SUPPORTS_MT_EH /* FIXME */
/* Mingw runtime will run the dtors in reverse order for each thread
when the thread exits. */
// __status = __mingwthr_key_dtor (*__key, __dtor);
#endif
}
else
__status = (int) ENOMEM;
return __status;
}
static inline void *
__gthread_getspecific (__gthread_key_t __key)
{
void *val;
__asm__ __volatile__(
"movl %%fs:(%1), %0"
:"=r"(val)
:"r"(__key));
return val;
};
static inline int
__gthread_setspecific (__gthread_key_t __key, const void *__ptr)
{
if(!(__key & 3))
{
__asm__ __volatile__(
"movl %0, %%fs:(%1)"
::"r"(__ptr),"r"(__key));
return 0;
}
else return EINVAL;
}
#endif

View File

@ -270,22 +270,17 @@ int _EXFUN(finitef, (float));
#define __IEEE_DBL_NAN_EXP 0x7ff
#define __IEEE_FLT_NAN_EXP 0xff
#ifndef __ieeefp_isnanf
#define __ieeefp_isnanf(x) (((*(long *)&(x) & 0x7f800000L)==0x7f800000L) && \
((*(long *)&(x) & 0x007fffffL)!=0000000000L))
#endif
#ifdef __ieeefp_isnanf
#define isnanf(x) __ieeefp_isnanf(x)
#ifndef __ieeefp_isinff
#define __ieeefp_isinff(x) (((*(long *)&(x) & 0x7f800000L)==0x7f800000L) && \
((*(long *)&(x) & 0x007fffffL)==0000000000L))
#endif
#ifdef __ieeefp_isinff
#define isinff(x) __ieeefp_isinff(x)
#ifndef __ieeefp_finitef
#define __ieeefp_finitef(x) (((*(long *)&(x) & 0x7f800000L)!=0x7f800000L))
#endif
#ifdef __ieeefp_finitef
#define finitef(x) __ieeefp_finitef(x)
#endif
#ifdef _DOUBLE_IS_32BITS
#undef __IEEE_DBL_EXPBIAS

View File

@ -65,11 +65,11 @@ void end_draw(void)
"int $0x40" ::"a"(12),"b"(2));
};
static inline void
static inline void
put_image(uint16_t x_coord, uint16_t y_coord,
uint16_t size_x, uint16_t size_y, void *img)
{
__asm__ __volatile__("int $0x40"
__asm__ __volatile__("int $0x40"
::"a"(25),
"b"(img),
"c"(size_x<<16 | size_y),
@ -237,7 +237,7 @@ static inline uint32_t set_wanted_events_mask(uint32_t event_mask)
__asm__ __volatile__(
"int $0x40"
:"=a"(old_event_mask)
:"a"(40));
:"a"(40),"b"(event_mask));
return old_event_mask;
};
@ -273,7 +273,7 @@ uint32_t wait_for_event(uint32_t time)
return val;
};
static inline uint32_t check_os_event()
static inline uint32_t check_os_event(void)
{
uint32_t val;
__asm__ __volatile__(
@ -283,7 +283,7 @@ static inline uint32_t check_os_event()
return val;
};
static inline uint32_t get_os_event()
static inline uint32_t get_os_event(void)
{
uint32_t val;
__asm__ __volatile__(
@ -328,7 +328,7 @@ oskey_t get_key(void)
}
static inline
uint32_t get_os_button()
uint32_t get_os_button(void)
{
uint32_t val;
__asm__ __volatile__(
@ -453,7 +453,7 @@ static inline ufile_t load_file(const char *path)
};
static inline ufile_t LoadFile(const char *path) __attribute__ ((alias ("load_file")));
static inline int GetScreenSize()
static inline int GetScreenSize(void)
{
int retval;
@ -514,6 +514,42 @@ static inline void Blit(void *bitmap, int dst_x, int dst_y,
::"a"(73),"b"(0),"c"(&bc.dstx));
};
#define TLS_KEY_PID 0
#define TLS_KEY_TID 4
#define TLS_KEY_LOW_STACK 8
#define TLS_KEY_HIGH_STACK 12
#define TLS_KEY_LIBC 16
unsigned int tls_alloc(void);
int tls_free(unsigned int key);
static inline int tls_set(unsigned int key, void *val)
{
int ret = -1;
if(key < 4096)
{
__asm__ __volatile__(
"movl %0, %%fs:(%1)"
::"r"(val),"r"(key));
ret = 0;
}
return ret;
};
static inline void *tls_get(unsigned int key)
{
void *val = (void*)-1;
if(key < 4096)
{
__asm__ __volatile__(
"movl %%fs:(%1), %0"
:"=r"(val)
:"r"(key));
};
return val;
}
int create_thread(int (*proc)(void *param), void *param, int stack_size);
void* load_library(const char *name);

View File

@ -2,6 +2,7 @@
# define _LIBC_LIMITS_H_ 1
#include <newlib.h>
#include <sys/cdefs.h>
# ifdef _MB_LEN_MAX
# define MB_LEN_MAX _MB_LEN_MAX
@ -96,8 +97,7 @@
# define __LONG_LONG_MAX__ 9223372036854775807LL
# endif
# if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
(defined(__cplusplus) && __cplusplus >= 201103L)
# if __ISO_C_VISIBLE >= 1999
/* Minimum and maximum values a `signed long long int' can hold. */
# undef LLONG_MIN
# define LLONG_MIN (-LLONG_MAX-1)
@ -109,7 +109,7 @@
# define ULLONG_MAX (LLONG_MAX * 2ULL + 1)
# endif
# if defined (__GNU_LIBRARY__) ? defined (__USE_GNU) : !defined (__STRICT_ANSI__)
# if __GNU_VISIBLE
/* Minimum and maximum values a `signed long long int' can hold. */
# undef LONG_LONG_MIN
# define LONG_LONG_MIN (-LONG_LONG_MAX-1)

View File

@ -1,100 +1,122 @@
#ifdef __sysvnecv70_target
double EXFUN(fast_sin,(double));
double EXFUN(fast_cos,(double));
double EXFUN(fast_tan,(double));
#ifndef _MACHFASTMATH_H
#define _MACHFASTMATH_H
double EXFUN(fast_asin,(double));
double EXFUN(fast_acos,(double));
double EXFUN(fast_atan,(double));
#if defined(__GNUC__) && __STDC__ - 0 > 0
double EXFUN(fast_sinh,(double));
double EXFUN(fast_cosh,(double));
double EXFUN(fast_tanh,(double));
#define __str1__(__x) #__x
#define __str2__(__x) __str1__(__x)
#define __U_L_PREFIX__ __str2__(__USER_LABEL_PREFIX__)
double EXFUN(fast_asinh,(double));
double EXFUN(fast_acosh,(double));
double EXFUN(fast_atanh,(double));
__extension__ double atan2(double, double)
__asm__(__U_L_PREFIX__ "_f_atan2");
__extension__ double exp(double)
__asm__(__U_L_PREFIX__ "_f_exp");
__extension__ double frexp(double, int*)
__asm__(__U_L_PREFIX__ "_f_frexp");
__extension__ double ldexp(double, int)
__asm__(__U_L_PREFIX__ "_f_ldexp");
__extension__ double log(double)
__asm__(__U_L_PREFIX__ "_f_log");
__extension__ double log10(double)
__asm__(__U_L_PREFIX__ "_f_log10");
__extension__ double pow(double, double)
__asm__(__U_L_PREFIX__ "_f_pow");
__extension__ double tan(double)
__asm__(__U_L_PREFIX__ "_f_tan");
double EXFUN(fast_abs,(double));
double EXFUN(fast_sqrt,(double));
double EXFUN(fast_exp2,(double));
double EXFUN(fast_exp10,(double));
double EXFUN(fast_expe,(double));
double EXFUN(fast_log10,(double));
double EXFUN(fast_log2,(double));
double EXFUN(fast_loge,(double));
#if !defined(__STRICT_ANSI__) || defined(__cplusplus) || __STDC_VERSION__ >= 199901L
#define sin(x) fast_sin(x)
#define cos(x) fast_cos(x)
#define tan(x) fast_tan(x)
#define asin(x) fast_asin(x)
#define acos(x) fast_acos(x)
#define atan(x) fast_atan(x)
#define sinh(x) fast_sinh(x)
#define cosh(x) fast_cosh(x)
#define tanh(x) fast_tanh(x)
#define asinh(x) fast_asinh(x)
#define acosh(x) fast_acosh(x)
#define atanh(x) fast_atanh(x)
#define abs(x) fast_abs(x)
#define sqrt(x) fast_sqrt(x)
#define exp2(x) fast_exp2(x)
#define exp10(x) fast_exp10(x)
#define expe(x) fast_expe(x)
#define log10(x) fast_log10(x)
#define log2(x) fast_log2(x)
#define loge(x) fast_loge(x)
#ifdef _HAVE_STDC
/* These functions are in assembler, they really do take floats. This
can only be used with a real ANSI compiler */
float EXFUN(fast_sinf,(float));
float EXFUN(fast_cosf,(float));
float EXFUN(fast_tanf,(float));
float EXFUN(fast_asinf,(float));
float EXFUN(fast_acosf,(float));
float EXFUN(fast_atanf,(float));
float EXFUN(fast_sinhf,(float));
float EXFUN(fast_coshf,(float));
float EXFUN(fast_tanhf,(float));
float EXFUN(fast_asinhf,(float));
float EXFUN(fast_acoshf,(float));
float EXFUN(fast_atanhf,(float));
float EXFUN(fast_absf,(float));
float EXFUN(fast_sqrtf,(float));
float EXFUN(fast_exp2f,(float));
float EXFUN(fast_exp10f,(float));
float EXFUN(fast_expef,(float));
float EXFUN(fast_log10f,(float));
float EXFUN(fast_log2f,(float));
float EXFUN(fast_logef,(float));
#define sinf(x) fast_sinf(x)
#define cosf(x) fast_cosf(x)
#define tanf(x) fast_tanf(x)
#define asinf(x) fast_asinf(x)
#define acosf(x) fast_acosf(x)
#define atanf(x) fast_atanf(x)
#define sinhf(x) fast_sinhf(x)
#define coshf(x) fast_coshf(x)
#define tanhf(x) fast_tanhf(x)
#define asinhf(x) fast_asinhf(x)
#define acoshf(x) fast_acoshf(x)
#define atanhf(x) fast_atanhf(x)
#define absf(x) fast_absf(x)
#define sqrtf(x) fast_sqrtf(x)
#define exp2f(x) fast_exp2f(x)
#define exp10f(x) fast_exp10f(x)
#define expef(x) fast_expef(x)
#define log10f(x) fast_log10f(x)
#define log2f(x) fast_log2f(x)
#define logef(x) fast_logef(x)
__extension__ float atan2f(float, float)
__asm__(__U_L_PREFIX__ "_f_atan2f");
__extension__ float expf(float)
__asm__(__U_L_PREFIX__ "_f_expf");
__extension__ float frexpf(float, int*)
__asm__(__U_L_PREFIX__ "_f_frexpf");
__extension__ float ldexpf(float, int)
__asm__(__U_L_PREFIX__ "_f_ldexpf");
__extension__ long long llrint(double)
__asm__(__U_L_PREFIX__ "_f_llrint");
__extension__ long long llrintf(float)
__asm__(__U_L_PREFIX__ "_f_llrintf");
__extension__ long long llrintl(long double)
__asm__(__U_L_PREFIX__ "_f_llrintl");
__extension__ float logf(float)
__asm__(__U_L_PREFIX__ "_f_logf");
__extension__ float log10f(float)
__asm__(__U_L_PREFIX__ "_f_log10f");
__extension__ long lrint(double)
__asm__(__U_L_PREFIX__ "_f_lrint");
__extension__ long lrintf(float)
__asm__(__U_L_PREFIX__ "_f_lrintf");
__extension__ long lrintl(long double)
__asm__(__U_L_PREFIX__ "_f_lrintl");
__extension__ float powf(float, float)
__asm__(__U_L_PREFIX__ "_f_powf");
__extension__ double rint(double)
__asm__(__U_L_PREFIX__ "_f_rint");
__extension__ float rintf(float)
__asm__(__U_L_PREFIX__ "_f_rintf");
__extension__ long double rintl(long double)
__asm__(__U_L_PREFIX__ "_f_rintl");
__extension__ float tanf(float)
__asm__(__U_L_PREFIX__ "_f_tanf");
#endif
/* Override the functions defined in math.h */
#endif /* __sysvnecv70_target */
#else
double EXFUN(_f_atan2,(double, double));
double EXFUN(_f_exp,(double));
double EXFUN(_f_frexp,(double, int*));
double EXFUN(_f_ldexp,(double, int));
double EXFUN(_f_log,(double));
double EXFUN(_f_log10,(double));
double EXFUN(_f_pow,(double, double));
#define atan2(__y,__x) _f_atan2((__y),(__x))
#define exp(__x) _f_exp(__x)
#define frexp(__x,__p) _f_frexp((__x),(__p))
#define ldexp(__x,__e) _f_ldexp((__x),(__e))
#define log(__x) _f_log(__x)
#define log10(__x) _f_log10(__x)
#define pow(__x,__y) _f_pow((__x),(__y))
#ifndef __STRICT_ANSI__
float EXFUN(_f_atan2f,(float, float));
float EXFUN(_f_expf,(float));
float EXFUN(_f_frexpf,(float, int*));
float EXFUN(_f_ldexpf,(float, int));
long long EXFUN(_f_llrint,(double));
long long EXFUN(_f_llrintf,(float));
long long EXFUN(_f_llrintl,(long double));
float EXFUN(_f_logf,(float));
float EXFUN(_f_log10f,(float));
long EXFUN(_f_lrint,(double));
long EXFUN(_f_lrintf,(float));
long EXFUN(_f_lrintl,(long double));
float EXFUN(_f_powf,(float, float));
float EXFUN(_f_rint,(double));
double EXFUN(_f_rintf,(float));
long double EXFUN(_f_rintl,(long double));
#define atan2f(__y,__x) _f_atan2f((__y),(__x))
#define expf(__x) _f_expf(__x)
#define frexpf(__x,__p) _f_frexpf((__x),(__p))
#define ldexpf(__x,__e) _f_ldexpf((__x),(__e))
#define llrint(__x) _f_llrint((__x))
#define llrintf(__x) _f_llrintf((__x))
#define llrintl(__x) _f_llrintl((__x))
#define logf(__x) _f_logf(__x)
#define log10f(__x) _f_log10f(__x)
#define lrint(__x) _f_lrint((__x))
#define lrintf(__x) _f_lrintf((__x))
#define lrintl(__x) _f_lrintl((__x))
#define powf(__x,y) _f_powf((__x),(__y))
#define rint(__x) _f_rint((__x))
#define rintf(__x) _f_rintf((__x))
#define rintl(__x) _f_rintl((__x))
#endif
#endif /* GCC */
#endif /* _MACHFASTMATH_H */

View File

@ -3,6 +3,7 @@
#define _MATH_H_
#include <sys/reent.h>
#include <sys/cdefs.h>
#include <machine/ieeefp.h>
#include "_ansi.h"
@ -136,9 +137,7 @@ extern double fmod _PARAMS((double, double));
#endif /* ! defined (__math_68881) */
#endif /* ! defined (_REENT_ONLY) */
#if !defined(__STRICT_ANSI__) || defined(__cplusplus) || \
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
#if __ISO_C_VISIBLE >= 1999
/* ISO C99 types and macros. */
/* FIXME: FLT_EVAL_METHOD should somehow be gotten from float.h (which is hard,
@ -205,35 +204,70 @@ extern int __fpclassifyd (double x);
extern int __signbitf (float x);
extern int __signbitd (double x);
#define fpclassify(__x) \
((sizeof(__x) == sizeof(float)) ? __fpclassifyf(__x) : \
__fpclassifyd(__x))
#ifndef isfinite
#define isfinite(__y) \
(__extension__ ({int __cy = fpclassify(__y); \
__cy != FP_INFINITE && __cy != FP_NAN;}))
#endif
/* Note: isinf and isnan were once functions in newlib that took double
* arguments. C99 specifies that these names are reserved for macros
* supporting multiple floating point types. Thus, they are
* now defined as macros. Implementations of the old functions
* taking double arguments still exist for compatibility purposes
* (prototypes for them are in <ieeefp.h>). */
#ifndef isinf
#define isinf(y) (fpclassify(y) == FP_INFINITE)
#if __GNUC_PREREQ (4, 4)
#define fpclassify(__x) (__builtin_fpclassify (FP_NAN, FP_INFINITE, \
FP_NORMAL, FP_SUBNORMAL, \
FP_ZERO, __x))
#ifndef isfinite
#define isfinite(__x) (__builtin_isfinite (__x))
#endif
#ifndef isinf
#define isinf(__x) (__builtin_isinf_sign (__x))
#endif
#ifndef isnan
#define isnan(__x) (__builtin_isnan (__x))
#endif
#define isnormal(__x) (__builtin_isnormal (__x))
#else
#define fpclassify(__x) \
((sizeof(__x) == sizeof(float)) ? __fpclassifyf(__x) : \
__fpclassifyd(__x))
#ifndef isfinite
#define isfinite(__y) \
(__extension__ ({int __cy = fpclassify(__y); \
__cy != FP_INFINITE && __cy != FP_NAN;}))
#endif
#ifndef isinf
#define isinf(__x) (fpclassify(__x) == FP_INFINITE)
#endif
#ifndef isnan
#define isnan(__x) (fpclassify(__x) == FP_NAN)
#endif
#define isnormal(__x) (fpclassify(__x) == FP_NORMAL)
#endif
#ifndef isnan
#define isnan(y) (fpclassify(y) == FP_NAN)
#endif
#define isnormal(y) (fpclassify(y) == FP_NORMAL)
#define signbit(__x) \
#if __GNUC_PREREQ (4, 0)
#if defined(_HAVE_LONG_DOUBLE)
#define signbit(__x) \
((sizeof(__x) == sizeof(float)) ? __builtin_signbitf(__x) : \
(sizeof(__x) == sizeof(double)) ? __builtin_signbit (__x) : \
__builtin_signbitl(__x))
#else
#define signbit(__x) \
((sizeof(__x) == sizeof(float)) ? __builtin_signbitf(__x) : \
__builtin_signbit (__x))
#endif
#else
#define signbit(__x) \
((sizeof(__x) == sizeof(float)) ? __signbitf(__x) : \
__signbitd(__x))
#endif
#if __GNUC_PREREQ (2, 97)
#define isgreater(__x,__y) (__builtin_isgreater (__x, __y))
#define isgreaterequal(__x,__y) (__builtin_isgreaterequal (__x, __y))
#define isless(__x,__y) (__builtin_isless (__x, __y))
#define islessequal(__x,__y) (__builtin_islessequal (__x, __y))
#define islessgreater(__x,__y) (__builtin_islessgreater (__x, __y))
#define isunordered(__x,__y) (__builtin_isunordered (__x, __y))
#else
#define isgreater(x,y) \
(__extension__ ({__typeof__(x) __x = (x); __typeof__(y) __y = (y); \
!isunordered(__x,__y) && (__x > __y);}))
@ -253,6 +287,7 @@ extern int __signbitd (double x);
#define isunordered(a,b) \
(__extension__ ({__typeof__(a) __a = (a); __typeof__(b) __b = (b); \
fpclassify(__a) == FP_NAN || fpclassify(__b) == FP_NAN;}))
#endif
/* Non ANSI long double precision functions. */
@ -386,8 +421,12 @@ extern float log2f _PARAMS((float));
extern float hypotf _PARAMS((float, float));
#endif /* ! defined (_REENT_ONLY) */
/* On platforms where long double equals double. */
#ifdef _LDBL_EQ_DBL
/* Newlib doesn't fully support long double math functions so far.
On platforms where long double equals double the long double functions
simply call the double functions. On Cygwin the long double functions
are implemented independently from newlib to be able to use optimized
assembler functions despite using the Microsoft x86_64 ABI. */
#if defined (_LDBL_EQ_DBL) || defined (__CYGWIN__)
/* Reentrant ANSI C functions. */
#ifndef __math_68881
extern long double atanl _PARAMS((long double));
@ -457,7 +496,7 @@ extern long double lgammal _PARAMS((long double));
extern long double erfl _PARAMS((long double));
extern long double erfcl _PARAMS((long double));
#endif /* ! defined (_REENT_ONLY) */
#else /* !_LDBL_EQ_DBL */
#else /* !_LDBL_EQ_DBL && !__CYGWIN__ */
extern long double hypotl _PARAMS((long double, long double));
extern long double sqrtl _PARAMS((long double));
#ifdef __i386__
@ -466,37 +505,47 @@ extern _LONG_DOUBLE rintl _PARAMS((_LONG_DOUBLE));
extern long int lrintl _PARAMS((_LONG_DOUBLE));
extern long long int llrintl _PARAMS((_LONG_DOUBLE));
#endif /* __i386__ */
#endif /* !_LDBL_EQ_DBL */
#endif /* !_LDBL_EQ_DBL && !__CYGWIN__ */
#endif /* !defined (__STRICT_ANSI__) || defined(__cplusplus) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) */
#if !defined (__STRICT_ANSI__) || defined(__cplusplus)
#endif /* __ISO_C_VISIBLE >= 1999 */
#if __MISC_VISIBLE
extern double drem _PARAMS((double, double));
extern void sincos _PARAMS((double, double *, double *));
extern float dremf _PARAMS((float, float));
#ifdef __CYGWIN__
extern float dreml _PARAMS((long double, long double));
#endif /* __CYGWIN__ */
extern double gamma_r _PARAMS((double, int *));
extern double lgamma_r _PARAMS((double, int *));
extern float gammaf_r _PARAMS((float, int *));
extern float lgammaf_r _PARAMS((float, int *));
#endif
#if __MISC_VISIBLE || __XSI_VISIBLE
extern double y0 _PARAMS((double));
extern double y1 _PARAMS((double));
extern double yn _PARAMS((int, double));
extern double j0 _PARAMS((double));
extern double j1 _PARAMS((double));
extern double jn _PARAMS((int, double));
#endif
extern float dremf _PARAMS((float, float));
extern void sincosf _PARAMS((float, float *, float *));
extern float gammaf_r _PARAMS((float, int *));
extern float lgammaf_r _PARAMS((float, int *));
#if __MISC_VISIBLE || __XSI_VISIBLE >= 600
extern float y0f _PARAMS((float));
extern float y1f _PARAMS((float));
extern float ynf _PARAMS((int, float));
extern float j0f _PARAMS((float));
extern float j1f _PARAMS((float));
extern float jnf _PARAMS((int, float));
#endif
/* GNU extensions */
#if __GNU_VISIBLE
extern void sincos _PARAMS((double, double *, double *));
extern void sincosf _PARAMS((float, float *, float *));
#ifdef __CYGWIN__
extern void sincosl _PARAMS((long double, long double *, long double *));
#endif /* __CYGWIN__ */
# ifndef exp10
extern double exp10 _PARAMS((double));
# endif
@ -509,11 +558,17 @@ extern float exp10f _PARAMS((float));
# ifndef pow10f
extern float pow10f _PARAMS((float));
# endif
#ifdef __CYGWIN__
# ifndef exp10l
extern float exp10l _PARAMS((float));
# endif
# ifndef pow10l
extern float pow10l _PARAMS((float));
# endif
#endif /* __CYGWIN__ */
#endif /* __GNU_VISIBLE */
#endif /* !defined (__STRICT_ANSI__) || defined(__cplusplus) */
#ifndef __STRICT_ANSI__
#if __MISC_VISIBLE || __XSI_VISIBLE
/* The gamma functions use a global variable, signgam. */
#ifndef _REENT_ONLY
#define signgam (*__signgam())
@ -521,7 +576,9 @@ extern int *__signgam _PARAMS((void));
#endif /* ! defined (_REENT_ONLY) */
#define __signgam_r(ptr) _REENT_SIGNGAM(ptr)
#endif /* __MISC_VISIBLE || __XSI_VISIBLE */
#if __SVID_VISIBLE
/* The exception structure passed to the matherr routine. */
/* We have a problem when using C++ since `exception' is a reserved
name in C++. */
@ -554,11 +611,11 @@ extern int matherr _PARAMS((struct exception *e));
#define TLOSS 5
#define PLOSS 6
#endif /* ! defined (__STRICT_ANSI__) */
#endif /* __SVID_VISIBLE */
/* Useful constants. */
#if !defined(__STRICT_ANSI__) || ((_XOPEN_SOURCE - 0) >= 500)
#if __BSD_VISIBLE || __XSI_VISIBLE >= 500
#define MAXFLOAT 3.40282347e+38F
@ -578,7 +635,7 @@ extern int matherr _PARAMS((struct exception *e));
#endif
#ifndef __STRICT_ANSI__
#if __BSD_VISIBLE
#define M_TWOPI (M_PI * 2.0)
#define M_3PI_4 2.3561944901923448370E0
@ -610,7 +667,7 @@ extern __IMPORT _LIB_VERSION_TYPE _LIB_VERSION;
#define _XOPEN_ __fdlibm_xopen
#define _POSIX_ __fdlibm_posix
#endif /* ! defined (__STRICT_ANSI__) */
#endif /* __BSD_VISIBLE */
_END_STD_C

View File

@ -11,11 +11,11 @@
/* #undef _ELIX_LEVEL */
/* Newlib version */
#define _NEWLIB_VERSION "2.3.0"
#include <_newlib_version.h>
/* C99 formats support (such as %a, %zu, ...) in IO functions like
* printf/scanf enabled */
//#define _WANT_IO_C99_FORMATS
/* #undef _WANT_IO_C99_FORMATS */
#define __DYNAMIC_REENT__
@ -49,7 +49,7 @@
/* Define if the linker supports .preinit_array/.init_array/.fini_array
* sections. */
#define HAVE_INITFINI_ARRAY 1
/* #undef HAVE_INITFINI_ARRAY */
/* True if atexit() may dynamically allocate space for cleanup
functions. */
@ -58,6 +58,9 @@
/* True if long double supported. */
#define _HAVE_LONG_DOUBLE 1
/* Define if compiler supports -fno-tree-loop-distribute-patterns. */
#define _HAVE_CC_INHIBIT_LOOP_TO_LIBCALL 1
/* True if long double supported and it is equal to double. */
/* #undef _LDBL_EQ_DBL */

View File

@ -1,8 +1,7 @@
/* pthread.h
/*
* Written by Joel Sherrill <joel.sherrill@OARcorp.com>.
*
* Written by Joel Sherrill <joel@OARcorp.com>.
*
* COPYRIGHT (c) 1989-2013.
* COPYRIGHT (c) 1989-2013, 2015.
* On-Line Applications Research Corporation (OAR).
*
* Permission to use, copy, modify, and distribute this software for any
@ -14,8 +13,6 @@
* WARRANTY. IN PARTICULAR, THE AUTHOR MAKES NO REPRESENTATION
* OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS
* SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
*
* $Id$
*/
#ifndef __PTHREAD_h
@ -96,6 +93,13 @@ int _EXFUN(pthread_mutex_timedlock,
int _EXFUN(pthread_condattr_init, (pthread_condattr_t *__attr));
int _EXFUN(pthread_condattr_destroy, (pthread_condattr_t *__attr));
int _EXFUN(pthread_condattr_getclock,
(const pthread_condattr_t *__restrict __attr,
clockid_t *__restrict __clock_id));
int _EXFUN(pthread_condattr_setclock,
(pthread_condattr_t *__attr, clockid_t __clock_id));
int _EXFUN(pthread_condattr_getpshared,
(_CONST pthread_condattr_t *__attr, int *__pshared));
int _EXFUN(pthread_condattr_setpshared,
@ -161,6 +165,9 @@ int _EXFUN(pthread_getschedparam,
int _EXFUN(pthread_setschedparam,
(pthread_t __pthread, int __policy, struct sched_param *__param));
/* Set Scheduling Priority of a Thread */
int _EXFUN(pthread_setschedprio, (pthread_t thread, int prio));
#endif /* defined(_POSIX_THREAD_PRIORITY_SCHEDULING) */
#if defined(_POSIX_THREAD_PRIO_INHERIT) || defined(_POSIX_THREAD_PRIO_PROTECT)
@ -253,7 +260,7 @@ int _EXFUN(pthread_detach, (pthread_t __pthread));
/* Thread Termination, p1003.1c/Draft 10, p. 150 */
void _EXFUN(pthread_exit, (void *__value_ptr));
void _EXFUN(pthread_exit, (void *__value_ptr)) __dead2;
/* Get Calling Thread's ID, p1003.1c/Draft 10, p. XXX */
@ -263,6 +270,14 @@ pthread_t _EXFUN(pthread_self, (void));
int _EXFUN(pthread_equal, (pthread_t __t1, pthread_t __t2));
/* Retrieve ID of a Thread's CPU Time Clock */
int _EXFUN(pthread_getcpuclockid,
(pthread_t thread, clockid_t *clock_id));
/* Get/Set Current Thread's Concurrency Level */
int _EXFUN(pthread_setconcurrency, (int new_level));
int _EXFUN(pthread_getconcurrency, (void));
/* Dynamic Package Initialization */
/* This is used to statically initialize a pthread_once_t. Example:
@ -329,7 +344,7 @@ void _EXFUN(_pthread_cleanup_pop,
_pthread_cleanup_pop(&_pthread_clup_ctx, (_execute)); \
} while (0)
#if defined(_GNU_SOURCE)
#if __GNU_VISIBLE
void _EXFUN(_pthread_cleanup_push_defer,
(struct _pthread_cleanup_context *_context,
void (*_routine)(void *), void *_arg));
@ -347,7 +362,7 @@ void _EXFUN(_pthread_cleanup_pop_restore,
#define pthread_cleanup_pop_restore_np(_execute) \
_pthread_cleanup_pop_restore(&_pthread_clup_ctx, (_execute)); \
} while (0)
#endif /* defined(_GNU_SOURCE) */
#endif /* __GNU_VISIBLE */
#if defined(_POSIX_THREAD_CPUTIME)

View File

@ -63,14 +63,14 @@ struct passwd {
struct passwd *getpwuid (uid_t);
struct passwd *getpwnam (const char *);
#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 500
#if __MISC_VISIBLE || __POSIX_VISIBLE
int getpwnam_r (const char *, struct passwd *,
char *, size_t , struct passwd **);
int getpwuid_r (uid_t, struct passwd *, char *,
size_t, struct passwd **);
#endif
#if __XSI_VISIBLE >= 500
#if __MISC_VISIBLE || __XSI_VISIBLE >= 4
struct passwd *getpwent (void);
void setpwent (void);
void endpwent (void);

View File

@ -2,15 +2,18 @@
#define _SIGNAL_H_
#include "_ansi.h"
#include <sys/cdefs.h>
#include <sys/signal.h>
_BEGIN_STD_C
typedef int sig_atomic_t; /* Atomic entity type (ANSI) */
#ifndef _POSIX_SOURCE
#if __BSD_VISIBLE
typedef _sig_func_ptr sig_t; /* BSD naming */
#endif
#if __GNU_VISIBLE
typedef _sig_func_ptr sighandler_t; /* glibc naming */
#endif /* !_POSIX_SOURCE */
#endif
#define SIG_DFL ((_sig_func_ptr)0) /* Default action */
#define SIG_IGN ((_sig_func_ptr)1) /* Ignore action */

View File

@ -128,7 +128,7 @@ typedef _fpos64_t fpos64_t;
#define L_tmpnam FILENAME_MAX
#endif
#ifndef __STRICT_ANSI__
#if __BSD_VISIBLE || __XSI_VISIBLE
#define P_tmpdir "/tmp"
#endif
@ -230,7 +230,7 @@ int _EXFUN(rename, (const char *, const char *));
int _EXFUN(_rename, (const char *, const char *));
#endif
#endif
#if !defined(__STRICT_ANSI__) || defined(__USE_XOPEN2K)
#if __LARGEFILE_VISIBLE || __POSIX_VISIBLE >= 200112
#ifdef _COMPILING_NEWLIB
int _EXFUN(fseeko, (FILE *, _off_t, int));
_off_t _EXFUN(ftello, ( FILE *));
@ -242,16 +242,32 @@ off_t _EXFUN(ftello, ( FILE *));
#if __GNU_VISIBLE
int _EXFUN(fcloseall, (_VOID));
#endif
#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) || (__cplusplus >= 201103L)
#ifndef _REENT_ONLY
#if __ISO_C_VISIBLE >= 1999
int _EXFUN(snprintf, (char *__restrict, size_t, const char *__restrict, ...)
_ATTRIBUTE ((__format__ (__printf__, 3, 4))));
int _EXFUN(vsnprintf, (char *__restrict, size_t, const char *__restrict, __VALIST)
_ATTRIBUTE ((__format__ (__printf__, 3, 0))));
int _EXFUN(vfscanf, (FILE *__restrict, const char *__restrict, __VALIST)
_ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
int _EXFUN(vscanf, (const char *, __VALIST)
_ATTRIBUTE ((__format__ (__scanf__, 1, 0))));
int _EXFUN(vsscanf, (const char *__restrict, const char *__restrict, __VALIST)
_ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
#endif
#if __GNU_VISIBLE
int _EXFUN(asprintf, (char **__restrict, const char *__restrict, ...)
_ATTRIBUTE ((__format__ (__printf__, 2, 3))));
int _EXFUN(vasprintf, (char **, const char *, __VALIST)
_ATTRIBUTE ((__format__ (__printf__, 2, 0))));
#endif
#if __MISC_VISIBLE /* Newlib-specific */
int _EXFUN(asiprintf, (char **, const char *, ...)
_ATTRIBUTE ((__format__ (__printf__, 2, 3))));
char * _EXFUN(asniprintf, (char *, size_t *, const char *, ...)
_ATTRIBUTE ((__format__ (__printf__, 3, 4))));
char * _EXFUN(asnprintf, (char *__restrict, size_t *__restrict, const char *__restrict, ...)
_ATTRIBUTE ((__format__ (__printf__, 3, 4))));
int _EXFUN(asprintf, (char **__restrict, const char *__restrict, ...)
_ATTRIBUTE ((__format__ (__printf__, 2, 3))));
#ifndef diprintf
int _EXFUN(diprintf, (int, const char *, ...)
_ATTRIBUTE ((__format__ (__printf__, 2, 3))));
@ -268,8 +284,6 @@ int _EXFUN(siprintf, (char *, const char *, ...)
_ATTRIBUTE ((__format__ (__printf__, 2, 3))));
int _EXFUN(siscanf, (const char *, const char *, ...)
_ATTRIBUTE ((__format__ (__scanf__, 2, 3))));
int _EXFUN(snprintf, (char *__restrict, size_t, const char *__restrict, ...)
_ATTRIBUTE ((__format__ (__printf__, 3, 4))));
int _EXFUN(sniprintf, (char *, size_t, const char *, ...)
_ATTRIBUTE ((__format__ (__printf__, 3, 4))));
int _EXFUN(vasiprintf, (char **, const char *, __VALIST)
@ -278,50 +292,50 @@ char * _EXFUN(vasniprintf, (char *, size_t *, const char *, __VALIST)
_ATTRIBUTE ((__format__ (__printf__, 3, 0))));
char * _EXFUN(vasnprintf, (char *, size_t *, const char *, __VALIST)
_ATTRIBUTE ((__format__ (__printf__, 3, 0))));
int _EXFUN(vasprintf, (char **, const char *, __VALIST)
_ATTRIBUTE ((__format__ (__printf__, 2, 0))));
int _EXFUN(vdiprintf, (int, const char *, __VALIST)
_ATTRIBUTE ((__format__ (__printf__, 2, 0))));
int _EXFUN(vfiprintf, (FILE *, const char *, __VALIST)
_ATTRIBUTE ((__format__ (__printf__, 2, 0))));
int _EXFUN(vfiscanf, (FILE *, const char *, __VALIST)
_ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
int _EXFUN(vfscanf, (FILE *__restrict, const char *__restrict, __VALIST)
_ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
int _EXFUN(viprintf, (const char *, __VALIST)
_ATTRIBUTE ((__format__ (__printf__, 1, 0))));
int _EXFUN(viscanf, (const char *, __VALIST)
_ATTRIBUTE ((__format__ (__scanf__, 1, 0))));
int _EXFUN(vscanf, (const char *, __VALIST)
_ATTRIBUTE ((__format__ (__scanf__, 1, 0))));
int _EXFUN(vsiprintf, (char *, const char *, __VALIST)
_ATTRIBUTE ((__format__ (__printf__, 2, 0))));
int _EXFUN(vsiscanf, (const char *, const char *, __VALIST)
_ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
int _EXFUN(vsniprintf, (char *, size_t, const char *, __VALIST)
_ATTRIBUTE ((__format__ (__printf__, 3, 0))));
int _EXFUN(vsnprintf, (char *__restrict, size_t, const char *__restrict, __VALIST)
_ATTRIBUTE ((__format__ (__printf__, 3, 0))));
int _EXFUN(vsscanf, (const char *__restrict, const char *__restrict, __VALIST)
_ATTRIBUTE ((__format__ (__scanf__, 2, 0))));
#endif /* __MISC_VISIBLE */
#endif /* !_REENT_ONLY */
#endif /* !__STRICT_ANSI__ */
/*
* Routines in POSIX 1003.1:2001.
*/
#ifndef __STRICT_ANSI__
#if __POSIX_VISIBLE
#ifndef _REENT_ONLY
FILE * _EXFUN(fdopen, (int, const char *));
#endif
int _EXFUN(fileno, (FILE *));
int _EXFUN(getw, (FILE *));
#endif
#if __MISC_VISIBLE || __POSIX_VISIBLE >= 199209
int _EXFUN(pclose, (FILE *));
FILE * _EXFUN(popen, (const char *, const char *));
int _EXFUN(putw, (int, FILE *));
#endif
#if __BSD_VISIBLE
void _EXFUN(setbuffer, (FILE *, char *, int));
int _EXFUN(setlinebuf, (FILE *));
#endif
#if __MISC_VISIBLE || (__XSI_VISIBLE && __POSIX_VISIBLE < 200112)
int _EXFUN(getw, (FILE *));
int _EXFUN(putw, (int, FILE *));
#endif
#if __MISC_VISIBLE || __POSIX_VISIBLE
int _EXFUN(getc_unlocked, (FILE *));
int _EXFUN(getchar_unlocked, (void));
void _EXFUN(flockfile, (FILE *));
@ -329,13 +343,13 @@ int _EXFUN(ftrylockfile, (FILE *));
void _EXFUN(funlockfile, (FILE *));
int _EXFUN(putc_unlocked, (int, FILE *));
int _EXFUN(putchar_unlocked, (int));
#endif /* ! __STRICT_ANSI__ */
#endif
/*
* Routines in POSIX 1003.1:200x.
*/
#ifndef __STRICT_ANSI__
#if __POSIX_VISIBLE >= 200809
# ifndef _REENT_ONLY
# ifndef dprintf
int _EXFUN(dprintf, (int, const char *__restrict, ...)
@ -345,13 +359,13 @@ FILE * _EXFUN(fmemopen, (void *__restrict, size_t, const char *__restrict));
/* getdelim - see __getdelim for now */
/* getline - see __getline for now */
FILE * _EXFUN(open_memstream, (char **, size_t *));
#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809
int _EXFUN(renameat, (int, const char *, int, const char *));
#endif
int _EXFUN(vdprintf, (int, const char *__restrict, __VALIST)
_ATTRIBUTE ((__format__ (__printf__, 2, 0))));
# endif
#endif
#if __ATFILE_VISIBLE
int _EXFUN(renameat, (int, const char *, int, const char *));
#endif
/*
* Recursive versions of the above.
@ -495,7 +509,7 @@ int _EXFUN(fpurge, (FILE *));
ssize_t _EXFUN(__getdelim, (char **, size_t *, int, FILE *));
ssize_t _EXFUN(__getline, (char **, size_t *, FILE *));
#if __BSD_VISIBLE
#if __MISC_VISIBLE
void _EXFUN(clearerr_unlocked, (FILE *));
int _EXFUN(feof_unlocked, (FILE *));
int _EXFUN(ferror_unlocked, (FILE *));
@ -545,7 +559,7 @@ int _EXFUN(__swbuf_r, (struct _reent *, int, FILE *));
* Stdio function-access interface.
*/
#ifndef __STRICT_ANSI__
#if __BSD_VISIBLE
# ifdef __LARGE64_FILES
FILE *_EXFUN(funopen,(const _PTR __cookie,
int (*__readfn)(_PTR __c, char *__buf,
@ -582,7 +596,9 @@ FILE *_EXFUN(_funopen_r,(struct _reent *, const _PTR __cookie,
(fpos_t (*)())0, (int (*)())0)
# define fwopen(__cookie, __fn) funopen(__cookie, (int (*)())0, __fn, \
(fpos_t (*)())0, (int (*)())0)
#endif /* __BSD_VISIBLE */
#if __GNU_VISIBLE
typedef ssize_t cookie_read_function_t(void *__cookie, char *__buf, size_t __n);
typedef ssize_t cookie_write_function_t(void *__cookie, const char *__buf,
size_t __n);
@ -606,7 +622,7 @@ FILE *_EXFUN(fopencookie,(void *__cookie,
const char *__mode, cookie_io_functions_t __functions));
FILE *_EXFUN(_fopencookie_r,(struct _reent *, void *__cookie,
const char *__mode, cookie_io_functions_t __functions));
#endif /* ! __STRICT_ANSI__ */
#endif /* __GNU_VISIBLE */
#ifndef __CUSTOM_FILE_IO__
/*
@ -645,10 +661,12 @@ _ELIDABLE_INLINE int __sgetc_r(struct _reent *__ptr, FILE *__p)
#define __sgetc_r(__ptr, __p) __sgetc_raw_r(__ptr, __p)
#endif
#ifdef _never /* __GNUC__ */
/* If this inline is actually used, then systems using coff debugging
info get hopelessly confused. 21sept93 rich@cygnus.com. */
#ifdef __GNUC__
_ELIDABLE_INLINE int __sputc_r(struct _reent *_ptr, int _c, FILE *_p) {
#ifdef __SCLE
if ((_p->_flags & __SCLE) && _c == '\n')
__sputc_r (_ptr, '\r', _p);
#endif
if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
return (*_p->_p++ = _c);
else
@ -686,14 +704,14 @@ _ELIDABLE_INLINE int __sputc_r(struct _reent *_ptr, int _c, FILE *_p) {
#define ferror(p) __sferror(p)
#define clearerr(p) __sclearerr(p)
#if __BSD_VISIBLE
#if __MISC_VISIBLE
#define feof_unlocked(p) __sfeof(p)
#define ferror_unlocked(p) __sferror(p)
#define clearerr_unlocked(p) __sclearerr(p)
#endif /* __BSD_VISIBLE */
#endif /* __MISC_VISIBLE */
#endif /* _REENT_SMALL */
#if 0 /*ndef __STRICT_ANSI__ - FIXME: must initialize stdio first, use fn */
#if 0 /* __POSIX_VISIBLE - FIXME: must initialize stdio first, use fn */
#define fileno(p) __sfileno(p)
#endif
@ -704,11 +722,13 @@ _ELIDABLE_INLINE int __sputc_r(struct _reent *_ptr, int _c, FILE *_p) {
#endif /* lint */
#endif /* __CYGWIN__ */
#ifndef __STRICT_ANSI__
#if __MISC_VISIBLE
/* fast always-buffered version, true iff error */
#define fast_putc(x,p) (--(p)->_w < 0 ? \
__swbuf_r(_REENT, (int)(x), p) == EOF : (*(p)->_p = (x), (p)->_p++, 0))
#endif
#if __XSI_VISIBLE
#define L_cuserid 9 /* posix says it goes in stdio.h :( */
#ifdef __CYGWIN__
#define L_ctermid 16
@ -720,7 +740,7 @@ _ELIDABLE_INLINE int __sputc_r(struct _reent *_ptr, int _c, FILE *_p) {
#define getchar() getc(stdin)
#define putchar(x) putc(x, stdout)
#ifndef __STRICT_ANSI__
#if __MISC_VISIBLE || __POSIX_VISIBLE
#define getchar_unlocked() getc_unlocked(stdin)
#define putchar_unlocked(x) putc_unlocked(x, stdout)
#endif

View File

@ -40,9 +40,7 @@ typedef struct
long rem; /* remainder */
} ldiv_t;
#if !defined(__STRICT_ANSI__) || \
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
(defined(__cplusplus) && __cplusplus >= 201103L)
#if __ISO_C_VISIBLE >= 1999
typedef struct
{
long long int quot; /* quotient */
@ -66,9 +64,14 @@ int _EXFUN(__locale_mb_cur_max,(_VOID));
_VOID _EXFUN(abort,(_VOID) _ATTRIBUTE ((__noreturn__)));
int _EXFUN(abs,(int));
#if __BSD_VISIBLE
__uint32_t _EXFUN(arc4random, (void));
__uint32_t _EXFUN(arc4random_uniform, (__uint32_t));
void _EXFUN(arc4random_buf, (void *, size_t));
#endif
int _EXFUN(atexit,(_VOID (*__func)(_VOID)));
double _EXFUN(atof,(const char *__nptr));
#ifndef __STRICT_ANSI__
#if __MISC_VISIBLE
float _EXFUN(atoff,(const char *__nptr));
#endif
int _EXFUN(atoi,(const char *__nptr));
@ -88,7 +91,7 @@ char * _EXFUN(getenv,(const char *__string));
char * _EXFUN(_getenv_r,(struct _reent *, const char *__string));
char * _EXFUN(_findenv,(_CONST char *, int *));
char * _EXFUN(_findenv_r,(struct _reent *, _CONST char *, int *));
#ifndef __STRICT_ANSI__
#if __POSIX_VISIBLE >= 200809
extern char *suboptarg; /* getsubopt(3) external variable */
int _EXFUN(getsubopt,(char **, char * const *, char **));
#endif
@ -105,39 +108,49 @@ size_t _EXFUN(mbstowcs,(wchar_t *__restrict, const char *__restrict, size_t));
size_t _EXFUN(_mbstowcs_r,(struct _reent *, wchar_t *__restrict, const char *__restrict, size_t, _mbstate_t *));
size_t _EXFUN(wcstombs,(char *__restrict, const wchar_t *__restrict, size_t));
size_t _EXFUN(_wcstombs_r,(struct _reent *, char *__restrict, const wchar_t *__restrict, size_t, _mbstate_t *));
#ifndef __STRICT_ANSI__
#ifndef _REENT_ONLY
#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809
char * _EXFUN(mkdtemp,(char *));
#endif
#if __GNU_VISIBLE
int _EXFUN(mkostemp,(char *, int));
int _EXFUN(mkostemps,(char *, int, int));
#endif
#if __MISC_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 4
int _EXFUN(mkstemp,(char *));
#endif
#if __MISC_VISIBLE
int _EXFUN(mkstemps,(char *, int));
#endif
#if __BSD_VISIBLE || (__XSI_VISIBLE >= 4 && __POSIX_VISIBLE < 200112)
char * _EXFUN(mktemp,(char *) _ATTRIBUTE ((__deprecated__("the use of `mktemp' is dangerous; use `mkstemp' instead"))));
#endif
#endif /* !_REENT_ONLY */
char * _EXFUN(_mkdtemp_r, (struct _reent *, char *));
int _EXFUN(_mkostemp_r, (struct _reent *, char *, int));
int _EXFUN(_mkostemps_r, (struct _reent *, char *, int, int));
int _EXFUN(_mkstemp_r, (struct _reent *, char *));
int _EXFUN(_mkstemps_r, (struct _reent *, char *, int));
char * _EXFUN(_mktemp_r, (struct _reent *, char *) _ATTRIBUTE ((__deprecated__("the use of `mktemp' is dangerous; use `mkstemp' instead"))));
#endif
_VOID _EXFUN(qsort,(_PTR __base, size_t __nmemb, size_t __size, __compar_fn_t _compar));
int _EXFUN(rand,(_VOID));
_PTR _EXFUN_NOTHROW(realloc,(_PTR __r, size_t __size));
#ifndef __STRICT_ANSI__
#if __BSD_VISIBLE
_PTR _EXFUN(reallocf,(_PTR __r, size_t __size));
#endif
#if __BSD_VISIBLE || __XSI_VISIBLE >= 4
char * _EXFUN(realpath, (const char *__restrict path, char *__restrict resolved_path));
#endif
#if __BSD_VISIBLE
int _EXFUN(rpmatch, (const char *response));
#endif
_VOID _EXFUN(srand,(unsigned __seed));
double _EXFUN(strtod,(const char *__restrict __n, char **__restrict __end_PTR));
double _EXFUN(_strtod_r,(struct _reent *,const char *__restrict __n, char **__restrict __end_PTR));
#if !defined(__STRICT_ANSI__) || \
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
(defined(__cplusplus) && __cplusplus >= 201103L)
#if __ISO_C_VISIBLE >= 1999
float _EXFUN(strtof,(const char *__restrict __n, char **__restrict __end_PTR));
#endif
#ifndef __STRICT_ANSI__
#if __MISC_VISIBLE
/* the following strtodf interface is deprecated...use strtof instead */
# ifndef strtodf
# define strtodf strtof
@ -150,24 +163,28 @@ unsigned long _EXFUN(_strtoul_r,(struct _reent *,const char *__restrict __n, cha
int _EXFUN(system,(const char *__string));
#ifndef __STRICT_ANSI__
#if __SVID_VISIBLE || __XSI_VISIBLE >= 4
long _EXFUN(a64l,(const char *__input));
char * _EXFUN(l64a,(long __input));
char * _EXFUN(_l64a_r,(struct _reent *,long __input));
#endif
#if __MISC_VISIBLE
int _EXFUN(on_exit,(_VOID (*__func)(int, _PTR),_PTR __arg));
#endif /* ! __STRICT_ANSI__ */
#if !defined(__STRICT_ANSI__) || \
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
(defined(__cplusplus) && __cplusplus >= 201103L)
#endif
#if __ISO_C_VISIBLE >= 1999
_VOID _EXFUN(_Exit,(int __status) _ATTRIBUTE ((__noreturn__)));
#endif
#ifndef __STRICT_ANSI__
#if __SVID_VISIBLE || __XSI_VISIBLE
int _EXFUN(putenv,(char *__string));
#endif
int _EXFUN(_putenv_r,(struct _reent *, char *__string));
_PTR _EXFUN(_reallocf_r,(struct _reent *, _PTR, size_t));
#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112
int _EXFUN(setenv,(const char *__string, const char *__value, int __overwrite));
#endif
int _EXFUN(_setenv_r,(struct _reent *, const char *__string, const char *__value, int __overwrite));
#if __XSI_VISIBLE >= 4 && __POSIX_VISIBLE < 200112
char * _EXFUN(gcvt,(double,int,char *));
char * _EXFUN(gcvtf,(float,int,char *));
char * _EXFUN(fcvt,(double,int,int *,int *));
@ -176,15 +193,18 @@ char * _EXFUN(ecvt,(double,int,int *,int *));
char * _EXFUN(ecvtbuf,(double, int, int*, int*, char *));
char * _EXFUN(fcvtbuf,(double, int, int*, int*, char *));
char * _EXFUN(ecvtf,(float,int,int *,int *));
char * _EXFUN(dtoa,(double, int, int, int *, int*, char**));
#endif
char * _EXFUN(__itoa,(int, char *, int));
char * _EXFUN(__utoa,(unsigned, char *, int));
#ifndef __STRICT_ANSI__
#if __MISC_VISIBLE
char * _EXFUN(itoa,(int, char *, int));
char * _EXFUN(utoa,(unsigned, char *, int));
#endif
#if __POSIX_VISIBLE
int _EXFUN(rand_r,(unsigned *__seed));
#endif
#if __SVID_VISIBLE || __XSI_VISIBLE
double _EXFUN(drand48,(_VOID));
double _EXFUN(_drand48_r,(struct _reent *));
double _EXFUN(erand48,(unsigned short [3]));
@ -205,45 +225,42 @@ unsigned short *
_EXFUN(_seed48_r,(struct _reent *, unsigned short [3]));
_VOID _EXFUN(srand48,(long));
_VOID _EXFUN(_srand48_r,(struct _reent *, long));
#endif /* ! __STRICT_ANSI__ */
#if !defined(__STRICT_ANSI__) || \
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
(defined(__cplusplus) && __cplusplus >= 201103L)
#endif /* __SVID_VISIBLE || __XSI_VISIBLE */
#if __SVID_VISIBLE || __XSI_VISIBLE >= 4 || __BSD_VISIBLE
char * _EXFUN(initstate,(unsigned, char *, size_t));
long _EXFUN(random,(_VOID));
char * _EXFUN(setstate,(char *));
_VOID _EXFUN(srandom,(unsigned));
#endif
#if __ISO_C_VISIBLE >= 1999
long long _EXFUN(atoll,(const char *__nptr));
#endif
#ifndef __STRICT_ANSI__
long long _EXFUN(_atoll_r,(struct _reent *, const char *__nptr));
#endif /* ! __STRICT_ANSI__ */
#if !defined(__STRICT_ANSI__) || \
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
(defined(__cplusplus) && __cplusplus >= 201103L)
#if __ISO_C_VISIBLE >= 1999
long long _EXFUN(llabs,(long long));
lldiv_t _EXFUN(lldiv,(long long __numer, long long __denom));
long long _EXFUN(strtoll,(const char *__restrict __n, char **__restrict __end_PTR, int __base));
#endif
#ifndef __STRICT_ANSI__
long long _EXFUN(_strtoll_r,(struct _reent *, const char *__restrict __n, char **__restrict __end_PTR, int __base));
#endif /* ! __STRICT_ANSI__ */
#if !defined(__STRICT_ANSI__) || \
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
(defined(__cplusplus) && __cplusplus >= 201103L)
#if __ISO_C_VISIBLE >= 1999
unsigned long long _EXFUN(strtoull,(const char *__restrict __n, char **__restrict __end_PTR, int __base));
#endif
#ifndef __STRICT_ANSI__
unsigned long long _EXFUN(_strtoull_r,(struct _reent *, const char *__restrict __n, char **__restrict __end_PTR, int __base));
#ifndef __CYGWIN__
#if __MISC_VISIBLE
_VOID _EXFUN(cfree,(_PTR));
#endif
#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112
int _EXFUN(unsetenv,(const char *__string));
#endif
int _EXFUN(_unsetenv_r,(struct _reent *, const char *__string));
#endif
#endif /* !__CYGWIN__ */
#ifdef __rtems__
int _EXFUN(posix_memalign,(void **, size_t, size_t));
#if __POSIX_VISIBLE >= 200112
int _EXFUN(__nonnull (1) posix_memalign,(void **, size_t, size_t));
#endif
#endif /* ! __STRICT_ANSI__ */
char * _EXFUN(_dtoa_r,(struct _reent *, double, int, int, int *, int*, char**));
#ifndef __CYGWIN__
_PTR _EXFUN_NOTHROW(_malloc_r,(struct _reent *, size_t));
@ -260,7 +277,9 @@ _VOID _EXFUN(__eprintf,(const char *, const char *, unsigned int, const char *))
_BSD_SOURCE, you get the BSD version; otherwise you get the GNU
version. We want that #undef qsort_r will still let you
invoke the underlying function, but that requires gcc support. */
#ifdef _BSD_SOURCE
#if __GNU_VISIBLE
_VOID _EXFUN(qsort_r,(_PTR __base, size_t __nmemb, size_t __size, int (*_compar)(const _PTR, const _PTR, _PTR), _PTR __thunk));
#elif __BSD_VISIBLE
# ifdef __GNUC__
_VOID _EXFUN(qsort_r,(_PTR __base, size_t __nmemb, size_t __size, _PTR __thunk, int (*_compar)(_PTR, const _PTR, const _PTR)))
__asm__ (__ASMNAME ("__bsd_qsort_r"));
@ -268,16 +287,12 @@ _VOID _EXFUN(qsort_r,(_PTR __base, size_t __nmemb, size_t __size, _PTR __thunk,
_VOID _EXFUN(__bsd_qsort_r,(_PTR __base, size_t __nmemb, size_t __size, _PTR __thunk, int (*_compar)(_PTR, const _PTR, const _PTR)));
# define qsort_r __bsd_qsort_r
# endif
#elif __GNU_VISIBLE
_VOID _EXFUN(qsort_r,(_PTR __base, size_t __nmemb, size_t __size, int (*_compar)(const _PTR, const _PTR, _PTR), _PTR __thunk));
#endif
/* On platforms where long double equals double. */
#ifdef _HAVE_LONG_DOUBLE
extern long double _strtold_r (struct _reent *, const char *__restrict, char **__restrict);
#if !defined(__STRICT_ANSI__) || \
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
(defined(__cplusplus) && __cplusplus >= 201103L)
#if __ISO_C_VISIBLE >= 1999
extern long double strtold (const char *__restrict, char **__restrict);
#endif
#endif /* _HAVE_LONG_DOUBLE */
@ -285,7 +300,7 @@ extern long double strtold (const char *__restrict, char **__restrict);
/*
* If we're in a mode greater than C99, expose C11 functions.
*/
#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L
#if __ISO_C_VISIBLE >= 2011
void * aligned_alloc(size_t, size_t) __malloc_like __alloc_align(1)
__alloc_size(2);
int at_quick_exit(void (*)(void));

View File

@ -43,28 +43,35 @@ char *_EXFUN(strtok,(char *__restrict, const char *__restrict));
#endif
size_t _EXFUN(strxfrm,(char *__restrict, const char *__restrict, size_t));
#if __POSIX_VISIBLE
#if __MISC_VISIBLE || __POSIX_VISIBLE
char *_EXFUN(strtok_r,(char *__restrict, const char *__restrict, char **__restrict));
#endif
#if __BSD_VISIBLE
#if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE < 200809)
int _EXFUN(bcmp,(const void *, const void *, size_t));
void _EXFUN(bcopy,(const void *, void *, size_t));
void _EXFUN(bzero,(void *, size_t));
#endif
#if __BSD_VISIBLE
void _EXFUN(explicit_bzero,(void *, size_t));
int _EXFUN(timingsafe_bcmp,(const void *, const void *, size_t));
int _EXFUN(timingsafe_memcmp,(const void *, const void *, size_t));
#endif
#if __MISC_VISIBLE || __POSIX_VISIBLE >= 200809
int _EXFUN(ffs,(int));
#endif
#if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE < 200809)
char *_EXFUN(index,(const char *, int));
#endif
#if __BSD_VISIBLE || __XSI_VISIBLE
#if __MISC_VISIBLE || __POSIX_VISIBLE
_PTR _EXFUN(memccpy,(_PTR __restrict, const _PTR __restrict, int, size_t));
#endif
#if __GNU_VISIBLE
_PTR _EXFUN(mempcpy,(_PTR, const _PTR, size_t));
_PTR _EXFUN(memmem, (const _PTR, size_t, const _PTR, size_t));
#endif
_PTR _EXFUN(memrchr,(const _PTR, int, size_t));
#if __GNU_VISIBLE
_PTR _EXFUN(rawmemchr,(const _PTR, int));
#endif
#if __BSD_VISIBLE
#if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE < 200809)
char *_EXFUN(rindex,(const char *, int));
#endif
char *_EXFUN(stpcpy,(char *__restrict, const char *__restrict));
@ -76,19 +83,14 @@ int _EXFUN(strcasecmp,(const char *, const char *));
char *_EXFUN(strcasestr,(const char *, const char *));
char *_EXFUN(strchrnul,(const char *, int));
#endif
#if __XSI_VISIBLE >= 500
#if __MISC_VISIBLE || __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 4
char *_EXFUN(strdup,(const char *));
#endif
#ifndef __STRICT_ANSI__
char *_EXFUN(_strdup_r,(struct _reent *, const char *));
#endif
#if __XSI_VISIBLE >= 700
#if __POSIX_VISIBLE >= 200809
char *_EXFUN(strndup,(const char *, size_t));
#endif
#ifndef __STRICT_ANSI__
char *_EXFUN(_strndup_r,(struct _reent *, const char *, size_t));
#endif
#if __GNU_VISIBLE
int _EXFUN(ffsl,(long));
@ -101,7 +103,7 @@ int _EXFUN(ffsll, (long long));
invoke the underlying function, but that requires gcc support. */
#if __GNU_VISIBLE
char *_EXFUN(strerror_r,(int, char *, size_t));
#else
#elif __POSIX_VISIBLE >= 200112
# ifdef __GNUC__
int _EXFUN(strerror_r,(int, char *, size_t))
#ifdef __ASMNAME
@ -124,19 +126,14 @@ size_t _EXFUN(strlcpy,(char *, const char *, size_t));
#if __BSD_VISIBLE || __POSIX_VISIBLE
int _EXFUN(strncasecmp,(const char *, const char *, size_t));
#endif
#if !defined(__STRICT_ANSI__) || __POSIX_VISIBLE >= 200809 || \
__XSI_VISIBLE >= 700
#if __POSIX_VISIBLE >= 200809
size_t _EXFUN(strnlen,(const char *, size_t));
#endif
#if __BSD_VISIBLE
char *_EXFUN(strsep,(char **, const char *));
#endif
/*
* The origin of these is unknown to me so I am conditionalizing them
* on __STRICT_ANSI__. Finetuning this is definitely needed. --joel
*/
#if !defined(__STRICT_ANSI__)
#if __MISC_VISIBLE
char *_EXFUN(strlwr,(char *));
char *_EXFUN(strupr,(char *));
#endif
@ -149,7 +146,7 @@ char *_EXFUN(strsignal, (int __signo));
int _EXFUN(strtosigno, (const char *__name));
#endif
#if defined _GNU_SOURCE && defined __GNUC__
#if __GNU_VISIBLE && defined(__GNUC__)
#define strdupa(__s) \
(__extension__ ({const char *__in = (__s); \
size_t __len = strlen (__in) + 1; \
@ -161,7 +158,7 @@ int _EXFUN(strtosigno, (const char *__name));
char *__out = (char *) __builtin_alloca (__len); \
__out[__len-1] = '\0'; \
(char *) memcpy (__out, __in, __len-1);}))
#endif /* _GNU_SOURCE && __GNUC__ */
#endif /* __GNU_VISIBLE && __GNUC__ */
/* There are two common basename variants. If you do NOT #include <libgen.h>
and you do

View File

@ -9,12 +9,12 @@
#include "_ansi.h"
#include <sys/reent.h>
#include <sys/cdefs.h>
#include <sys/types.h> /* for size_t */
_BEGIN_STD_C
#if !defined __STRICT_ANSI__ && _POSIX_VERSION < 200809L
#if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE < 200809)
/*
* Marked LEGACY in Open Group Base Specifications Issue 6/IEEE Std 1003.1-2004
* Removed from Open Group Base Specifications Issue 7/IEEE Std 1003.1-2008
@ -24,7 +24,7 @@ void _EXFUN(bcopy,(const void *, void *, size_t));
void _EXFUN(bzero,(void *, size_t));
char *_EXFUN(index,(const char *, int));
char *_EXFUN(rindex,(const char *, int));
#endif /* ! __STRICT_ANSI__ */
#endif /* __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE < 200809) */
int _EXFUN(ffs,(int));
int _EXFUN(strcasecmp,(const char *, const char *));

View File

@ -66,8 +66,7 @@ extern "C" {
#define _O_BINARY O_BINARY
#define _O_RAW O_BINARY
#define _O_NOINHERIT O_NOINHERIT
#ifndef _POSIX_SOURCE
#if __MISC_VISIBLE
/*
* Flags that work for fcntl(fd, F_SETFL, FXXXX)
@ -99,7 +98,7 @@ extern "C" {
#define FEXCL _FEXCL
#define FNOCTTY _FNOCTTY
#endif /* !_POSIX_SOURCE */
#endif /* __MISC_VISIBLE */
/* XXX close on exec request; must match UF_EXCLOSE in user.h */
#define FD_CLOEXEC 1 /* posix */
@ -110,20 +109,20 @@ extern "C" {
#define F_SETFD 2 /* Set fildes flags (close on exec) */
#define F_GETFL 3 /* Get file flags */
#define F_SETFL 4 /* Set file flags */
#ifndef _POSIX_SOURCE
#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112
#define F_GETOWN 5 /* Get owner - for ASYNC */
#define F_SETOWN 6 /* Set owner - for ASYNC */
#endif /* !_POSIX_SOURCE */
#endif /* __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 */
#define F_GETLK 7 /* Get record-locking information */
#define F_SETLK 8 /* Set or Clear a record-lock (Non-Blocking) */
#define F_SETLKW 9 /* Set or Clear a record-lock (Blocking) */
#ifndef _POSIX_SOURCE
#if __MISC_VISIBLE
#define F_RGETLK 10 /* Test a remote lock to see if it is blocked */
#define F_RSETLK 11 /* Set or unlock a remote lock */
#define F_CNVT 12 /* Convert a fhandle to an open fd */
#define F_RSETLKW 13 /* Set or Clear remote record-lock(Blocking) */
#endif /* !_POSIX_SOURCE */
#ifdef __CYGWIN__
#endif /* __MISC_VISIBLE */
#if __POSIX_VISIBLE >= 200809
#define F_DUPFD_CLOEXEC 14 /* As F_DUPFD, but set close-on-exec flag */
#endif
@ -131,11 +130,11 @@ extern "C" {
#define F_RDLCK 1 /* read lock */
#define F_WRLCK 2 /* write lock */
#define F_UNLCK 3 /* remove lock(s) */
#ifndef _POSIX_SOURCE
#if __MISC_VISIBLE
#define F_UNLKSYS 4 /* remove remote locks for a given system */
#endif /* !_POSIX_SOURCE */
#endif /* __MISC_VISIBLE */
#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 || defined(__CYGWIN__)
#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809
/* Special descriptor value to denote the cwd in calls to openat(2) etc. */
#define AT_FDCWD -2
@ -168,7 +167,7 @@ struct flock {
};
#endif /* __CYGWIN__ */
#ifndef _POSIX_SOURCE
#if __MISC_VISIBLE
/* extended file segment locking set data type */
struct eflock {
short l_type; /* F_RDLCK, F_WRLCK, or F_UNLCK */
@ -180,13 +179,13 @@ struct eflock {
long l_rpid; /* Remote process id wanting this lock */
long l_rsys; /* Remote system id wanting this lock */
};
#endif /* !_POSIX_SOURCE */
#endif /* __MISC_VISIBLE */
#include <sys/types.h>
#include <sys/stat.h> /* sigh. for the mode bits for open/creat */
extern int open _PARAMS ((const char *, int, ...));
#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 || defined(__CYGWIN__)
#if __ATFILE_VISIBLE
extern int openat _PARAMS ((int, const char *, int, ...));
#endif
extern int creat _PARAMS ((const char *, mode_t));
@ -194,7 +193,7 @@ extern int fcntl _PARAMS ((int, int, ...));
#if __BSD_VISIBLE
extern int flock _PARAMS ((int, int));
#endif
#ifdef __CYGWIN__
#if __GNU_VISIBLE
#include <sys/time.h>
extern int futimesat _PARAMS ((int, const char *, const struct timeval *));
#endif

View File

@ -624,134 +624,6 @@
#define __DEQUALIFY(type, var) ((type)(__uintptr_t)(const volatile void *)(var))
#endif
/*-
* The following definitions are an extension of the behavior originally
* implemented in <sys/_posix.h>, but with a different level of granularity.
* POSIX.1 requires that the macros we test be defined before any standard
* header file is included.
*
* Here's a quick run-down of the versions:
* defined(_POSIX_SOURCE) 1003.1-1988
* _POSIX_C_SOURCE == 1 1003.1-1990
* _POSIX_C_SOURCE == 2 1003.2-1992 C Language Binding Option
* _POSIX_C_SOURCE == 199309 1003.1b-1993
* _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995,
* and the omnibus ISO/IEC 9945-1: 1996
* _POSIX_C_SOURCE == 200112 1003.1-2001
* _POSIX_C_SOURCE == 200809 1003.1-2008
*
* In addition, the X/Open Portability Guide, which is now the Single UNIX
* Specification, defines a feature-test macro which indicates the version of
* that specification, and which subsumes _POSIX_C_SOURCE.
*
* Our macros begin with two underscores to avoid namespace screwage.
*/
/* Deal with _GNU_SOURCE, which implies everything and the kitchen sink */
#ifdef _GNU_SOURCE
#undef _XOPEN_SOURCE
#define _XOPEN_SOURCE 700
#define __BSD_VISIBLE 1
#define __GNU_VISIBLE 1
#endif
#define __GNU_VISIBLE 1
/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1
#undef _POSIX_C_SOURCE /* Probably illegal, but beyond caring now. */
#define _POSIX_C_SOURCE 199009
#endif
/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2
#undef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 199209
#endif
/* Deal with various X/Open Portability Guides and Single UNIX Spec. */
#ifdef _XOPEN_SOURCE
#if _XOPEN_SOURCE - 0 >= 700
#define __XSI_VISIBLE 700
#undef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200809
#elif _XOPEN_SOURCE - 0 >= 600
#define __XSI_VISIBLE 600
#undef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200112
#elif _XOPEN_SOURCE - 0 >= 500
#define __XSI_VISIBLE 500
#undef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 199506
#endif
#endif
/*
* Deal with all versions of POSIX. The ordering relative to the tests above is
* important.
*/
#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
#define _POSIX_C_SOURCE 198808
#endif
#ifdef _POSIX_C_SOURCE
#if _POSIX_C_SOURCE >= 200809
#define __POSIX_VISIBLE 200809
#define __ISO_C_VISIBLE 1999
#elif _POSIX_C_SOURCE >= 200112
#define __POSIX_VISIBLE 200112
#define __ISO_C_VISIBLE 1999
#elif _POSIX_C_SOURCE >= 199506
#define __POSIX_VISIBLE 199506
#define __ISO_C_VISIBLE 1990
#elif _POSIX_C_SOURCE >= 199309
#define __POSIX_VISIBLE 199309
#define __ISO_C_VISIBLE 1990
#elif _POSIX_C_SOURCE >= 199209
#define __POSIX_VISIBLE 199209
#define __ISO_C_VISIBLE 1990
#elif _POSIX_C_SOURCE >= 199009
#define __POSIX_VISIBLE 199009
#define __ISO_C_VISIBLE 1990
#else
#define __POSIX_VISIBLE 198808
#define __ISO_C_VISIBLE 0
#endif /* _POSIX_C_SOURCE */
#else
/*-
* Deal with _ANSI_SOURCE:
* If it is defined, and no other compilation environment is explicitly
* requested, then define our internal feature-test macros to zero. This
* makes no difference to the preprocessor (undefined symbols in preprocessing
* expressions are defined to have value zero), but makes it more convenient for
* a test program to print out the values.
*
* If a program mistakenly defines _ANSI_SOURCE and some other macro such as
* _POSIX_C_SOURCE, we will assume that it wants the broader compilation
* environment (and in fact we will never get here).
*/
#if defined(_ANSI_SOURCE) /* Hide almost everything. */
#define __POSIX_VISIBLE 0
#define __XSI_VISIBLE 0
#define __BSD_VISIBLE 0
#define __ISO_C_VISIBLE 1990
#elif defined(_C99_SOURCE) /* Localism to specify strict C99 env. */
#define __POSIX_VISIBLE 0
#define __XSI_VISIBLE 0
#define __BSD_VISIBLE 0
#define __ISO_C_VISIBLE 1999
#elif defined(_C11_SOURCE) /* Localism to specify strict C11 env. */
#define __POSIX_VISIBLE 0
#define __XSI_VISIBLE 0
#define __BSD_VISIBLE 0
#define __ISO_C_VISIBLE 2011
#else /* Default: everything except __GNU_VISIBLE. */
#define __POSIX_VISIBLE 200809
#define __XSI_VISIBLE 700
#define __BSD_VISIBLE 1
#define __ISO_C_VISIBLE 2011
#endif
#endif
/*
* Type Safety Checking
*

View File

@ -232,9 +232,6 @@
#if defined(__CYGWIN__)
#include <cygwin/config.h>
#if !defined (__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L)
#define __USE_XOPEN2K 1
#endif
#endif
#if defined(__rtems__)

View File

@ -25,11 +25,7 @@
extern "C" {
#endif
/* Macros to determine that newlib is being used. Put in this header to
* be similar to where glibc stores its version of these macros.
*/
#define __NEWLIB__ 2
#define __NEWLIB_MINOR__ 2
#include <_newlib_version.h>
/* Macro to test version of GCC. Returns 0 for non-GCC or too old GCC. */
#ifndef __GNUC_PREREQ
@ -43,6 +39,281 @@ extern "C" {
/* Version with trailing underscores for BSD compatibility. */
#define __GNUC_PREREQ__(ma, mi) __GNUC_PREREQ(ma, mi)
/*
* Feature test macros control which symbols are exposed by the system
* headers. Any of these must be defined before including any headers.
*
* __STRICT_ANSI__ (defined by gcc -ansi, -std=c90, -std=c99, or -std=c11)
* ISO C
*
* _POSIX_SOURCE (deprecated by _POSIX_C_SOURCE=1)
* _POSIX_C_SOURCE >= 1
* POSIX.1-1990
*
* _POSIX_C_SOURCE >= 2
* POSIX.2-1992
*
* _POSIX_C_SOURCE >= 199309L
* POSIX.1b-1993 Real-time extensions
*
* _POSIX_C_SOURCE >= 199506L
* POSIX.1c-1995 Threads extensions
*
* _POSIX_C_SOURCE >= 200112L
* POSIX.1-2001 and C99
*
* _POSIX_C_SOURCE >= 200809L
* POSIX.1-2008
*
* _XOPEN_SOURCE
* POSIX.1-1990 and XPG4
*
* _XOPEN_SOURCE_EXTENDED
* SUSv1 (POSIX.2-1992 plus XPG4v2)
*
* _XOPEN_SOURCE >= 500
* SUSv2 (POSIX.1c-1995 plus XSI)
*
* _XOPEN_SOURCE >= 600
* SUSv3 (POSIX.1-2001 plus XSI) and C99
*
* _XOPEN_SOURCE >= 700
* SUSv4 (POSIX.1-2008 plus XSI)
*
* _ISOC99_SOURCE or gcc -std=c99 or g++
* ISO C99
*
* _ISOC11_SOURCE or gcc -std=c11 or g++ -std=c++11
* ISO C11
*
* _ATFILE_SOURCE (implied by _POSIX_C_SOURCE >= 200809L)
* "at" functions
*
* _LARGEFILE_SOURCE (deprecated by _XOPEN_SOURCE >= 500)
* fseeko, ftello
*
* _GNU_SOURCE
* All of the above plus GNU extensions
*
* _BSD_SOURCE (deprecated by _DEFAULT_SOURCE)
* _SVID_SOURCE (deprecated by _DEFAULT_SOURCE)
* _DEFAULT_SOURCE (or none of the above)
* POSIX-1.2008 with BSD and SVr4 extensions
*/
#ifdef _GNU_SOURCE
#undef _ATFILE_SOURCE
#define _ATFILE_SOURCE 1
#undef _DEFAULT_SOURCE
#define _DEFAULT_SOURCE 1
#undef _ISOC99_SOURCE
#define _ISOC99_SOURCE 1
#undef _ISOC11_SOURCE
#define _ISOC11_SOURCE 1
#undef _POSIX_SOURCE
#define _POSIX_SOURCE 1
#undef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200809L
#undef _XOPEN_SOURCE
#define _XOPEN_SOURCE 700
#undef _XOPEN_SOURCE_EXTENDED
#define _XOPEN_SOURCE_EXTENDED 1
#endif /* _GNU_SOURCE */
#if defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || \
(!defined(__STRICT_ANSI__) && !defined(_ANSI_SOURCE) && \
!defined(_ISOC99_SOURCE) && !defined(_POSIX_SOURCE) && \
!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE))
#undef _DEFAULT_SOURCE
#define _DEFAULT_SOURCE 1
#endif
#if defined(_DEFAULT_SOURCE)
#undef _POSIX_SOURCE
#define _POSIX_SOURCE 1
#undef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200809L
#endif
#if !defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) && \
((!defined(__STRICT_ANSI__) && !defined(_ANSI_SOURCE)) || \
(_XOPEN_SOURCE - 0) >= 500)
#define _POSIX_SOURCE 1
#if !defined(_XOPEN_SOURCE) || (_XOPEN_SOURCE - 0) >= 700
#define _POSIX_C_SOURCE 200809L
#elif (_XOPEN_SOURCE - 0) >= 600
#define _POSIX_C_SOURCE 200112L
#elif (_XOPEN_SOURCE - 0) >= 500
#define _POSIX_C_SOURCE 199506L
#elif (_XOPEN_SOURCE - 0) < 500
#define _POSIX_C_SOURCE 2
#endif
#endif
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809
#undef _ATFILE_SOURCE
#define _ATFILE_SOURCE 1
#endif
/*
* The following private macros are used throughout the headers to control
* which symbols should be exposed. They are for internal use only, as
* indicated by the leading double underscore, and must never be used outside
* of these headers.
*
* __POSIX_VISIBLE
* any version of POSIX.1; enabled by default, or with _POSIX_SOURCE,
* any value of _POSIX_C_SOURCE, or _XOPEN_SOURCE >= 500.
*
* __POSIX_VISIBLE >= 2
* POSIX.2-1992; enabled by default, with _POSIX_C_SOURCE >= 2,
* or _XOPEN_SOURCE >= 500.
*
* __POSIX_VISIBLE >= 199309
* POSIX.1b-1993; enabled by default, with _POSIX_C_SOURCE >= 199309L,
* or _XOPEN_SOURCE >= 500.
*
* __POSIX_VISIBLE >= 199506
* POSIX.1c-1995; enabled by default, with _POSIX_C_SOURCE >= 199506L,
* or _XOPEN_SOURCE >= 500.
*
* __POSIX_VISIBLE >= 200112
* POSIX.1-2001; enabled by default, with _POSIX_C_SOURCE >= 200112L,
* or _XOPEN_SOURCE >= 600.
*
* __POSIX_VISIBLE >= 200809
* POSIX.1-2008; enabled by default, with _POSIX_C_SOURCE >= 200809L,
* or _XOPEN_SOURCE >= 700.
*
* __XSI_VISIBLE
* XPG4 XSI extensions; enabled with any version of _XOPEN_SOURCE.
*
* __XSI_VISIBLE >= 4
* SUSv1 XSI extensions; enabled with both _XOPEN_SOURCE and
* _XOPEN_SOURCE_EXTENDED together.
*
* __XSI_VISIBLE >= 500
* SUSv2 XSI extensions; enabled with _XOPEN_SOURCE >= 500.
*
* __XSI_VISIBLE >= 600
* SUSv3 XSI extensions; enabled with _XOPEN_SOURCE >= 600.
*
* __XSI_VISIBLE >= 700
* SUSv4 XSI extensions; enabled with _XOPEN_SOURCE >= 700.
*
* __ISO_C_VISIBLE >= 1999
* ISO C99; enabled with gcc -std=c99 or newer (on by default since GCC 5),
* any version of C++, or with _ISOC99_SOURCE, _POSIX_C_SOURCE >= 200112L,
* or _XOPEN_SOURCE >= 600.
*
* __ISO_C_VISIBLE >= 2011
* ISO C11; enabled with gcc -std=c11 or newer (on by default since GCC 5),
* g++ -std=c++11 or newer (on by default since GCC 6), or with
* _ISOC11_SOURCE.
*
* __ATFILE_VISIBLE
* "at" functions; enabled by default, with _ATFILE_SOURCE,
* _POSIX_C_SOURCE >= 200809L, or _XOPEN_SOURCE >= 700.
*
* __LARGEFILE_VISIBLE
* fseeko, ftello; enabled with _LARGEFILE_SOURCE or _XOPEN_SOURCE >= 500.
*
* __BSD_VISIBLE
* BSD extensions; enabled by default, or with _BSD_SOURCE.
*
* __SVID_VISIBLE
* SVr4 extensions; enabled by default, or with _SVID_SOURCE.
*
* __MISC_VISIBLE
* Extensions found in both BSD and SVr4 (shorthand for
* (__BSD_VISIBLE || __SVID_VISIBLE)), or newlib-specific
* extensions; enabled by default.
*
* __GNU_VISIBLE
* GNU extensions; enabled with _GNU_SOURCE.
*
* In all cases above, "enabled by default" means either by defining
* _DEFAULT_SOURCE, or by not defining any of the public feature test macros.
* Defining _GNU_SOURCE makes all of the above avaliable.
*/
#ifdef _ATFILE_SOURCE
#define __ATFILE_VISIBLE 1
#else
#define __ATFILE_VISIBLE 0
#endif
#ifdef _DEFAULT_SOURCE
#define __BSD_VISIBLE 1
#else
#define __BSD_VISIBLE 0
#endif
#ifdef _GNU_SOURCE
#define __GNU_VISIBLE 1
#else
#define __GNU_VISIBLE 0
#endif
#if defined(_ISOC11_SOURCE) || \
(__STDC_VERSION__ - 0) >= 201112L || (__cplusplus - 0) >= 201103L
#define __ISO_C_VISIBLE 2011
#elif defined(_ISOC99_SOURCE) || (_POSIX_C_SOURCE - 0) >= 200112L || \
(__STDC_VERSION__ - 0) >= 199901L || defined(__cplusplus)
#define __ISO_C_VISIBLE 1999
#else
#define __ISO_C_VISIBLE 1990
#endif
#if defined(_LARGEFILE_SOURCE) || (_XOPEN_SOURCE - 0) >= 500
#define __LARGEFILE_VISIBLE 1
#else
#define __LARGEFILE_VISIBLE 0
#endif
#ifdef _DEFAULT_SOURCE
#define __MISC_VISIBLE 1
#else
#define __MISC_VISIBLE 0
#endif
#if (_POSIX_C_SOURCE - 0) >= 200809L
#define __POSIX_VISIBLE 200809
#elif (_POSIX_C_SOURCE - 0) >= 200112L
#define __POSIX_VISIBLE 200112
#elif (_POSIX_C_SOURCE - 0) >= 199506L
#define __POSIX_VISIBLE 199506
#elif (_POSIX_C_SOURCE - 0) >= 199309L
#define __POSIX_VISIBLE 199309
#elif (_POSIX_C_SOURCE - 0) >= 2 || defined(_XOPEN_SOURCE)
#define __POSIX_VISIBLE 199209
#elif defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE)
#define __POSIX_VISIBLE 199009
#else
#define __POSIX_VISIBLE 0
#endif
#ifdef _DEFAULT_SOURCE
#define __SVID_VISIBLE 1
#else
#define __SVID_VISIBLE 0
#endif
#if (_XOPEN_SOURCE - 0) >= 700
#define __XSI_VISIBLE 700
#elif (_XOPEN_SOURCE - 0) >= 600
#define __XSI_VISIBLE 600
#elif (_XOPEN_SOURCE - 0) >= 500
#define __XSI_VISIBLE 500
#elif defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)
#define __XSI_VISIBLE 4
#elif defined(_XOPEN_SOURCE)
#define __XSI_VISIBLE 1
#else
#define __XSI_VISIBLE 0
#endif
/* RTEMS adheres to POSIX -- 1003.1b with some features from annexes. */
#ifdef __rtems__
@ -112,50 +383,50 @@ extern "C" {
#ifdef __CYGWIN__
#if !defined(__STRICT_ANSI__) || defined(__cplusplus) || __STDC_VERSION__ >= 199901L
#define _POSIX_VERSION 200112L
#define _POSIX2_VERSION 200112L
#define _POSIX_VERSION 200809L
#define _POSIX2_VERSION 200809L
#define _XOPEN_VERSION 600
#define _POSIX_ADVISORY_INFO 200112L
#define _POSIX_ADVISORY_INFO 200809L
/* #define _POSIX_ASYNCHRONOUS_IO -1 */
/* #define _POSIX_BARRIERS -1 */
#define _POSIX_BARRIERS 200809L
#define _POSIX_CHOWN_RESTRICTED 1
#define _POSIX_CLOCK_SELECTION 200112L
#define _POSIX_CPUTIME 200112L
#define _POSIX_FSYNC 200112L
#define _POSIX_IPV6 200112L
#define _POSIX_CLOCK_SELECTION 200809L
#define _POSIX_CPUTIME 200809L
#define _POSIX_FSYNC 200809L
#define _POSIX_IPV6 200809L
#define _POSIX_JOB_CONTROL 1
#define _POSIX_MAPPED_FILES 200112L
#define _POSIX_MAPPED_FILES 200809L
/* #define _POSIX_MEMLOCK -1 */
#define _POSIX_MEMLOCK_RANGE 200112L
#define _POSIX_MEMORY_PROTECTION 200112L
#define _POSIX_MESSAGE_PASSING 200112L
#define _POSIX_MONOTONIC_CLOCK 200112L
#define _POSIX_MEMLOCK_RANGE 200809L
#define _POSIX_MEMORY_PROTECTION 200809L
#define _POSIX_MESSAGE_PASSING 200809L
#define _POSIX_MONOTONIC_CLOCK 200809L
#define _POSIX_NO_TRUNC 1
/* #define _POSIX_PRIORITIZED_IO -1 */
#define _POSIX_PRIORITY_SCHEDULING 200112L
#define _POSIX_RAW_SOCKETS 200112L
#define _POSIX_READER_WRITER_LOCKS 200112L
#define _POSIX_REALTIME_SIGNALS 200112L
#define _POSIX_PRIORITY_SCHEDULING 200809L
#define _POSIX_RAW_SOCKETS 200809L
#define _POSIX_READER_WRITER_LOCKS 200809L
#define _POSIX_REALTIME_SIGNALS 200809L
#define _POSIX_REGEXP 1
#define _POSIX_SAVED_IDS 1
#define _POSIX_SEMAPHORES 200112L
#define _POSIX_SHARED_MEMORY_OBJECTS 200112L
#define _POSIX_SEMAPHORES 200809L
#define _POSIX_SHARED_MEMORY_OBJECTS 200809L
#define _POSIX_SHELL 1
/* #define _POSIX_SPAWN -1 */
#define _POSIX_SPIN_LOCKS 200112L
#define _POSIX_SPAWN 200809L
#define _POSIX_SPIN_LOCKS 200809L
/* #define _POSIX_SPORADIC_SERVER -1 */
#define _POSIX_SYNCHRONIZED_IO 200112L
#define _POSIX_THREAD_ATTR_STACKADDR 200112L
#define _POSIX_THREAD_ATTR_STACKSIZE 200112L
#define _POSIX_THREAD_CPUTIME 200112L
#define _POSIX_SYNCHRONIZED_IO 200809L
#define _POSIX_THREAD_ATTR_STACKADDR 200809L
#define _POSIX_THREAD_ATTR_STACKSIZE 200809L
#define _POSIX_THREAD_CPUTIME 200809L
/* #define _POSIX_THREAD_PRIO_INHERIT -1 */
/* #define _POSIX_THREAD_PRIO_PROTECT -1 */
#define _POSIX_THREAD_PRIORITY_SCHEDULING 200112L
#define _POSIX_THREAD_PROCESS_SHARED 200112L
#define _POSIX_THREAD_SAFE_FUNCTIONS 200112L
#define _POSIX_THREAD_PRIORITY_SCHEDULING 200809L
#define _POSIX_THREAD_PROCESS_SHARED 200809L
#define _POSIX_THREAD_SAFE_FUNCTIONS 200809L
/* #define _POSIX_THREAD_SPORADIC_SERVER -1 */
#define _POSIX_THREADS 200112L
#define _POSIX_THREADS 200809L
/* #define _POSIX_TIMEOUTS -1 */
#define _POSIX_TIMERS 1
/* #define _POSIX_TRACE -1 */
@ -164,9 +435,9 @@ extern "C" {
/* #define _POSIX_TRACE_LOG -1 */
/* #define _POSIX_TYPED_MEMORY_OBJECTS -1 */
#define _POSIX_VDISABLE '\0'
#define _POSIX2_C_BIND 200112L
#define _POSIX2_C_DEV 200112L
#define _POSIX2_CHAR_TERM 200112L
#define _POSIX2_C_BIND 200809L
#define _POSIX2_C_DEV 200809L
#define _POSIX2_CHAR_TERM 200809L
/* #define _POSIX2_FORT_DEV -1 */
/* #define _POSIX2_FORT_RUN -1 */
/* #define _POSIX2_LOCALEDEF -1 */
@ -176,8 +447,8 @@ extern "C" {
/* #define _POSIX2_PBS_LOCATE -1 */
/* #define _POSIX2_PBS_MESSAGE -1 */
/* #define _POSIX2_PBS_TRACK -1 */
#define _POSIX2_SW_DEV 200112L
#define _POSIX2_UPE 200112L
#define _POSIX2_SW_DEV 200809L
#define _POSIX2_UPE 200809L
#define _POSIX_V6_ILP32_OFF32 -1
#ifdef __LP64__
#define _POSIX_V6_ILP32_OFFBIG -1
@ -210,27 +481,6 @@ extern "C" {
#endif /* __CYGWIN__ */
/* Per the permission given in POSIX.1-2008 section 2.2.1, define
* _POSIX_C_SOURCE if _XOPEN_SOURCE is defined and _POSIX_C_SOURCE is not.
* (_XOPEN_SOURCE indicates that XSI extensions are desired by an application.)
* This permission is first granted in 2008, but use it for older ones, also.
* Allow for _XOPEN_SOURCE to be empty (from the earliest form of it, before it
* was required to have specific values).
*/
#if !defined(_POSIX_C_SOURCE) && defined(_XOPEN_SOURCE)
#if (_XOPEN_SOURCE - 0) == 700 /* POSIX.1-2008 */
#define _POSIX_C_SOURCE 200809L
#elif (_XOPEN_SOURCE - 0) == 600 /* POSIX.1-2001 or 2004 */
#define _POSIX_C_SOURCE 200112L
#elif (_XOPEN_SOURCE - 0) == 500 /* POSIX.1-1995 */
#define _POSIX_C_SOURCE 199506L
#elif (_XOPEN_SOURCE - 0) < 500 /* really old */
#define _POSIX_C_SOURCE 2
#endif
#endif
#define _POSIX_MONOTONIC_CLOCK 200112L
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,215 @@
/* Threads compatibility routines for libgcc2 and libobjc. */
/* Compile this one with gcc. */
/* Copyright (C) 1999-2015 Free Software Foundation, Inc.
Contributed by Mumit Khan <khan@xraylith.wisc.edu>.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
#ifndef GCC_GTHR_KOS32_H
#define GCC_GTHR_KOS32_H
/* Make sure CONST_CAST2 (origin in system.h) is declared. */
#ifndef CONST_CAST2
#define CONST_CAST2(TOTYPE,FROMTYPE,X) ((__extension__(union {FROMTYPE _q; TOTYPE _nq;})(X))._nq)
#endif
#define __GTHREADS 1
#include <stddef.h>
#ifndef __UNUSED_PARAM
#define __UNUSED_PARAM(x) x
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned long __gthread_key_t;
typedef struct
{
int done;
long started;
} __gthread_once_t;
typedef struct
{
volatile int lock;
int handle;
} __gthread_mutex_t;
typedef struct
{
volatile int lock;
int handle;
long depth;
unsigned long owner;
} __gthread_recursive_mutex_t;
#define __GTHREAD_ONCE_INIT {0, -1}
#define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function
#define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION \
__gthread_recursive_mutex_init_function
#if defined (_WIN32) && !defined(__CYGWIN__)
#define MINGW32_SUPPORTS_MT_EH 1
/* Mingw runtime >= v0.3 provides a magic variable that is set to nonzero
if -mthreads option was specified, or 0 otherwise. This is to get around
the lack of weak symbols in PE-COFF. */
extern int _CRT_MT;
extern int __mingwthr_key_dtor (unsigned long, void (*) (void *));
#endif /* _WIN32 && !__CYGWIN__ */
static inline int __gthread_active_p (void)
{
#ifdef MINGW32_SUPPORTS_MT_EH
return _CRT_MT;
#else
return 1;
#endif
}
extern int __gthr_kos32_once (__gthread_once_t *, void (*) (void));
extern int __gthr_kos32_key_create (__gthread_key_t *, void (*) (void*));
extern int __gthr_kos32_key_delete (__gthread_key_t);
extern void * __gthr_kos32_getspecific (__gthread_key_t);
extern int __gthr_kos32_setspecific (__gthread_key_t, const void *);
extern void __gthr_kos32_mutex_init_function (__gthread_mutex_t *);
extern int __gthr_kos32_mutex_lock (__gthread_mutex_t *);
extern int __gthr_kos32_mutex_trylock (__gthread_mutex_t *);
extern int __gthr_kos32_mutex_unlock (__gthread_mutex_t *);
extern void __gthr_kos32_recursive_mutex_init_function (__gthread_recursive_mutex_t *);
extern int __gthr_kos32_recursive_mutex_lock (__gthread_recursive_mutex_t *);
extern int __gthr_kos32_recursive_mutex_trylock (__gthread_recursive_mutex_t *);
extern int __gthr_kos32_recursive_mutex_unlock (__gthread_recursive_mutex_t *);
extern void __gthr_kos32_mutex_destroy (__gthread_mutex_t *);
extern int __gthr_kos32_recursive_mutex_destroy (__gthread_recursive_mutex_t *);
static inline int __gthread_once (__gthread_once_t *__once, void (*__func) (void))
{
if (__gthread_active_p ())
return __gthr_kos32_once (__once, __func);
else
return -1;
}
static inline int __gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *))
{
return __gthr_kos32_key_create (__key, __dtor);
}
static inline int __gthread_key_delete (__gthread_key_t __key)
{
return __gthr_kos32_key_delete (__key);
}
static inline void* __gthread_getspecific (__gthread_key_t __key)
{
return __gthr_kos32_getspecific (__key);
}
static inline int __gthread_setspecific (__gthread_key_t __key, const void *__ptr)
{
return __gthr_kos32_setspecific (__key, __ptr);
}
static inline void __gthread_mutex_init_function (__gthread_mutex_t *__mutex)
{
__gthr_kos32_mutex_init_function(__mutex);
}
static inline void __gthread_mutex_destroy (__gthread_mutex_t *__mutex)
{
__gthr_kos32_mutex_destroy (__mutex);
}
static inline int __gthread_mutex_lock (__gthread_mutex_t *__mutex)
{
if (__gthread_active_p ())
return __gthr_kos32_mutex_lock (__mutex);
else
return 0;
}
static inline int __gthread_mutex_trylock (__gthread_mutex_t *__mutex)
{
if (__gthread_active_p ())
return __gthr_kos32_mutex_trylock (__mutex);
else
return 0;
}
static inline int __gthread_mutex_unlock (__gthread_mutex_t *__mutex)
{
if (__gthread_active_p ())
return __gthr_kos32_mutex_unlock (__mutex);
else
return 0;
}
static inline void __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex)
{
__gthr_kos32_recursive_mutex_init_function (__mutex);
}
static inline int __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
{
if (__gthread_active_p ())
return __gthr_kos32_recursive_mutex_lock (__mutex);
else
return 0;
}
static inline int __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
{
if (__gthread_active_p ())
return __gthr_kos32_recursive_mutex_trylock (__mutex);
else
return 0;
}
static inline int __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
{
if (__gthread_active_p ())
return __gthr_kos32_recursive_mutex_unlock (__mutex);
else
return 0;
}
static inline int __gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex)
{
return __gthr_kos32_recursive_mutex_destroy (__mutex);
}
#ifdef __cplusplus
}
#endif
#endif /* ! GCC_GTHR_WIN32_H */

View File

@ -0,0 +1,154 @@
/* Threads compatibility routines for libgcc2. */
/* Compile this one with gcc. */
/* Copyright (C) 1997-2015 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
#ifndef _GLIBCXX_GCC_GTHR_H
#define _GLIBCXX_GCC_GTHR_H
#ifndef _GLIBCXX_HIDE_EXPORTS
#pragma GCC visibility push(default)
#endif
/* If this file is compiled with threads support, it must
#define __GTHREADS 1
to indicate that threads support is present. Also it has define
function
int __gthread_active_p ()
that returns 1 if thread system is active, 0 if not.
The threads interface must define the following types:
__gthread_key_t
__gthread_once_t
__gthread_mutex_t
__gthread_recursive_mutex_t
The threads interface must define the following macros:
__GTHREAD_ONCE_INIT
to initialize __gthread_once_t
__GTHREAD_MUTEX_INIT
to initialize __gthread_mutex_t to get a fast
non-recursive mutex.
__GTHREAD_MUTEX_INIT_FUNCTION
to initialize __gthread_mutex_t to get a fast
non-recursive mutex.
Define this to a function which looks like this:
void __GTHREAD_MUTEX_INIT_FUNCTION (__gthread_mutex_t *)
Some systems can't initialize a mutex without a
function call. Don't define __GTHREAD_MUTEX_INIT in this case.
__GTHREAD_RECURSIVE_MUTEX_INIT
__GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION
as above, but for a recursive mutex.
The threads interface must define the following static functions:
int __gthread_once (__gthread_once_t *once, void (*func) ())
int __gthread_key_create (__gthread_key_t *keyp, void (*dtor) (void *))
int __gthread_key_delete (__gthread_key_t key)
void *__gthread_getspecific (__gthread_key_t key)
int __gthread_setspecific (__gthread_key_t key, const void *ptr)
int __gthread_mutex_destroy (__gthread_mutex_t *mutex);
int __gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *mutex);
int __gthread_mutex_lock (__gthread_mutex_t *mutex);
int __gthread_mutex_trylock (__gthread_mutex_t *mutex);
int __gthread_mutex_unlock (__gthread_mutex_t *mutex);
int __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex);
int __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex);
int __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex);
The following are supported in POSIX threads only. They are required to
fix a deadlock in static initialization inside libsupc++. The header file
gthr-posix.h defines a symbol __GTHREAD_HAS_COND to signify that these extra
features are supported.
Types:
__gthread_cond_t
Macros:
__GTHREAD_COND_INIT
__GTHREAD_COND_INIT_FUNCTION
Interface:
int __gthread_cond_broadcast (__gthread_cond_t *cond);
int __gthread_cond_wait (__gthread_cond_t *cond, __gthread_mutex_t *mutex);
int __gthread_cond_wait_recursive (__gthread_cond_t *cond,
__gthread_recursive_mutex_t *mutex);
All functions returning int should return zero on success or the error
number. If the operation is not supported, -1 is returned.
If the following are also defined, you should
#define __GTHREADS_CXX0X 1
to enable the c++0x thread library.
Types:
__gthread_t
__gthread_time_t
Interface:
int __gthread_create (__gthread_t *thread, void *(*func) (void*),
void *args);
int __gthread_join (__gthread_t thread, void **value_ptr);
int __gthread_detach (__gthread_t thread);
int __gthread_equal (__gthread_t t1, __gthread_t t2);
__gthread_t __gthread_self (void);
int __gthread_yield (void);
int __gthread_mutex_timedlock (__gthread_mutex_t *m,
const __gthread_time_t *abs_timeout);
int __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *m,
const __gthread_time_t *abs_time);
int __gthread_cond_signal (__gthread_cond_t *cond);
int __gthread_cond_timedwait (__gthread_cond_t *cond,
__gthread_mutex_t *mutex,
const __gthread_time_t *abs_timeout);
*/
#if __GXX_WEAK__
/* The pe-coff weak support isn't fully compatible to ELF's weak.
For static libraries it might would work, but as we need to deal
with shared versions too, we disable it for mingw-targets. */
#ifdef __MINGW32__
#undef _GLIBCXX_GTHREAD_USE_WEAK
#define _GLIBCXX_GTHREAD_USE_WEAK 0
#endif
#ifndef _GLIBCXX_GTHREAD_USE_WEAK
#define _GLIBCXX_GTHREAD_USE_WEAK 1
#endif
#endif
#include <sys/gthr-default.h>
#ifndef _GLIBCXX_HIDE_EXPORTS
#pragma GCC visibility pop
#endif
#endif /* ! _GLIBCXX_GCC_GTHR_H */

View File

@ -1,69 +1,47 @@
#ifndef __SYS_LOCK_H__
#define __SYS_LOCK_H__
//#define _LIBC 1
#define NOT_IN_libc 1
#ifndef _SYS_LOCK_H_
#define _SYS_LOCK_H_
#ifndef __USE_GNU
#define __USE_GNU 1
#endif
#include <sys/cdefs.h>
#include <stddef.h>
#include <sys/gthr.h>
void __mutex_lock(volatile int *val);
typedef __gthread_mutex_t _LOCK_T;
typedef volatile int __libc_lock_t;
typedef struct { volatile int mutex; } __libc_lock_recursive_t;
typedef __gthread_recursive_mutex_t _LOCK_RECURSIVE_T;
#define __libc_lock_define(CLASS,NAME) \
CLASS __libc_lock_t NAME;
#define __libc_rwlock_define(CLASS,NAME) \
CLASS __libc_rwlock_t NAME;
#define __libc_lock_define_recursive(CLASS,NAME) \
CLASS __libc_lock_recursive_t NAME;
#define __rtld_lock_define_recursive(CLASS,NAME) \
CLASS __rtld_lock_recursive_t NAME;
#define _MUTEX_INITIALIZER { 0, -1 }
typedef __libc_lock_t _LOCK_T;
typedef __libc_lock_recursive_t _LOCK_RECURSIVE_T;
#define _MUTEX_RECURSIVE_INITIALIZER { 0,-1,0,0 }
#define __LOCK_INIT(class,lock) \
__libc_lock_define_initialized(class, lock)
#define __LOCK_INIT(_qualifier, _designator) \
_qualifier _LOCK_T _designator = _MUTEX_INITIALIZER
#define __LOCK_INIT_RECURSIVE(class, lock) \
__libc_lock_define_initialized_recursive(class, lock)
#define __LOCK_INIT_RECURSIVE(_qualifier, _designator) \
_qualifier _LOCK_RECURSIVE_T _designator = _MUTEX_RECURSIVE_INITIALIZER
#define __libc_lock_define_initialized(CLASS,NAME) \
CLASS __libc_lock_t NAME;
static inline int __libc_lock_acquire(_LOCK_T *lock)
{
if(lock->handle == -1)
__gthread_mutex_init_function(lock);
#define __libc_lock_define_initialized_recursive(CLASS,NAME) \
CLASS __libc_lock_recursive_t NAME = _LIBC_LOCK_RECURSIVE_INITIALIZER;
return __gthread_mutex_lock(lock);
}
#define _LIBC_LOCK_RECURSIVE_INITIALIZER {0}
static inline int __libc_lock_acquire_recursive(_LOCK_RECURSIVE_T *lock)
{
if(lock->handle == -1)
__gthread_recursive_mutex_init_function(lock);
#define __lock_init(__lock) __libc_lock_init(__lock)
#define __lock_init_recursive(__lock) __libc_lock_init_recursive(__lock)
#define __lock_acquire(__lock) __libc_lock_lock(__lock)
#define __lock_acquire_recursive(__lock) __libc_lock_lock_recursive(__lock)
#define __lock_release(__lock) __libc_lock_unlock(__lock)
#define __lock_release_recursive(__lock) __libc_lock_unlock_recursive(__lock)
#define __lock_try_acquire(__lock) __libc_lock_trylock(__lock)
#define __lock_try_acquire_recursive(__lock) \
__libc_lock_trylock_recursive(__lock)
#define __lock_close(__lock) __libc_lock_fini(__lock)
#define __lock_close_recursive(__lock) __libc_lock_fini_recursive(__lock)
return __gthread_recursive_mutex_lock(lock);
}
#define __lock_acquire(_lock) __libc_lock_acquire(&_lock)
#define __lock_release(_lock) __gthread_mutex_unlock(&_lock)
#define __libc_lock_init_recursive(NAME) ((NAME).mutex=0)
#define __libc_lock_fini(NAME)
#define __lock_init_recursive(_lock) __gthread_recursive_mutex_init_function(&_lock)
#define __lock_acquire_recursive(_lock) __libc_lock_acquire_recursive(&_lock)
#define __lock_release_recursive(_lock) __gthread_recursive_mutex_unlock(&_lock)
#define __lock_close_recursive(_lock) __gthread_recursive_mutex_destroy(&_lock)
#define __libc_lock_fini_recursive(NAME) __libc_lock_fini ((NAME).mutex)
#define __libc_lock_lock(NAME) __mutex_lock (&(NAME))
/* Lock the recursive named lock variable. */
#define __libc_lock_lock_recursive(NAME) __libc_lock_lock ((NAME).mutex)
#define __libc_lock_unlock(NAME) ((NAME)=0)
#define __libc_lock_unlock_recursive(NAME) __libc_lock_unlock ((NAME).mutex)
#endif /* __SYS_LOCK_H__ */
#endif /* _SYS_LOCK_H_ */

View File

@ -19,10 +19,9 @@ details. */
includes the W32api winsock[2].h header must know what it is doing;
it must not call the Cygwin select function.
*/
# if !(defined (_POSIX_SOURCE) || defined (_WINSOCK_H) || defined (_WINSOCKAPI_) || defined (__USE_W32_SOCKETS))
# if !(defined (_WINSOCK_H) || defined (_WINSOCKAPI_) || defined (__USE_W32_SOCKETS))
#include <sys/cdefs.h>
#include <sys/_sigset.h>
#include <sys/_timeval.h>
#include <sys/timespec.h>
@ -73,14 +72,16 @@ __BEGIN_DECLS
int select __P ((int __n, fd_set *__readfds, fd_set *__writefds,
fd_set *__exceptfds, struct timeval *__timeout));
#if __POSIX_VISIBLE >= 200112
int pselect __P ((int __n, fd_set *__readfds, fd_set *__writefds,
fd_set *__exceptfds, const struct timespec *__timeout,
const sigset_t *__set));
#endif
__END_DECLS
#endif
#endif /* !__INSIDE_CYGWIN_NET__ */
#endif /* !_POSIX_SOURCE, !__INSIDE_CYGWIN_NET__ */
#endif /* !(_WINSOCK_H || _WINSOCKAPI_ || __USE_W32_SOCKETS) */
#endif /* sys/select.h */

View File

@ -13,8 +13,6 @@ extern "C" {
#include <sys/_sigset.h>
#include <sys/_timespec.h>
/* #ifndef __STRICT_ANSI__*/
#if !defined(_SIGSET_T_DECLARED)
#define _SIGSET_T_DECLARED
typedef __sigset_t sigset_t;
@ -77,7 +75,7 @@ typedef struct {
#define SA_NOCLDSTOP 0x1 /* Do not generate SIGCHLD when children stop */
#define SA_SIGINFO 0x2 /* Invoke the signal catching function with */
/* three arguments instead of one. */
#if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
#if __BSD_VISIBLE || __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809
#define SA_ONSTACK 0x4 /* Signal delivery will be on a separate stack. */
#endif
@ -125,7 +123,7 @@ struct sigaction
};
#endif /* defined(__rtems__) */
#if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
#if __BSD_VISIBLE || __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809
/*
* Minimum and default signal stack constants. Allow for target overrides
* from <sys/features.h>.
@ -158,15 +156,6 @@ typedef struct sigaltstack {
#define SIG_BLOCK 1 /* set of signals to block */
#define SIG_UNBLOCK 2 /* set of signals to, well, unblock */
/* These depend upon the type of sigset_t, which right now
is always a long.. They're in the POSIX namespace, but
are not ANSI. */
#define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0)
#define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0)
#define sigemptyset(what) (*(what) = 0, 0)
#define sigfillset(what) (*(what) = ~(0), 0)
#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0)
int _EXFUN(sigprocmask, (int how, const sigset_t *set, sigset_t *oset));
#if defined(_POSIX_THREADS)
@ -174,12 +163,6 @@ int _EXFUN(pthread_sigmask, (int how, const sigset_t *set, sigset_t *oset));
#endif
#if defined(__CYGWIN__) || defined(__rtems__)
#undef sigaddset
#undef sigdelset
#undef sigemptyset
#undef sigfillset
#undef sigismember
#ifdef _COMPILING_NEWLIB
int _EXFUN(_kill, (pid_t, int));
#endif /* _COMPILING_NEWLIB */
@ -187,7 +170,7 @@ int _EXFUN(_kill, (pid_t, int));
int _EXFUN(kill, (pid_t, int));
#if defined(__CYGWIN__) || defined(__rtems__)
#if __BSD_VISIBLE || __XSI_VISIBLE >= 4
int _EXFUN(killpg, (pid_t, int));
int _EXFUN(sigaction, (int, const struct sigaction *, struct sigaction *));
int _EXFUN(sigaddset, (sigset_t *, const int));
@ -199,11 +182,21 @@ int _EXFUN(sigpending, (sigset_t *));
int _EXFUN(sigsuspend, (const sigset_t *));
int _EXFUN(sigpause, (int));
#if defined(__CYGWIN__) || defined(__rtems__)
#if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
#if !defined(__CYGWIN__) && !defined(__rtems__)
/* These depend upon the type of sigset_t, which right now
is always a long.. They're in the POSIX namespace, but
are not ANSI. */
#define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0)
#define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0)
#define sigemptyset(what) (*(what) = 0, 0)
#define sigfillset(what) (*(what) = ~(0), 0)
#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0)
#endif /* !__CYGWIN__ && !__rtems__ */
#endif /* __BSD_VISIBLE || __XSI_VISIBLE >= 4 */
#if __BSD_VISIBLE || __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809
int _EXFUN(sigaltstack, (const stack_t *__restrict, stack_t *__restrict));
#endif
#endif
#if defined(_POSIX_THREADS)
#ifdef __CYGWIN__
@ -230,10 +223,6 @@ int _EXFUN(sigqueue, (pid_t pid, int signo, const union sigval value));
#endif /* defined(_POSIX_REALTIME_SIGNALS) */
#endif /* defined(__CYGWIN__) || defined(__rtems__) */
/* #endif __STRICT_ANSI__ */
#if defined(___AM29K__)
/* These all need to be defined for ANSI C, but I don't think they are
meaningful. */
@ -354,7 +343,7 @@ int _EXFUN(sigqueue, (pid_t pid, int signo, const union sigval value));
#endif
#if defined(__CYGWIN__)
#if __POSIX_VISIBLE >= 200809
#if __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809
#include <sys/ucontext.h>
#endif
#endif

View File

@ -82,12 +82,12 @@ struct stat
#define S_ISUID 0004000 /* set user id on execution */
#define S_ISGID 0002000 /* set group id on execution */
#define S_ISVTX 0001000 /* save swapped text even after use */
#ifndef _POSIX_SOURCE
#if __BSD_VISIBLE
#define S_IREAD 0000400 /* read permission, owner */
#define S_IWRITE 0000200 /* write permission, owner */
#define S_IEXEC 0000100 /* execute/search permission, owner */
#define S_ENFMT 0002000 /* enforcement-mode locking */
#endif /* !_POSIX_SOURCE */
#endif /* !_BSD_VISIBLE */
#define S_IFMT _IFMT
#define S_IFDIR _IFDIR
@ -124,7 +124,7 @@ struct stat
#define S_IWOTH 0000002 /* write permission, other */
#define S_IXOTH 0000001/* execute/search permission, other */
#ifndef _POSIX_SOURCE
#if __BSD_VISIBLE
#define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */
#define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */
#define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */
@ -144,6 +144,8 @@ struct stat
#define UTIME_OMIT -1L
#endif
int _EXFUN(chmod,( const char *__path, mode_t __mode ));
int _EXFUN(fchmod,(int __fd, mode_t __mode));
int _EXFUN(fstat,( int __fd, struct stat *__sbuf ));
int _EXFUN(mkdir,( const char *_path, mode_t __mode ));
int _EXFUN(mkfifo,( const char *__path, mode_t __mode ));
@ -155,19 +157,15 @@ int _EXFUN(lstat,( const char *__restrict __path, struct stat *__restrict __buf
int _EXFUN(mknod,( const char *__path, mode_t __mode, dev_t __dev ));
#endif
#if (__POSIX_VISIBLE >= 200809 || defined (__CYGWIN__)) && !defined(__INSIDE_CYGWIN__)
#if __ATFILE_VISIBLE && !defined(__INSIDE_CYGWIN__)
int _EXFUN(fchmodat, (int, const char *, mode_t, int));
#endif
#if (__BSD_VISIBLE || __POSIX_VISIBLE >= 200809 || defined (__CYGWIN__)) && !defined(__INSIDE_CYGWIN__)
int _EXFUN(fstatat, (int, const char *__restrict , struct stat *__restrict, int));
int _EXFUN(mkdirat, (int, const char *, mode_t));
int _EXFUN(mkfifoat, (int, const char *, mode_t));
#endif
#if (__BSD_VISIBLE || __XSI_VISIBLE >= 700 || defined (__CYGWIN__)) && !defined(__INSIDE_CYGWIN__)
int _EXFUN(mknodat, (int, const char *, mode_t, dev_t));
#endif
#if (__BSD_VISIBLE || __POSIX_VISIBLE >= 200809 || defined (__CYGWIN__)) && !defined(__INSIDE_CYGWIN__)
int _EXFUN(utimensat, (int, const char *, const struct timespec *, int));
#endif
#if __POSIX_VISIBLE >= 200809 && !defined(__INSIDE_CYGWIN__)
int _EXFUN(futimens, (int, const struct timespec *));
#endif

View File

@ -9,11 +9,11 @@
detect if FILE is private to sprintf/sscanf class of functions; if
set then do nothing as lock is not initialised. */
#if !defined(_flockfile)
//#ifndef __SINGLE_THREAD__
//# define _flockfile(fp) (((fp)->_flags & __SSTR) ? 0 : __lock_acquire_recursive((fp)->_lock))
//#else
#ifndef __SINGLE_THREAD__
# define _flockfile(fp) (((fp)->_flags & __SSTR) ? 0 : __lock_acquire_recursive((fp)->_lock))
#else
# define _flockfile(fp) (_CAST_VOID 0)
//#endif
#endif
#endif
#if !defined(_funlockfile)

View File

@ -43,7 +43,7 @@
#include <sys/types.h>
#include <sys/timespec.h>
#if __BSD_VISIBLE
#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE
#include <sys/select.h>
#endif
@ -416,24 +416,27 @@ int tvtohz(struct timeval *tv);
#include <sys/cdefs.h>
__BEGIN_DECLS
int _EXFUN(setitimer, (int __which, const struct itimerval *__restrict __value,
struct itimerval *__restrict __ovalue));
int _EXFUN(utimes, (const char *__path, const struct timeval *__tvp));
#if __BSD_VISIBLE
int _EXFUN(adjtime, (const struct timeval *, struct timeval *));
int _EXFUN(futimes, (int, const struct timeval *));
int _EXFUN(futimesat, (int, const char *, const struct timeval [2]));
int _EXFUN(lutimes, (const char *, const struct timeval *));
int _EXFUN(settimeofday, (const struct timeval *, const struct timezone *));
#endif
#if __XSI_VISIBLE
#if __MISC_VISIBLE || __XSI_VISIBLE
int _EXFUN(getitimer, (int __which, struct itimerval *__value));
int _EXFUN(setitimer, (int __which, const struct itimerval *__restrict __value,
struct itimerval *__restrict __ovalue));
int _EXFUN(gettimeofday, (struct timeval *__restrict __p,
void *__restrict __tz));
#endif
#if __GNU_VISIBLE
int _EXFUN(futimesat, (int, const char *, const struct timeval [2]));
#endif
#ifdef _COMPILING_NEWLIB
int _EXFUN(_gettimeofday, (struct timeval *__p, void *__tz));
#endif

View File

@ -18,21 +18,12 @@
#ifndef _SYS_TYPES_H
#include <_ansi.h>
# include <sys/cdefs.h>
#ifndef __INTTYPES_DEFINED__
#define __INTTYPES_DEFINED__
#include <sys/cdefs.h>
#include <machine/_types.h>
#if defined(__rtems__) || defined(__XMK__)
/*
* The following section is RTEMS specific and is needed to more
* closely match the types defined in the BSD sys/types.h.
* This is needed to let the RTEMS/BSD TCP/IP stack compile.
*/
/* deprecated */
/* BSD types permitted by POSIX and always exposed as in Glibc. Only provided
for backward compatibility with BSD code. The uintN_t standard types should
be preferred in new code. */
#if ___int8_t_defined
typedef __uint8_t u_int8_t;
#endif
@ -42,19 +33,25 @@ typedef __uint16_t u_int16_t;
#if ___int32_t_defined
typedef __uint32_t u_int32_t;
#endif
#if ___int64_t_defined
typedef __uint64_t u_int64_t;
#endif
#if defined(__rtems__) || defined(__XMK__)
/*
* The following section is RTEMS specific and is needed to more
* closely match the types defined in the BSD sys/types.h.
* This is needed to let the RTEMS/BSD TCP/IP stack compile.
*/
/* deprecated */
#if ___int64_t_defined
typedef __uint64_t u_quad_t;
typedef __int64_t quad_t;
typedef quad_t * qaddr_t;
#endif
#endif
#endif /* ! __INTTYPES_DEFINED */
#endif /* __rtems__ || __XMK__ */
#ifndef __need_inttypes
@ -84,11 +81,13 @@ typedef quad_t * qaddr_t;
#define _ST_INT32
#endif
# if __BSD_VISIBLE
#if __BSD_VISIBLE
#include <sys/select.h>
# define physadr physadr_t
# define quad quad_t
#endif
#if __MISC_VISIBLE
#ifndef _BSDTYPES_DEFINED
/* also defined in mingw/gmon.h and in w32api/winsock[2].h */
#ifndef __u_char_defined
@ -109,11 +108,13 @@ typedef unsigned long u_long;
#endif
#define _BSDTYPES_DEFINED
#endif
#endif /*__BSD_VISIBLE || __CYGWIN__ */
#if __MISC_VISIBLE
typedef unsigned short ushort; /* System V compatibility */
typedef unsigned int uint; /* System V compatibility */
typedef unsigned long ulong; /* System V compatibility */
# endif /*__BSD_VISIBLE */
#endif
#ifndef __clock_t_defined
typedef _CLOCK_T_ clock_t;
@ -187,7 +188,11 @@ typedef _mode_t mode_t;
#ifndef __CYGWIN__
typedef long key_t;
#endif
#ifndef _SSIZE_T_DECLARED
typedef _ssize_t ssize_t;
#define _SSIZE_T_DECLARED
#endif
#if !defined(__CYGWIN__) && !defined(__rtems__)
#ifdef __MS_types__
@ -410,6 +415,7 @@ typedef __uint32_t pthread_cond_t; /* identify a condition variable */
typedef struct {
int is_initialized;
clock_t clock; /* specifiy clock for timeouts */
#if defined(_POSIX_THREAD_PROCESS_SHARED)
int process_shared; /* allow this to be shared amongst processes */
#endif
@ -431,6 +437,7 @@ typedef struct {
/* POSIX Barrier Types */
#if !defined(__CYGWIN__)
#if defined(_POSIX_BARRIERS)
typedef __uint32_t pthread_barrier_t; /* POSIX Barrier Object */
typedef struct {
@ -443,7 +450,6 @@ typedef struct {
/* POSIX Spin Lock Types */
#if !defined (__CYGWIN__)
#if defined(_POSIX_SPIN_LOCKS)
typedef __uint32_t pthread_spinlock_t; /* POSIX Spin Lock Object */
#endif /* defined(_POSIX_SPIN_LOCKS) */

View File

@ -24,72 +24,79 @@ int _EXFUN(chmod, (const char *__path, mode_t __mode ));
#if !defined(__INSIDE_CYGWIN__)
int _EXFUN(chown, (const char *__path, uid_t __owner, gid_t __group ));
#endif
#if defined(__CYGWIN__) || defined(__rtems__)
#if __BSD_VISIBLE || (__XSI_VISIBLE >= 4 && __POSIX_VISIBLE < 200112)
int _EXFUN(chroot, (const char *__path ));
#endif
int _EXFUN(close, (int __fildes ));
#if defined(__CYGWIN__)
#if __POSIX_VISIBLE >= 199209
size_t _EXFUN(confstr, (int __name, char *__buf, size_t __len));
#endif
char * _EXFUN(ctermid, (char *__s ));
char * _EXFUN(cuserid, (char *__s ));
#if defined(__CYGWIN__)
#if __BSD_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 500)
int _EXFUN(daemon, (int nochdir, int noclose));
#endif
int _EXFUN(dup, (int __fildes ));
int _EXFUN(dup2, (int __fildes, int __fildes2 ));
#if defined(__CYGWIN__)
#if __GNU_VISIBLE
int _EXFUN(dup3, (int __fildes, int __fildes2, int flags));
int _EXFUN(eaccess, (const char *__path, int __mode));
#endif
#if __BSD_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 500)
void _EXFUN(endusershell, (void));
#endif
#if __GNU_VISIBLE
int _EXFUN(euidaccess, (const char *__path, int __mode));
#endif
int _EXFUN(execl, (const char *__path, const char *, ... ));
int _EXFUN(execle, (const char *__path, const char *, ... ));
int _EXFUN(execlp, (const char *__file, const char *, ... ));
#if defined(__CYGWIN__)
#if __MISC_VISIBLE
int _EXFUN(execlpe, (const char *__file, const char *, ... ));
#endif
int _EXFUN(execv, (const char *__path, char * const __argv[] ));
int _EXFUN(execve, (const char *__path, char * const __argv[], char * const __envp[] ));
int _EXFUN(execvp, (const char *__file, char * const __argv[] ));
#if defined(__CYGWIN__)
#if __GNU_VISIBLE
int _EXFUN(execvpe, (const char *__file, char * const __argv[], char * const __envp[] ));
#endif
#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE || defined(__CYGWIN__)
#if __ATFILE_VISIBLE
int _EXFUN(faccessat, (int __dirfd, const char *__path, int __mode, int __flags));
#endif
#if defined(__CYGWIN__) || defined(__rtems__) || defined(__SPU__)
#if __BSD_VISIBLE || __XSI_VISIBLE >= 4
int _EXFUN(fchdir, (int __fildes));
#endif
int _EXFUN(fchmod, (int __fildes, mode_t __mode ));
#if !defined(__INSIDE_CYGWIN__)
int _EXFUN(fchown, (int __fildes, uid_t __owner, gid_t __group ));
#endif
#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE || defined(__CYGWIN__)
#if __ATFILE_VISIBLE
int _EXFUN(fchownat, (int __dirfd, const char *__path, uid_t __owner, gid_t __group, int __flags));
#endif
#if defined(__CYGWIN__)
#if __POSIX_VISIBLE >= 200809
int _EXFUN(fexecve, (int __fd, char * const __argv[], char * const __envp[] ));
#endif
pid_t _EXFUN(fork, (void ));
long _EXFUN(fpathconf, (int __fd, int __name ));
int _EXFUN(fsync, (int __fd));
int _EXFUN(fdatasync, (int __fd));
#if defined(__CYGWIN__)
#if __GNU_VISIBLE
char * _EXFUN(get_current_dir_name, (void));
#endif
char * _EXFUN(getcwd, (char *__buf, size_t __size ));
#if defined(__CYGWIN__)
#if __BSD_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 500)
int _EXFUN(getdomainname ,(char *__name, size_t __len));
#endif
#if __BSD_VISIBLE
int _EXFUN(getentropy, (void *, size_t));
#endif
#if !defined(__INSIDE_CYGWIN__)
gid_t _EXFUN(getegid, (void ));
uid_t _EXFUN(geteuid, (void ));
gid_t _EXFUN(getgid, (void ));
#endif
int _EXFUN(getgroups, (int __gidsetsize, gid_t __grouplist[] ));
#if defined(__CYGWIN__)
#if __BSD_VISIBLE || __XSI_VISIBLE >= 4
long _EXFUN(gethostid, (void));
#endif
char * _EXFUN(getlogin, (void ));
@ -98,22 +105,26 @@ int _EXFUN(getlogin_r, (char *name, size_t namesize) );
#endif
char * _EXFUN(getpass, (const char *__prompt));
int _EXFUN(getpagesize, (void));
#if defined(__CYGWIN__)
#if __BSD_VISIBLE
int _EXFUN(getpeereid, (int, uid_t *, gid_t *));
#endif
pid_t _EXFUN(getpgid, (pid_t));
pid_t _EXFUN(getpgrp, (void ));
pid_t _EXFUN(getpid, (void ));
pid_t _EXFUN(getppid, (void ));
#if defined(__CYGWIN__) || defined(__rtems__)
#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 4
pid_t _EXFUN(getsid, (pid_t));
#endif
#if !defined(__INSIDE_CYGWIN__)
uid_t _EXFUN(getuid, (void ));
#endif
#ifdef __CYGWIN__
#if __BSD_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 500)
char * _EXFUN(getusershell, (void));
#endif
#if __BSD_VISIBLE || (__XSI_VISIBLE >= 4 && __POSIX_VISIBLE < 200809)
char * _EXFUN(getwd, (char *__buf ));
#endif
#if __BSD_VISIBLE
int _EXFUN(iruserok, (unsigned long raddr, int superuser, const char *ruser, const char *luser));
#endif
int _EXFUN(isatty, (int __fildes ));
@ -124,14 +135,14 @@ int _EXFUN(issetugid, (void));
int _EXFUN(lchown, (const char *__path, uid_t __owner, gid_t __group ));
#endif
int _EXFUN(link, (const char *__path1, const char *__path2 ));
#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE || defined(__CYGWIN__)
#if __ATFILE_VISIBLE
int _EXFUN(linkat, (int __dirfd1, const char *__path1, int __dirfd2, const char *__path2, int __flags ));
#endif
int _EXFUN(nice, (int __nice_value ));
#if !defined(__INSIDE_CYGWIN__)
off_t _EXFUN(lseek, (int __fildes, off_t __offset, int __whence ));
#endif
#if defined(__SPU__) || defined(__CYGWIN__)
#if __MISC_VISIBLE || __XSI_VISIBLE >= 4
#define F_ULOCK 0
#define F_LOCK 1
#define F_TLOCK 2
@ -140,41 +151,41 @@ int _EXFUN(lockf, (int __fd, int __cmd, off_t __len));
#endif
long _EXFUN(pathconf, (const char *__path, int __name ));
int _EXFUN(pause, (void ));
#ifdef __CYGWIN__
#if __POSIX_VISIBLE >= 199506
int _EXFUN(pthread_atfork, (void (*)(void), void (*)(void), void (*)(void)));
#endif
int _EXFUN(pipe, (int __fildes[2] ));
#ifdef __CYGWIN__
#if __GNU_VISIBLE
int _EXFUN(pipe2, (int __fildes[2], int flags));
#endif
ssize_t _EXFUN(pread, (int __fd, void *__buf, size_t __nbytes, off_t __offset));
ssize_t _EXFUN(pwrite, (int __fd, const void *__buf, size_t __nbytes, off_t __offset));
_READ_WRITE_RETURN_TYPE _EXFUN(read, (int __fd, void *__buf, size_t __nbyte ));
#if defined(__CYGWIN__)
#if __BSD_VISIBLE
int _EXFUN(rresvport, (int *__alport));
int _EXFUN(revoke, (char *__path));
#endif
int _EXFUN(rmdir, (const char *__path ));
#if defined(__CYGWIN__)
#if __BSD_VISIBLE
int _EXFUN(ruserok, (const char *rhost, int superuser, const char *ruser, const char *luser));
#endif
void * _EXFUN(sbrk, (ptrdiff_t __incr));
#if !defined(__INSIDE_CYGWIN__)
#if defined(__CYGWIN__) || defined(__rtems__)
#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112
int _EXFUN(setegid, (gid_t __gid ));
int _EXFUN(seteuid, (uid_t __uid ));
#endif
int _EXFUN(setgid, (gid_t __gid ));
#endif
#if defined(__CYGWIN__)
#if __BSD_VISIBLE
int _EXFUN(setgroups, (int ngroups, const gid_t *grouplist ));
#endif
#if __BSD_VISIBLE || (defined(_XOPEN_SOURCE) && __XSI_VISIBLE < 500)
#if __BSD_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 500)
int _EXFUN(sethostname, (const char *, size_t));
#endif
int _EXFUN(setpgid, (pid_t __pid, pid_t __pgid ));
int _EXFUN(setpgrp, (void ));
#if defined(__CYGWIN__) && !defined(__INSIDE_CYGWIN__)
#if (__BSD_VISIBLE || __XSI_VISIBLE >= 4) && !defined(__INSIDE_CYGWIN__)
int _EXFUN(setregid, (gid_t __rgid, gid_t __egid));
int _EXFUN(setreuid, (uid_t __ruid, uid_t __euid));
#endif
@ -182,7 +193,7 @@ pid_t _EXFUN(setsid, (void ));
#if !defined(__INSIDE_CYGWIN__)
int _EXFUN(setuid, (uid_t __uid ));
#endif
#if defined(__CYGWIN__)
#if __BSD_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 500)
void _EXFUN(setusershell, (void));
#endif
unsigned _EXFUN(sleep, (unsigned int __seconds ));
@ -191,9 +202,7 @@ long _EXFUN(sysconf, (int __name ));
pid_t _EXFUN(tcgetpgrp, (int __fildes ));
int _EXFUN(tcsetpgrp, (int __fildes, pid_t __pgrp_id ));
char * _EXFUN(ttyname, (int __fildes ));
#if defined(__CYGWIN__) || defined(__rtems__)
int _EXFUN(ttyname_r, (int, char *, size_t));
#endif
int _EXFUN(unlink, (const char *__path ));
int _EXFUN(usleep, (useconds_t __useconds));
int _EXFUN(vhangup, (void ));
@ -210,9 +219,9 @@ int getopt(int, char * const [], const char *);
extern int optreset; /* getopt(3) external variable */
#endif
#ifndef _POSIX_SOURCE
#if __BSD_VISIBLE || (__XSI_VISIBLE >= 4 && __POSIX_VISIBLE < 200809)
pid_t _EXFUN(vfork, (void ));
#endif /* _POSIX_SOURCE */
#endif
#ifdef _COMPILING_NEWLIB
/* Provide prototypes for most of the _<systemcall> names that are
@ -255,14 +264,14 @@ char * _EXFUN(mktemp, (char *));
void _EXFUN(sync, (void));
#endif
#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 4
ssize_t _EXFUN(readlink, (const char *__restrict __path,
char *__restrict __buf, size_t __buflen));
#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE || defined(__CYGWIN__)
int _EXFUN(symlink, (const char *__name1, const char *__name2));
#endif
#if __ATFILE_VISIBLE
ssize_t _EXFUN(readlinkat, (int __dirfd1, const char *__restrict __path,
char *__restrict __buf, size_t __buflen));
#endif
int _EXFUN(symlink, (const char *__name1, const char *__name2));
#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE || defined(__CYGWIN__)
int _EXFUN(symlinkat, (const char *, int, const char *));
int _EXFUN(unlinkat, (int, const char *, int));
#endif

View File

@ -79,7 +79,7 @@
__tg_type3(__e1, __e2, __e3, long double _Complex) || \
__tg_type3(__e1, __e2, __e3, __typeof__(_Complex_I)))
#ifdef _LDBL_EQ_DBL
#if defined (_LDBL_EQ_DBL) || defined (__CYGWIN__)
#define __tg_impl_simple(x, y, z, fn, fnf, fnl, ...) \
__builtin_choose_expr(__tg_type_corr(x, y, z, long double), \
fnl(__VA_ARGS__), __builtin_choose_expr( \
@ -161,9 +161,10 @@
#define lround(__x) __tg_simple(__x, lround)
#define nearbyint(__x) __tg_simple(__x, nearbyint)
#define nextafter(__x, __y) __tg_simple2(__x, __y, nextafter)
/* not yet implemented even for _LDBL_EQ_DBL platforms
/* not yet implemented even for _LDBL_EQ_DBL platforms */
#ifdef __CYGWIN__
#define nexttoward(__x, __y) __tg_simplev(__x, nexttoward, __x, __y)
*/
#endif
#define remainder(__x, __y) __tg_simple2(__x, __y, remainder)
#define remquo(__x, __y, __z) __tg_impl_simple(__x, __x, __y, remquo, remquof, \
remquol, __x, __y, __z)

View File

@ -8,6 +8,7 @@
#define _TIME_H_
#include "_ansi.h"
#include <sys/cdefs.h>
#include <sys/reent.h>
#define __need_size_t
@ -76,11 +77,14 @@ _END_STD_C
extern "C" {
#endif
#ifndef __STRICT_ANSI__
#if __XSI_VISIBLE
char *_EXFUN(strptime, (const char *__restrict,
const char *__restrict,
struct tm *__restrict));
#endif
#if __POSIX_VISIBLE
_VOID _EXFUN(tzset, (_VOID));
#endif
_VOID _EXFUN(_tzset_r, (struct _reent *));
typedef struct __tzrule_struct
@ -106,6 +110,7 @@ __tzinfo_type *_EXFUN (__gettzinfo, (_VOID));
/* getdate functions */
#ifdef HAVE_GETDATE
#if __XSI_VISIBLE >= 4
#ifndef _REENT_ONLY
#define getdate_err (*__getdate_err())
int *_EXFUN(__getdate_err,(_VOID));
@ -121,21 +126,27 @@ struct tm * _EXFUN(getdate, (const char *));
7 there is no line in the template that matches the input,
8 invalid input specification */
#endif /* !_REENT_ONLY */
#endif /* __XSI_VISIBLE >= 4 */
#if __GNU_VISIBLE
/* getdate_r returns the error code as above */
int _EXFUN(getdate_r, (const char *, struct tm *));
#endif /* __GNU_VISIBLE */
#endif /* HAVE_GETDATE */
/* defines for the opengroup specifications Derived from Issue 1 of the SVID. */
#if __SVID_VISIBLE || __XSI_VISIBLE
extern __IMPORT long _timezone;
extern __IMPORT int _daylight;
#endif
#if __POSIX_VISIBLE
extern __IMPORT char *_tzname[2];
/* POSIX defines the external tzname being defined in time.h */
#ifndef tzname
#define tzname _tzname
#endif
#endif /* !__STRICT_ANSI__ */
#endif /* __POSIX_VISIBLE */
#ifdef __cplusplus
}

View File

@ -189,7 +189,9 @@ wint_t _EXFUN(putwc_unlocked, (wchar_t, __FILE *));
wint_t _EXFUN(putwchar_unlocked, (wchar_t));
#endif
#if __POSIX_VISIBLE >= 200809
__FILE *_EXFUN (open_wmemstream, (wchar_t **, size_t *));
#endif
__FILE *_EXFUN (_open_wmemstream_r, (struct _reent *, wchar_t **, size_t *));
#ifndef __VALIST

View File

@ -1,5 +1,5 @@
OUTPUT_FORMAT(pei-i386)
SEARCH_DIR("=/mingw32/lib")
ENTRY("_libc_crt_startup")

View File

@ -175,6 +175,8 @@ split_lines(char *p, const char *plim) {
for (i = 0; p < plim; i++) {
p = strchr(p, '\n');
if (!p)
break;
*p++ = '\0';
}
return i;

View File

@ -345,7 +345,7 @@ void* create_image(void *raw)
int link_image(void *img_base, PIMAGE_IMPORT_DESCRIPTOR imp)
{
static jmp_buf loader_env;
static recursion = -1;
static int recursion = -1;
int warn = 0;
recursion++;

View File

@ -2,9 +2,10 @@
#include <_ansi.h>
#include <string.h>
#include <reent.h>
#include <sys/reent.h>
#include <kos32sys.h>
extern _VOID _EXFUN(__sinit,(struct _reent *));
void init_reent()
{

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2014 Red Hat, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <_ansi.h>
#include <stdio.h>
#include "local.h"
/* A subroutine version of the macro clearerr_unlocked. */
#undef clearerr_unlocked
_VOID
_DEFUN(clearerr_unlocked, (fp),
FILE * fp)
{
CHECK_INIT(_REENT, fp);
__sclearerr (fp);
}

View File

@ -0,0 +1,81 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
FUNCTION
<<fcloseall>>---close all files
INDEX
fcloseall
INDEX
_fcloseall_r
ANSI_SYNOPSIS
#include <stdio.h>
int fcloseall(void);
int _fcloseall_r (struct _reent *<[ptr]>);
TRAD_SYNOPSIS
#include <stdio.h>
int fcloseall()
int _fcloseall_r (<[ptr]>)
struct _reent *<[ptr]>;
DESCRIPTION
<<fcloseall>> closes all files in the current reentrancy struct's domain.
The function <<_fcloseall_r>> is the same function, except the reentrancy
struct is passed in as the <[ptr]> argument.
This function is not recommended as it closes all streams, including
the std streams.
RETURNS
<<fclose>> returns <<0>> if all closes are successful. Otherwise,
EOF is returned.
PORTABILITY
<<fcloseall>> is a glibc extension.
Required OS subroutines: <<close>>, <<fstat>>, <<isatty>>, <<lseek>>,
<<read>>, <<sbrk>>, <<write>>.
*/
/* This file based upon fwalk.c. */
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "local.h"
int
_DEFUN(_fcloseall_r, (ptr),
struct _reent *ptr)
{
return _fwalk_reent (ptr, _fclose_r);
}
#ifndef _REENT_ONLY
int
_DEFUN_VOID(fcloseall)
{
return _fcloseall_r (_GLOBAL_REENT);
}
#endif

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2014 Red Hat, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdio.h>
#include "local.h"
/* A subroutine version of the macro feof_unlocked. */
#undef feof_unlocked
int
_DEFUN(feof_unlocked, (fp),
FILE * fp)
{
CHECK_INIT(_REENT, fp);
return __sfeof (fp);
}

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2014 Red Hat, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <_ansi.h>
#include <stdio.h>
#include "local.h"
/* A subroutine version of the macro ferror_unlocked. */
#undef ferror_unlocked
int
_DEFUN(ferror_unlocked, (fp),
FILE * fp)
{
CHECK_INIT(_REENT, fp);
return __sferror (fp);
}

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2014 Red Hat, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#define __IMPL_UNLOCKED__
#include "fflush.c"

View File

@ -0,0 +1,56 @@
/*
* Copyright (c) 2014 Red Hat, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <_ansi.h>
#include <stdio.h>
#include "local.h"
int
_DEFUN(_fgetc_unlocked_r, (ptr, fp),
struct _reent * ptr _AND
FILE * fp)
{
CHECK_INIT(ptr, fp);
return __sgetc_r (ptr, fp);
}
#ifndef _REENT_ONLY
int
_DEFUN(fgetc_unlocked, (fp),
FILE * fp)
{
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
struct _reent *reent = _REENT;
CHECK_INIT(reent, fp);
return __sgetc_r (reent, fp);
#else
return _fgetc_unlocked_r (_REENT, fp);
#endif
}
#endif /* !_REENT_ONLY */

View File

@ -0,0 +1,103 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
FUNCTION
<<fgetpos>>---record position in a stream or file
INDEX
fgetpos
INDEX
_fgetpos_r
ANSI_SYNOPSIS
#include <stdio.h>
int fgetpos(FILE *restrict <[fp]>, fpos_t *restrict <[pos]>);
int _fgetpos_r(struct _reent *<[ptr]>, FILE *restrict <[fp]>, fpos_t *restrict <[pos]>);
TRAD_SYNOPSIS
#include <stdio.h>
int fgetpos(<[fp]>, <[pos]>)
FILE *<[fp]>;
fpos_t *<[pos]>;
int _fgetpos_r(<[ptr]>, <[fp]>, <[pos]>)
struct _reent *<[ptr]>;
FILE *<[fp]>;
fpos_t *<[pos]>;
DESCRIPTION
Objects of type <<FILE>> can have a ``position'' that records how much
of the file your program has already read. Many of the <<stdio>> functions
depend on this position, and many change it as a side effect.
You can use <<fgetpos>> to report on the current position for a file
identified by <[fp]>; <<fgetpos>> will write a value
representing that position at <<*<[pos]>>>. Later, you can
use this value with <<fsetpos>> to return the file to this
position.
In the current implementation, <<fgetpos>> simply uses a character
count to represent the file position; this is the same number that
would be returned by <<ftell>>.
RETURNS
<<fgetpos>> returns <<0>> when successful. If <<fgetpos>> fails, the
result is <<1>>. Failure occurs on streams that do not support
positioning; the global <<errno>> indicates this condition with the
value <<ESPIPE>>.
PORTABILITY
<<fgetpos>> is required by the ANSI C standard, but the meaning of the
value it records is not specified beyond requiring that it be
acceptable as an argument to <<fsetpos>>. In particular, other
conforming C implementations may return a different result from
<<ftell>> than what <<fgetpos>> writes at <<*<[pos]>>>.
No supporting OS subroutines are required.
*/
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
int
_DEFUN(_fgetpos_r, (ptr, fp, pos),
struct _reent * ptr _AND
FILE *__restrict fp _AND
_fpos_t *__restrict pos)
{
*pos = _ftell_r (ptr, fp);
if (*pos != -1)
{
return 0;
}
return 1;
}
#ifndef _REENT_ONLY
int
_DEFUN(fgetpos, (fp, pos),
FILE *__restrict fp _AND
_fpos_t *__restrict pos)
{
return _fgetpos_r (_REENT, fp, pos);
}
#endif /* !_REENT_ONLY */

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2014 Red Hat, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#define __IMPL_UNLOCKED__
#include "fgets.c"

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2014 Red Hat, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <_ansi.h>
#include <stdio.h>
#include <errno.h>
#include "local.h"
int
_DEFUN(fileno_unlocked, (f),
FILE * f)
{
int result;
CHECK_INIT (_REENT, f);
if (f->_flags)
result = __sfileno (f);
else
{
result = -1;
_REENT->_errno = EBADF;
}
return result;
}

View File

@ -267,25 +267,25 @@ __LOCK_INIT_RECURSIVE(static, __sinit_lock);
_VOID
_DEFUN_VOID(__sfp_lock_acquire)
{
//__lock_acquire_recursive (__sfp_lock);
__lock_acquire_recursive (__sfp_lock);
}
_VOID
_DEFUN_VOID(__sfp_lock_release)
{
//__lock_release_recursive (__sfp_lock);
__lock_release_recursive (__sfp_lock);
}
_VOID
_DEFUN_VOID(__sinit_lock_acquire)
{
//__lock_acquire_recursive (__sinit_lock);
__lock_acquire_recursive (__sinit_lock);
}
_VOID
_DEFUN_VOID(__sinit_lock_release)
{
//__lock_release_recursive (__sinit_lock);
__lock_release_recursive (__sinit_lock);
}
/* Walkable file locking routine. */

View File

@ -0,0 +1,371 @@
/* Copyright (C) 2007 Eric Blake
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
/*
FUNCTION
<<fmemopen>>---open a stream around a fixed-length string
INDEX
fmemopen
ANSI_SYNOPSIS
#include <stdio.h>
FILE *fmemopen(void *restrict <[buf]>, size_t <[size]>,
const char *restrict <[mode]>);
DESCRIPTION
<<fmemopen>> creates a seekable <<FILE>> stream that wraps a
fixed-length buffer of <[size]> bytes starting at <[buf]>. The stream
is opened with <[mode]> treated as in <<fopen>>, where append mode
starts writing at the first NUL byte. If <[buf]> is NULL, then
<[size]> bytes are automatically provided as if by <<malloc>>, with
the initial size of 0, and <[mode]> must contain <<+>> so that data
can be read after it is written.
The stream maintains a current position, which moves according to
bytes read or written, and which can be one past the end of the array.
The stream also maintains a current file size, which is never greater
than <[size]>. If <[mode]> starts with <<r>>, the position starts at
<<0>>, and file size starts at <[size]> if <[buf]> was provided. If
<[mode]> starts with <<w>>, the position and file size start at <<0>>,
and if <[buf]> was provided, the first byte is set to NUL. If
<[mode]> starts with <<a>>, the position and file size start at the
location of the first NUL byte, or else <[size]> if <[buf]> was
provided.
When reading, NUL bytes have no significance, and reads cannot exceed
the current file size. When writing, the file size can increase up to
<[size]> as needed, and NUL bytes may be embedded in the stream (see
<<open_memstream>> for an alternative that automatically enlarges the
buffer). When the stream is flushed or closed after a write that
changed the file size, a NUL byte is written at the current position
if there is still room; if the stream is not also open for reading, a
NUL byte is additionally written at the last byte of <[buf]> when the
stream has exceeded <[size]>, so that a write-only <[buf]> is always
NUL-terminated when the stream is flushed or closed (and the initial
<[size]> should take this into account). It is not possible to seek
outside the bounds of <[size]>. A NUL byte written during a flush is
restored to its previous value when seeking elsewhere in the string.
RETURNS
The return value is an open FILE pointer on success. On error,
<<NULL>> is returned, and <<errno>> will be set to EINVAL if <[size]>
is zero or <[mode]> is invalid, ENOMEM if <[buf]> was NULL and memory
could not be allocated, or EMFILE if too many streams are already
open.
PORTABILITY
This function is being added to POSIX 200x, but is not in POSIX 2001.
Supporting OS subroutines required: <<sbrk>>.
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/lock.h>
#include "local.h"
/* Describe details of an open memstream. */
typedef struct fmemcookie {
void *storage; /* storage to free on close */
char *buf; /* buffer start */
size_t pos; /* current position */
size_t eof; /* current file size */
size_t max; /* maximum file size */
char append; /* nonzero if appending */
char writeonly; /* 1 if write-only */
char saved; /* saved character that lived at pos before write-only NUL */
} fmemcookie;
/* Read up to non-zero N bytes into BUF from stream described by
COOKIE; return number of bytes read (0 on EOF). */
static _READ_WRITE_RETURN_TYPE
_DEFUN(fmemreader, (ptr, cookie, buf, n),
struct _reent *ptr _AND
void *cookie _AND
char *buf _AND
_READ_WRITE_BUFSIZE_TYPE n)
{
fmemcookie *c = (fmemcookie *) cookie;
/* Can't read beyond current size, but EOF condition is not an error. */
if (c->pos > c->eof)
return 0;
if (n >= c->eof - c->pos)
n = c->eof - c->pos;
memcpy (buf, c->buf + c->pos, n);
c->pos += n;
return n;
}
/* Write up to non-zero N bytes of BUF into the stream described by COOKIE,
returning the number of bytes written or EOF on failure. */
static _READ_WRITE_RETURN_TYPE
_DEFUN(fmemwriter, (ptr, cookie, buf, n),
struct _reent *ptr _AND
void *cookie _AND
const char *buf _AND
_READ_WRITE_BUFSIZE_TYPE n)
{
fmemcookie *c = (fmemcookie *) cookie;
int adjust = 0; /* true if at EOF, but still need to write NUL. */
/* Append always seeks to eof; otherwise, if we have previously done
a seek beyond eof, ensure all intermediate bytes are NUL. */
if (c->append)
c->pos = c->eof;
else if (c->pos > c->eof)
memset (c->buf + c->eof, '\0', c->pos - c->eof);
/* Do not write beyond EOF; saving room for NUL on write-only stream. */
if (c->pos + n > c->max - c->writeonly)
{
adjust = c->writeonly;
n = c->max - c->pos;
}
/* Now n is the number of bytes being modified, and adjust is 1 if
the last byte is NUL instead of from buf. Write a NUL if
write-only; or if read-write, eof changed, and there is still
room. When we are within the file contents, remember what we
overwrite so we can restore it if we seek elsewhere later. */
if (c->pos + n > c->eof)
{
c->eof = c->pos + n;
if (c->eof - adjust < c->max)
c->saved = c->buf[c->eof - adjust] = '\0';
}
else if (c->writeonly)
{
if (n)
{
c->saved = c->buf[c->pos + n - adjust];
c->buf[c->pos + n - adjust] = '\0';
}
else
adjust = 0;
}
c->pos += n;
if (n - adjust)
memcpy (c->buf + c->pos - n, buf, n - adjust);
else
{
ptr->_errno = ENOSPC;
return EOF;
}
return n;
}
/* Seek to position POS relative to WHENCE within stream described by
COOKIE; return resulting position or fail with EOF. */
static _fpos_t
_DEFUN(fmemseeker, (ptr, cookie, pos, whence),
struct _reent *ptr _AND
void *cookie _AND
_fpos_t pos _AND
int whence)
{
fmemcookie *c = (fmemcookie *) cookie;
#ifndef __LARGE64_FILES
off_t offset = (off_t) pos;
#else /* __LARGE64_FILES */
_off64_t offset = (_off64_t) pos;
#endif /* __LARGE64_FILES */
if (whence == SEEK_CUR)
offset += c->pos;
else if (whence == SEEK_END)
offset += c->eof;
if (offset < 0)
{
ptr->_errno = EINVAL;
offset = -1;
}
else if (offset > c->max)
{
ptr->_errno = ENOSPC;
offset = -1;
}
#ifdef __LARGE64_FILES
else if ((_fpos_t) offset != offset)
{
ptr->_errno = EOVERFLOW;
offset = -1;
}
#endif /* __LARGE64_FILES */
else
{
if (c->writeonly && c->pos < c->eof)
{
c->buf[c->pos] = c->saved;
c->saved = '\0';
}
c->pos = offset;
if (c->writeonly && c->pos < c->eof)
{
c->saved = c->buf[c->pos];
c->buf[c->pos] = '\0';
}
}
return (_fpos_t) offset;
}
/* Seek to position POS relative to WHENCE within stream described by
COOKIE; return resulting position or fail with EOF. */
#ifdef __LARGE64_FILES
static _fpos64_t
_DEFUN(fmemseeker64, (ptr, cookie, pos, whence),
struct _reent *ptr _AND
void *cookie _AND
_fpos64_t pos _AND
int whence)
{
_off64_t offset = (_off64_t) pos;
fmemcookie *c = (fmemcookie *) cookie;
if (whence == SEEK_CUR)
offset += c->pos;
else if (whence == SEEK_END)
offset += c->eof;
if (offset < 0)
{
ptr->_errno = EINVAL;
offset = -1;
}
else if (offset > c->max)
{
ptr->_errno = ENOSPC;
offset = -1;
}
else
{
if (c->writeonly && c->pos < c->eof)
{
c->buf[c->pos] = c->saved;
c->saved = '\0';
}
c->pos = offset;
if (c->writeonly && c->pos < c->eof)
{
c->saved = c->buf[c->pos];
c->buf[c->pos] = '\0';
}
}
return (_fpos64_t) offset;
}
#endif /* __LARGE64_FILES */
/* Reclaim resources used by stream described by COOKIE. */
static int
_DEFUN(fmemcloser, (ptr, cookie),
struct _reent *ptr _AND
void *cookie)
{
fmemcookie *c = (fmemcookie *) cookie;
_free_r (ptr, c->storage);
return 0;
}
/* Open a memstream around buffer BUF of SIZE bytes, using MODE.
Return the new stream, or fail with NULL. */
FILE *
_DEFUN(_fmemopen_r, (ptr, buf, size, mode),
struct _reent *ptr _AND
void *__restrict buf _AND
size_t size _AND
const char *__restrict mode)
{
FILE *fp;
fmemcookie *c;
int flags;
int dummy;
if ((flags = __sflags (ptr, mode, &dummy)) == 0)
return NULL;
if (!size || !(buf || flags & __SRW))
{
ptr->_errno = EINVAL;
return NULL;
}
if ((fp = __sfp (ptr)) == NULL)
return NULL;
if ((c = (fmemcookie *) _malloc_r (ptr, sizeof *c + (buf ? 0 : size)))
== NULL)
{
_newlib_sfp_lock_start ();
fp->_flags = 0; /* release */
#ifndef __SINGLE_THREAD__
__lock_close_recursive (fp->_lock);
#endif
_newlib_sfp_lock_end ();
return NULL;
}
c->storage = c;
c->max = size;
/* 9 modes to worry about. */
/* w/a, buf or no buf: Guarantee a NUL after any file writes. */
c->writeonly = (flags & __SWR) != 0;
c->saved = '\0';
if (!buf)
{
/* r+/w+/a+, and no buf: file starts empty. */
c->buf = (char *) (c + 1);
c->buf[0] = '\0';
c->pos = c->eof = 0;
c->append = (flags & __SAPP) != 0;
}
else
{
c->buf = (char *) buf;
switch (*mode)
{
case 'a':
/* a/a+ and buf: position and size at first NUL. */
buf = memchr (c->buf, '\0', size);
c->eof = c->pos = buf ? (char *) buf - c->buf : size;
if (!buf && c->writeonly)
/* a: guarantee a NUL within size even if no writes. */
c->buf[size - 1] = '\0';
c->append = 1;
break;
case 'r':
/* r/r+ and buf: read at beginning, full size available. */
c->pos = c->append = 0;
c->eof = size;
break;
case 'w':
/* w/w+ and buf: write at beginning, truncate to empty. */
c->pos = c->append = c->eof = 0;
*c->buf = '\0';
break;
default:
abort ();
}
}
_newlib_flockfile_start (fp);
fp->_file = -1;
fp->_flags = flags;
fp->_cookie = c;
fp->_read = flags & (__SRD | __SRW) ? fmemreader : NULL;
fp->_write = flags & (__SWR | __SRW) ? fmemwriter : NULL;
fp->_seek = fmemseeker;
#ifdef __LARGE64_FILES
fp->_seek64 = fmemseeker64;
fp->_flags |= __SL64;
#endif
fp->_close = fmemcloser;
_newlib_flockfile_end (fp);
return fp;
}
#ifndef _REENT_ONLY
FILE *
_DEFUN(fmemopen, (buf, size, mode),
void *__restrict buf _AND
size_t size _AND
const char *__restrict mode)
{
return _fmemopen_r (_REENT, buf, size, mode);
}
#endif /* !_REENT_ONLY */

View File

@ -0,0 +1,263 @@
/* Copyright (C) 2007 Eric Blake
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
/*
FUNCTION
<<fopencookie>>---open a stream with custom callbacks
INDEX
fopencookie
ANSI_SYNOPSIS
#include <stdio.h>
FILE *fopencookie(const void *<[cookie]>, const char *<[mode]>,
cookie_io_functions_t <[functions]>);
DESCRIPTION
<<fopencookie>> creates a <<FILE>> stream where I/O is performed using
custom callbacks. The callbacks are registered via the structure:
typedef ssize_t (*cookie_read_function_t)(void *_cookie, char *_buf,
size_t _n);
typedef ssize_t (*cookie_write_function_t)(void *_cookie,
const char *_buf, size_t _n);
typedef int (*cookie_seek_function_t)(void *_cookie, off_t *_off,
int _whence);
typedef int (*cookie_close_function_t)(void *_cookie);
. typedef struct
. {
. cookie_read_function_t *read;
. cookie_write_function_t *write;
. cookie_seek_function_t *seek;
. cookie_close_function_t *close;
. } cookie_io_functions_t;
The stream is opened with <[mode]> treated as in <<fopen>>. The
callbacks <[functions.read]> and <[functions.write]> may only be NULL
when <[mode]> does not require them.
<[functions.read]> should return -1 on failure, or else the number of
bytes read (0 on EOF). It is similar to <<read>>, except that
<[cookie]> will be passed as the first argument.
<[functions.write]> should return -1 on failure, or else the number of
bytes written. It is similar to <<write>>, except that <[cookie]>
will be passed as the first argument.
<[functions.seek]> should return -1 on failure, and 0 on success, with
*<[_off]> set to the current file position. It is a cross between
<<lseek>> and <<fseek>>, with the <[_whence]> argument interpreted in
the same manner. A NULL <[functions.seek]> makes the stream behave
similarly to a pipe in relation to stdio functions that require
positioning.
<[functions.close]> should return -1 on failure, or 0 on success. It
is similar to <<close>>, except that <[cookie]> will be passed as the
first argument. A NULL <[functions.close]> merely flushes all data
then lets <<fclose>> succeed. A failed close will still invalidate
the stream.
Read and write I/O functions are allowed to change the underlying
buffer on fully buffered or line buffered streams by calling
<<setvbuf>>. They are also not required to completely fill or empty
the buffer. They are not, however, allowed to change streams from
unbuffered to buffered or to change the state of the line buffering
flag. They must also be prepared to have read or write calls occur on
buffers other than the one most recently specified.
RETURNS
The return value is an open FILE pointer on success. On error,
<<NULL>> is returned, and <<errno>> will be set to EINVAL if a
function pointer is missing or <[mode]> is invalid, ENOMEM if the
stream cannot be created, or EMFILE if too many streams are already
open.
PORTABILITY
This function is a newlib extension, copying the prototype from Linux.
It is not portable. See also the <<funopen>> interface from BSD.
Supporting OS subroutines required: <<sbrk>>.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <sys/lock.h>
#include "local.h"
typedef struct fccookie {
void *cookie;
FILE *fp;
cookie_read_function_t *readfn;
cookie_write_function_t *writefn;
cookie_seek_function_t *seekfn;
cookie_close_function_t *closefn;
} fccookie;
static _READ_WRITE_RETURN_TYPE
_DEFUN(fcreader, (ptr, cookie, buf, n),
struct _reent *ptr _AND
void *cookie _AND
char *buf _AND
_READ_WRITE_BUFSIZE_TYPE n)
{
int result;
fccookie *c = (fccookie *) cookie;
errno = 0;
if ((result = c->readfn (c->cookie, buf, n)) < 0 && errno)
ptr->_errno = errno;
return result;
}
static _READ_WRITE_RETURN_TYPE
_DEFUN(fcwriter, (ptr, cookie, buf, n),
struct _reent *ptr _AND
void *cookie _AND
const char *buf _AND
_READ_WRITE_BUFSIZE_TYPE n)
{
int result;
fccookie *c = (fccookie *) cookie;
if (c->fp->_flags & __SAPP && c->fp->_seek)
{
#ifdef __LARGE64_FILES
c->fp->_seek64 (ptr, cookie, 0, SEEK_END);
#else
c->fp->_seek (ptr, cookie, 0, SEEK_END);
#endif
}
errno = 0;
if ((result = c->writefn (c->cookie, buf, n)) < 0 && errno)
ptr->_errno = errno;
return result;
}
static _fpos_t
_DEFUN(fcseeker, (ptr, cookie, pos, whence),
struct _reent *ptr _AND
void *cookie _AND
_fpos_t pos _AND
int whence)
{
fccookie *c = (fccookie *) cookie;
#ifndef __LARGE64_FILES
off_t offset = (off_t) pos;
#else /* __LARGE64_FILES */
_off64_t offset = (_off64_t) pos;
#endif /* __LARGE64_FILES */
errno = 0;
if (c->seekfn (c->cookie, &offset, whence) < 0 && errno)
ptr->_errno = errno;
#ifdef __LARGE64_FILES
else if ((_fpos_t)offset != offset)
{
ptr->_errno = EOVERFLOW;
offset = -1;
}
#endif /* __LARGE64_FILES */
return (_fpos_t) offset;
}
#ifdef __LARGE64_FILES
static _fpos64_t
_DEFUN(fcseeker64, (ptr, cookie, pos, whence),
struct _reent *ptr _AND
void *cookie _AND
_fpos64_t pos _AND
int whence)
{
_off64_t offset;
fccookie *c = (fccookie *) cookie;
errno = 0;
if (c->seekfn (c->cookie, &offset, whence) < 0 && errno)
ptr->_errno = errno;
return (_fpos64_t) offset;
}
#endif /* __LARGE64_FILES */
static int
_DEFUN(fccloser, (ptr, cookie),
struct _reent *ptr _AND
void *cookie)
{
int result = 0;
fccookie *c = (fccookie *) cookie;
if (c->closefn)
{
errno = 0;
if ((result = c->closefn (c->cookie)) < 0 && errno)
ptr->_errno = errno;
}
_free_r (ptr, c);
return result;
}
FILE *
_DEFUN(_fopencookie_r, (ptr, cookie, mode, functions),
struct _reent *ptr _AND
void *cookie _AND
const char *mode _AND
cookie_io_functions_t functions)
{
FILE *fp;
fccookie *c;
int flags;
int dummy;
if ((flags = __sflags (ptr, mode, &dummy)) == 0)
return NULL;
if (((flags & (__SRD | __SRW)) && !functions.read)
|| ((flags & (__SWR | __SRW)) && !functions.write))
{
ptr->_errno = EINVAL;
return NULL;
}
if ((fp = __sfp (ptr)) == NULL)
return NULL;
if ((c = (fccookie *) _malloc_r (ptr, sizeof *c)) == NULL)
{
_newlib_sfp_lock_start ();
fp->_flags = 0; /* release */
#ifndef __SINGLE_THREAD__
__lock_close_recursive (fp->_lock);
#endif
_newlib_sfp_lock_end ();
return NULL;
}
_newlib_flockfile_start (fp);
fp->_file = -1;
fp->_flags = flags;
c->cookie = cookie;
c->fp = fp;
fp->_cookie = c;
c->readfn = functions.read;
fp->_read = fcreader;
c->writefn = functions.write;
fp->_write = fcwriter;
c->seekfn = functions.seek;
fp->_seek = functions.seek ? fcseeker : NULL;
#ifdef __LARGE64_FILES
fp->_seek64 = functions.seek ? fcseeker64 : NULL;
fp->_flags |= __SL64;
#endif
c->closefn = functions.close;
fp->_close = fccloser;
_newlib_flockfile_end (fp);
return fp;
}
#ifndef _REENT_ONLY
FILE *
_DEFUN(fopencookie, (cookie, mode, functions),
void *cookie _AND
const char *mode _AND
cookie_io_functions_t functions)
{
return _fopencookie_r (_REENT, cookie, mode, functions);
}
#endif /* !_REENT_ONLY */

View File

@ -0,0 +1,113 @@
/* Copyright (C) 2009 Eric Blake
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
/*
FUNCTION
<<fpurge>>---discard pending file I/O
INDEX
fpurge
INDEX
_fpurge_r
INDEX
__fpurge
ANSI_SYNOPSIS
#include <stdio.h>
int fpurge(FILE *<[fp]>);
int _fpurge_r(struct _reent *<[reent]>, FILE *<[fp]>);
#include <stdio.h>
#include <stdio_ext.h>
void __fpurge(FILE *<[fp]>);
DESCRIPTION
Use <<fpurge>> to clear all buffers of the given stream. For output
streams, this discards data not yet written to disk. For input streams,
this discards any data from <<ungetc>> and any data retrieved from disk
but not yet read via <<getc>>. This is more severe than <<fflush>>,
and generally is only needed when manually altering the underlying file
descriptor of a stream.
<<__fpurge>> behaves exactly like <<fpurge>> but does not return a value.
The alternate function <<_fpurge_r>> is a reentrant version, where the
extra argument <[reent]> is a pointer to a reentrancy structure, and
<[fp]> must not be NULL.
RETURNS
<<fpurge>> returns <<0>> unless <[fp]> is not valid, in which case it
returns <<EOF>> and sets <<errno>>.
PORTABILITY
These functions are not portable to any standard.
No supporting OS subroutines are required.
*/
#include <_ansi.h>
#include <stdio.h>
#ifndef __rtems__
#include <stdio_ext.h>
#endif
#include <errno.h>
#include "local.h"
/* Discard I/O from a single file. */
int
_DEFUN(_fpurge_r, (ptr, fp),
struct _reent *ptr _AND
register FILE * fp)
{
int t;
CHECK_INIT (ptr, fp);
_newlib_flockfile_start (fp);
t = fp->_flags;
if (!t)
{
ptr->_errno = EBADF;
_newlib_flockfile_exit (fp);
return EOF;
}
fp->_p = fp->_bf._base;
if ((t & __SWR) == 0)
{
fp->_r = 0;
if (HASUB (fp))
FREEUB (ptr, fp);
}
else
fp->_w = t & (__SLBF | __SNBF) ? 0 : fp->_bf._size;
_newlib_flockfile_end (fp);
return 0;
}
#ifndef _REENT_ONLY
int
_DEFUN(fpurge, (fp),
register FILE * fp)
{
return _fpurge_r (_REENT, fp);
}
#ifndef __rtems__
void
_DEFUN(__fpurge, (fp),
register FILE * fp)
{
_fpurge_r (_REENT, fp);
}
#endif
#endif /* _REENT_ONLY */

View File

@ -0,0 +1,56 @@
/*
* Copyright (c) 2014 Red Hat, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <_ansi.h>
#include <stdio.h>
#include "local.h"
int
_DEFUN(_fputc_unlocked_r, (ptr, ch, file),
struct _reent *ptr _AND
int ch _AND
FILE * file)
{
CHECK_INIT(ptr, file);
return _putc_unlocked_r (ptr, ch, file);
}
#ifndef _REENT_ONLY
int
_DEFUN(fputc_unlocked, (ch, file),
int ch _AND
FILE * file)
{
#if !defined(__OPTIMIZE_SIZE__) && !defined(PREFER_SIZE_OVER_SPEED)
struct _reent *reent = _REENT;
CHECK_INIT(reent, file);
return _putc_unlocked_r (reent, ch, file);
#else
return _fputc_unlocked_r (_REENT, ch, file);
#endif
}
#endif /* !_REENT_ONLY */

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2014 Red Hat, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#define __IMPL_UNLOCKED__
#include "fputs.c"

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2014 Red Hat, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#define __IMPL_UNLOCKED__
#include "fread.c"

View File

@ -0,0 +1,90 @@
/*
* Copyright (c) 2014 Red Hat, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
FUNCTION
<<__fsetlocking>>---set or query locking mode on FILE stream
INDEX
__fsetlocking
ANSI_SYNOPSIS
#include <stdio.h>
#include <stdio_ext.h>
int __fsetlocking(FILE *<[fp]>, int <[type]>);
DESCRIPTION
This function sets how the stdio functions handle locking of FILE <[fp]>.
The following values describe <[type]>:
<<FSETLOCKING_INTERNAL>> is the default state, where stdio functions
automatically lock and unlock the stream.
<<FSETLOCKING_BYCALLER>> means that automatic locking in stdio functions
is disabled. Applications which set this take all responsibility for file
locking themselves.
<<FSETLOCKING_QUERY>> returns the current locking mode without changing it.
RETURNS
<<__fsetlocking>> returns the current locking mode of <[fp]>.
PORTABILITY
This function originates from Solaris and is also provided by GNU libc.
No supporting OS subroutines are required.
*/
#ifndef __rtems__
#include <_ansi.h>
#include <stdio.h>
#include <stdio_ext.h>
#include "local.h"
int
_DEFUN(__fsetlocking, (fp, type),
FILE * fp _AND
int type)
{
int result;
CHECK_INIT(_REENT, fp);
result = (fp->_flags2 & __SNLK) ? FSETLOCKING_BYCALLER : FSETLOCKING_INTERNAL;
switch (type)
{
case FSETLOCKING_BYCALLER:
fp->_flags2 |= __SNLK;
break;
case FSETLOCKING_INTERNAL:
fp->_flags2 &= ~__SNLK;
break;
case FSETLOCKING_QUERY:
default:
break;
}
return result;
}
#endif /* __rtems__ */

View File

@ -0,0 +1,95 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
FUNCTION
<<fsetpos>>---restore position of a stream or file
INDEX
fsetpos
INDEX
_fsetpos_r
ANSI_SYNOPSIS
#include <stdio.h>
int fsetpos(FILE *<[fp]>, const fpos_t *<[pos]>);
int _fsetpos_r(struct _reent *<[ptr]>, FILE *<[fp]>,
const fpos_t *<[pos]>);
TRAD_SYNOPSIS
#include <stdio.h>
int fsetpos(<[fp]>, <[pos]>)
FILE *<[fp]>;
fpos_t *<[pos]>;
int _fsetpos_r(<[ptr]>, <[fp]>, <[pos]>)
struct _reent *<[ptr]>;
FILE *<[fp]>;
fpos_t *<[pos]>;
DESCRIPTION
Objects of type <<FILE>> can have a ``position'' that records how much
of the file your program has already read. Many of the <<stdio>> functions
depend on this position, and many change it as a side effect.
You can use <<fsetpos>> to return the file identified by <[fp]> to a previous
position <<*<[pos]>>> (after first recording it with <<fgetpos>>).
See <<fseek>> for a similar facility.
RETURNS
<<fgetpos>> returns <<0>> when successful. If <<fgetpos>> fails, the
result is <<1>>. The reason for failure is indicated in <<errno>>:
either <<ESPIPE>> (the stream identified by <[fp]> doesn't support
repositioning) or <<EINVAL>> (invalid file position).
PORTABILITY
ANSI C requires <<fsetpos>>, but does not specify the nature of
<<*<[pos]>>> beyond identifying it as written by <<fgetpos>>.
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
int
_DEFUN(_fsetpos_r, (ptr, iop, pos),
struct _reent * ptr _AND
FILE * iop _AND
_CONST _fpos_t * pos)
{
int x = _fseek_r (ptr, iop, *pos, SEEK_SET);
if (x != 0)
return 1;
return 0;
}
#ifndef _REENT_ONLY
int
_DEFUN(fsetpos, (iop, pos),
FILE * iop _AND
_CONST _fpos_t * pos)
{
return _fsetpos_r (_REENT, iop, pos);
}
#endif /* !_REENT_ONLY */

View File

@ -0,0 +1,279 @@
/* Copyright (C) 2007 Eric Blake
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
/*
FUNCTION
<<funopen>>, <<fropen>>, <<fwopen>>---open a stream with custom callbacks
INDEX
funopen
INDEX
fropen
INDEX
fwopen
ANSI_SYNOPSIS
#include <stdio.h>
FILE *funopen(const void *<[cookie]>,
int (*<[readfn]>) (void *cookie, char *buf, int n),
int (*<[writefn]>) (void *cookie, const char *buf, int n),
fpos_t (*<[seekfn]>) (void *cookie, fpos_t off, int whence),
int (*<[closefn]>) (void *cookie));
FILE *fropen(const void *<[cookie]>,
int (*<[readfn]>) (void *cookie, char *buf, int n));
FILE *fwopen(const void *<[cookie]>,
int (*<[writefn]>) (void *cookie, const char *buf, int n));
DESCRIPTION
<<funopen>> creates a <<FILE>> stream where I/O is performed using
custom callbacks. At least one of <[readfn]> and <[writefn]> must be
provided, which determines whether the stream behaves with mode <"r">,
<"w">, or <"r+">.
<[readfn]> should return -1 on failure, or else the number of bytes
read (0 on EOF). It is similar to <<read>>, except that <int> rather
than <size_t> bounds a transaction size, and <[cookie]> will be passed
as the first argument. A NULL <[readfn]> makes attempts to read the
stream fail.
<[writefn]> should return -1 on failure, or else the number of bytes
written. It is similar to <<write>>, except that <int> rather than
<size_t> bounds a transaction size, and <[cookie]> will be passed as
the first argument. A NULL <[writefn]> makes attempts to write the
stream fail.
<[seekfn]> should return (fpos_t)-1 on failure, or else the current
file position. It is similar to <<lseek>>, except that <[cookie]>
will be passed as the first argument. A NULL <[seekfn]> makes the
stream behave similarly to a pipe in relation to stdio functions that
require positioning. This implementation assumes fpos_t and off_t are
the same type.
<[closefn]> should return -1 on failure, or 0 on success. It is
similar to <<close>>, except that <[cookie]> will be passed as the
first argument. A NULL <[closefn]> merely flushes all data then lets
<<fclose>> succeed. A failed close will still invalidate the stream.
Read and write I/O functions are allowed to change the underlying
buffer on fully buffered or line buffered streams by calling
<<setvbuf>>. They are also not required to completely fill or empty
the buffer. They are not, however, allowed to change streams from
unbuffered to buffered or to change the state of the line buffering
flag. They must also be prepared to have read or write calls occur on
buffers other than the one most recently specified.
The functions <<fropen>> and <<fwopen>> are convenience macros around
<<funopen>> that only use the specified callback.
RETURNS
The return value is an open FILE pointer on success. On error,
<<NULL>> is returned, and <<errno>> will be set to EINVAL if a
function pointer is missing, ENOMEM if the stream cannot be created,
or EMFILE if too many streams are already open.
PORTABILITY
This function is a newlib extension, copying the prototype from BSD.
It is not portable. See also the <<fopencookie>> interface from Linux.
Supporting OS subroutines required: <<sbrk>>.
*/
#include <stdio.h>
#include <errno.h>
#include <sys/lock.h>
#include "local.h"
typedef int (*funread)(void *_cookie, char *_buf, _READ_WRITE_BUFSIZE_TYPE _n);
typedef int (*funwrite)(void *_cookie, const char *_buf,
_READ_WRITE_BUFSIZE_TYPE _n);
#ifdef __LARGE64_FILES
typedef _fpos64_t (*funseek)(void *_cookie, _fpos64_t _off, int _whence);
#else
typedef fpos_t (*funseek)(void *_cookie, fpos_t _off, int _whence);
#endif
typedef int (*funclose)(void *_cookie);
typedef struct funcookie {
void *cookie;
funread readfn;
funwrite writefn;
funseek seekfn;
funclose closefn;
} funcookie;
static _READ_WRITE_RETURN_TYPE
_DEFUN(funreader, (ptr, cookie, buf, n),
struct _reent *ptr _AND
void *cookie _AND
char *buf _AND
_READ_WRITE_BUFSIZE_TYPE n)
{
int result;
funcookie *c = (funcookie *) cookie;
errno = 0;
if ((result = c->readfn (c->cookie, buf, n)) < 0 && errno)
ptr->_errno = errno;
return result;
}
static _READ_WRITE_RETURN_TYPE
_DEFUN(funwriter, (ptr, cookie, buf, n),
struct _reent *ptr _AND
void *cookie _AND
const char *buf _AND
_READ_WRITE_BUFSIZE_TYPE n)
{
int result;
funcookie *c = (funcookie *) cookie;
errno = 0;
if ((result = c->writefn (c->cookie, buf, n)) < 0 && errno)
ptr->_errno = errno;
return result;
}
static _fpos_t
_DEFUN(funseeker, (ptr, cookie, off, whence),
struct _reent *ptr _AND
void *cookie _AND
_fpos_t off _AND
int whence)
{
funcookie *c = (funcookie *) cookie;
#ifndef __LARGE64_FILES
fpos_t result;
errno = 0;
if ((result = c->seekfn (c->cookie, (fpos_t) off, whence)) < 0 && errno)
ptr->_errno = errno;
#else /* __LARGE64_FILES */
_fpos64_t result;
errno = 0;
if ((result = c->seekfn (c->cookie, (_fpos64_t) off, whence)) < 0 && errno)
ptr->_errno = errno;
else if ((_fpos_t)result != result)
{
ptr->_errno = EOVERFLOW;
result = -1;
}
#endif /* __LARGE64_FILES */
return result;
}
#ifdef __LARGE64_FILES
static _fpos64_t
_DEFUN(funseeker64, (ptr, cookie, off, whence),
struct _reent *ptr _AND
void *cookie _AND
_fpos64_t off _AND
int whence)
{
_fpos64_t result;
funcookie *c = (funcookie *) cookie;
errno = 0;
if ((result = c->seekfn (c->cookie, off, whence)) < 0 && errno)
ptr->_errno = errno;
return result;
}
#endif /* __LARGE64_FILES */
static int
_DEFUN(funcloser, (ptr, cookie),
struct _reent *ptr _AND
void *cookie)
{
int result = 0;
funcookie *c = (funcookie *) cookie;
if (c->closefn)
{
errno = 0;
if ((result = c->closefn (c->cookie)) < 0 && errno)
ptr->_errno = errno;
}
_free_r (ptr, c);
return result;
}
FILE *
_DEFUN(_funopen_r, (ptr, cookie, readfn, writefn, seekfn, closefn),
struct _reent *ptr _AND
const void *cookie _AND
funread readfn _AND
funwrite writefn _AND
funseek seekfn _AND
funclose closefn)
{
FILE *fp;
funcookie *c;
if (!readfn && !writefn)
{
ptr->_errno = EINVAL;
return NULL;
}
if ((fp = __sfp (ptr)) == NULL)
return NULL;
if ((c = (funcookie *) _malloc_r (ptr, sizeof *c)) == NULL)
{
_newlib_sfp_lock_start ();
fp->_flags = 0; /* release */
#ifndef __SINGLE_THREAD__
__lock_close_recursive (fp->_lock);
#endif
_newlib_sfp_lock_end ();
return NULL;
}
_newlib_flockfile_start (fp);
fp->_file = -1;
c->cookie = (void *) cookie; /* cast away const */
fp->_cookie = c;
if (readfn)
{
c->readfn = readfn;
fp->_read = funreader;
if (writefn)
{
fp->_flags = __SRW;
c->writefn = writefn;
fp->_write = funwriter;
}
else
{
fp->_flags = __SRD;
c->writefn = NULL;
fp->_write = NULL;
}
}
else
{
fp->_flags = __SWR;
c->writefn = writefn;
fp->_write = funwriter;
c->readfn = NULL;
fp->_read = NULL;
}
c->seekfn = seekfn;
fp->_seek = seekfn ? funseeker : NULL;
#ifdef __LARGE64_FILES
fp->_seek64 = seekfn ? funseeker64 : NULL;
fp->_flags |= __SL64;
#endif
c->closefn = closefn;
fp->_close = funcloser;
_newlib_flockfile_end (fp);
return fp;
}
#ifndef _REENT_ONLY
FILE *
_DEFUN(funopen, (cookie, readfn, writefn, seekfn, closefn),
const void *cookie _AND
funread readfn _AND
funwrite writefn _AND
funseek seekfn _AND
funclose closefn)
{
return _funopen_r (_REENT, cookie, readfn, writefn, seekfn, closefn);
}
#endif /* !_REENT_ONLY */

View File

@ -0,0 +1,89 @@
/*
FUNCTION
<<fwide>>---set and determine the orientation of a FILE stream
INDEX
fwide
INDEX
_fwide_r
ANSI_SYNOPSIS
#include <wchar.h>
int fwide(FILE *<[fp]>, int <[mode]>);
int _fwide_r(struct _reent *<[ptr]>, FILE *<[fp]>, int <[mode]>);
TRAD_SYNOPSIS
#include <wchar.h>
int fwide(<[fp]>, <[mode]>);
FILE *<[fp]>;
int <[mode]>;
int _fwide_r(<[ptr]>, <[fp]>, <[mode]>);
struct _reent *<[ptr]>;
FILE *<[fp]>;
int <[mode]>;
DESCRIPTION
When <[mode]> is zero, the <<fwide>> function determines the current
orientation of <[fp]>. It returns a value > 0 if <[fp]> is
wide-character oriented, i.e. if wide character I/O is permitted but
char I/O is disallowed. It returns a value < 0 if <[fp]> is byte
oriented, i.e. if char I/O is permitted but wide character I/O is
disallowed. It returns zero if <[fp]> has no orientation yet; in
this case the next I/O operation might change the orientation (to byte
oriented if it is a char I/O operation, or to wide-character oriented
if it is a wide character I/O operation).
Once a stream has an orientation, it cannot be changed and persists
until the stream is closed, unless the stream is re-opened with freopen,
which removes the orientation of the stream.
When <[mode]> is non-zero, the <<fwide>> function first attempts to set
<[fp]>'s orientation (to wide-character oriented if <[mode]> > 0, or to
byte oriented if <[mode]> < 0). It then returns a value denoting the
current orientation, as above.
RETURNS
The <<fwide>> function returns <[fp]>'s orientation, after possibly
changing it. A return value > 0 means wide-character oriented. A return
value < 0 means byte oriented. A return value of zero means undecided.
PORTABILITY
C99, POSIX.1-2001.
*/
#include <_ansi.h>
#include <wchar.h>
#include "local.h"
int
_DEFUN(_fwide_r, (ptr, fp, mode),
struct _reent *ptr _AND
FILE *fp _AND
int mode)
{
int ret;
CHECK_INIT(ptr, fp);
_newlib_flockfile_start (fp);
if (mode != 0) {
ORIENT (fp, mode);
}
if (!(fp->_flags & __SORD))
ret = 0;
else
ret = (fp->_flags2 & __SWID) ? 1 : -1;
_newlib_flockfile_end (fp);
return ret;
}
int
_DEFUN(fwide, (fp, mode),
FILE *fp _AND
int mode)
{
return _fwide_r (_REENT, fp, mode);
}

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2014 Red Hat, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#define __IMPL_UNLOCKED__
#include "fwrite.c"

View File

@ -0,0 +1,117 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
FUNCTION
<<getc>>---read a character (macro)
INDEX
getc
INDEX
_getc_r
ANSI_SYNOPSIS
#include <stdio.h>
int getc(FILE *<[fp]>);
#include <stdio.h>
int _getc_r(struct _reent *<[ptr]>, FILE *<[fp]>);
TRAD_SYNOPSIS
#include <stdio.h>
int getc(<[fp]>)
FILE *<[fp]>;
#include <stdio.h>
int _getc_r(<[ptr]>, <[fp]>)
struct _reent *<[ptr]>;
FILE *<[fp]>;
DESCRIPTION
<<getc>> is a macro, defined in <<stdio.h>>. You can use <<getc>>
to get the next single character from the file or stream
identified by <[fp]>. As a side effect, <<getc>> advances the file's
current position indicator.
For a subroutine version of this macro, see <<fgetc>>.
The <<_getc_r>> function is simply the reentrant version of <<getc>>
which passes an additional reentrancy structure pointer argument: <[ptr]>.
RETURNS
The next character (read as an <<unsigned char>>, and cast to
<<int>>), unless there is no more data, or the host system reports a
read error; in either of these situations, <<getc>> returns <<EOF>>.
You can distinguish the two situations that cause an <<EOF>> result by
using the <<ferror>> and <<feof>> functions.
PORTABILITY
ANSI C requires <<getc>>; it suggests, but does not require, that
<<getc>> be implemented as a macro. The standard explicitly permits
macro implementations of <<getc>> to use the argument more than once;
therefore, in a portable program, you should not use an expression
with side effects as the <<getc>> argument.
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "%W% (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#include <_ansi.h>
#include <stdio.h>
#include "local.h"
/*
* A subroutine version of the macro getc.
*/
#undef getc
int
_DEFUN(_getc_r, (ptr, fp),
struct _reent *ptr _AND
register FILE *fp)
{
int result;
CHECK_INIT (ptr, fp);
_newlib_flockfile_start (fp);
result = __sgetc_r (ptr, fp);
_newlib_flockfile_end (fp);
return result;
}
#ifndef _REENT_ONLY
int
_DEFUN(getc, (fp),
register FILE *fp)
{
int result;
struct _reent *reent = _REENT;
CHECK_INIT (reent, fp);
_newlib_flockfile_start (fp);
result = __sgetc_r (reent, fp);
_newlib_flockfile_end (fp);
return result;
}
#endif /* !_REENT_ONLY */

View File

@ -0,0 +1,90 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
FUNCTION
<<getc_unlocked>>---non-thread-safe version of getc (macro)
INDEX
getc_unlocked
INDEX
_getc_unlocked_r
SYNOPSIS
#include <stdio.h>
int getc_unlocked(FILE *<[fp]>);
#include <stdio.h>
int _getc_unlocked_r(FILE *<[fp]>);
DESCRIPTION
<<getc_unlocked>> is a non-thread-safe version of <<getc>> declared in
<<stdio.h>>. <<getc_unlocked>> may only safely be used within a scope
protected by flockfile() (or ftrylockfile()) and funlockfile(). These
functions may safely be used in a multi-threaded program if and only
if they are called while the invoking thread owns the ( FILE *)
object, as is the case after a successful call to the flockfile() or
ftrylockfile() functions. If threads are disabled, then
<<getc_unlocked>> is equivalent to <<getc>>.
The <<_getc_unlocked_r>> function is simply the reentrant version of
<<get_unlocked>> which passes an additional reentrancy structure pointer
argument: <[ptr]>.
RETURNS
See <<getc>>.
PORTABILITY
POSIX 1003.1 requires <<getc_unlocked>>. <<getc_unlocked>> may be
implemented as a macro, so arguments should not have side-effects.
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>. */
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "%W% (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#include <_ansi.h>
#include <stdio.h>
/*
* A subroutine version of the macro getc_unlocked.
*/
#undef getc_unlocked
int
_DEFUN(_getc_unlocked_r, (ptr, fp),
struct _reent *ptr _AND
register FILE *fp)
{
/* CHECK_INIT is called (eventually) by __srefill_r. */
return __sgetc_r (ptr, fp);
}
#ifndef _REENT_ONLY
int
_DEFUN(getc_unlocked, (fp),
register FILE *fp)
{
return __sgetc_r (_REENT, fp);
}
#endif /* !_REENT_ONLY */

View File

@ -0,0 +1,101 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
FUNCTION
<<getchar>>---read a character (macro)
INDEX
getchar
INDEX
_getchar_r
ANSI_SYNOPSIS
#include <stdio.h>
int getchar(void);
int _getchar_r(struct _reent *<[reent]>);
TRAD_SYNOPSIS
#include <stdio.h>
int getchar();
int _getchar_r(<[reent]>)
char * <[reent]>;
DESCRIPTION
<<getchar>> is a macro, defined in <<stdio.h>>. You can use <<getchar>>
to get the next single character from the standard input stream.
As a side effect, <<getchar>> advances the standard input's
current position indicator.
The alternate function <<_getchar_r>> is a reentrant version. The
extra argument <[reent]> is a pointer to a reentrancy structure.
RETURNS
The next character (read as an <<unsigned char>>, and cast to
<<int>>), unless there is no more data, or the host system reports a
read error; in either of these situations, <<getchar>> returns <<EOF>>.
You can distinguish the two situations that cause an <<EOF>> result by
using `<<ferror(stdin)>>' and `<<feof(stdin)>>'.
PORTABILITY
ANSI C requires <<getchar>>; it suggests, but does not require, that
<<getchar>> be implemented as a macro.
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "%W% (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
/*
* A subroutine version of the macro getchar.
*/
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include "local.h"
#undef getchar
int
_DEFUN(_getchar_r, (reent),
struct _reent *reent)
{
_REENT_SMALL_CHECK_INIT (reent);
return _getc_r (reent, _stdin_r (reent));
}
#ifndef _REENT_ONLY
int
_DEFUN_VOID(getchar)
{
struct _reent *reent = _REENT;
/* CHECK_INIT is called (eventually) by __srefill_r. */
_REENT_SMALL_CHECK_INIT (reent);
return _getc_r (reent, _stdin_r (reent));
}
#endif

View File

@ -0,0 +1,89 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
FUNCTION
<<getchar_unlocked>>---non-thread-safe version of getchar (macro)
INDEX
getchar_unlocked
INDEX
_getchar_unlocked_r
SYNOPSIS
#include <stdio.h>
int getchar_unlocked(void);
#include <stdio.h>
int _getchar_unlocked_r(struct _reent *<[ptr]>);
DESCRIPTION
<<getchar_unlocked>> is a non-thread-safe version of <<getchar>>
declared in <<stdio.h>>. <<getchar_unlocked>> may only safely be used
within a scope protected by flockfile() (or ftrylockfile()) and
funlockfile(). These functions may safely be used in a multi-threaded
program if and only if they are called while the invoking thread owns
the ( FILE *) object, as is the case after a successful call to the
flockfile() or ftrylockfile() functions. If threads are disabled,
then <<getchar_unlocked>> is equivalent to <<getchar>>.
The <<_getchar_unlocked_r>> function is simply the reentrant version of
<<getchar_unlocked>> which passes an addtional reentrancy structure pointer
argument: <[ptr]>.
RETURNS
See <<getchar>>.
PORTABILITY
POSIX 1003.1 requires <<getchar_unlocked>>. <<getchar_unlocked>> may
be implemented as a macro.
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>. */
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "%W% (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
/*
* A subroutine version of the macro getchar_unlocked.
*/
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#undef getchar_unlocked
int
_DEFUN(_getchar_unlocked_r, (ptr),
struct _reent *ptr)
{
return _getc_unlocked_r (ptr, _stdin_r (ptr));
}
#ifndef _REENT_ONLY
int
_DEFUN_VOID(getchar_unlocked)
{
/* CHECK_INIT is called (eventually) by __srefill_r. */
return _getc_unlocked_r (_REENT, _stdin_r (_REENT));
}
#endif

View File

@ -0,0 +1,142 @@
/* Copyright 2002, Red Hat Inc. - all rights reserved */
/*
FUNCTION
<<getdelim>>---read a line up to a specified line delimiter
INDEX
getdelim
ANSI_SYNOPSIS
#include <stdio.h>
int getdelim(char **<[bufptr]>, size_t *<[n]>,
int <[delim]>, FILE *<[fp]>);
TRAD_SYNOPSIS
#include <stdio.h>
int getdelim(<[bufptr]>, <[n]>, <[delim]>, <[fp]>)
char **<[bufptr]>;
size_t *<[n]>;
int <[delim]>;
FILE *<[fp]>;
DESCRIPTION
<<getdelim>> reads a file <[fp]> up to and possibly including a specified
delimiter <[delim]>. The line is read into a buffer pointed to
by <[bufptr]> and designated with size *<[n]>. If the buffer is
not large enough, it will be dynamically grown by <<getdelim>>.
As the buffer is grown, the pointer to the size <[n]> will be
updated.
RETURNS
<<getdelim>> returns <<-1>> if no characters were successfully read;
otherwise, it returns the number of bytes successfully read.
At end of file, the result is nonzero.
PORTABILITY
<<getdelim>> is a glibc extension.
No supporting OS subroutines are directly required.
*/
#include <_ansi.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "local.h"
#define MIN_LINE_SIZE 4
#define DEFAULT_LINE_SIZE 128
ssize_t
_DEFUN(__getdelim, (bufptr, n, delim, fp),
char **bufptr _AND
size_t *n _AND
int delim _AND
FILE *fp)
{
char *buf;
char *ptr;
size_t newsize, numbytes;
int pos;
int ch;
int cont;
if (fp == NULL || bufptr == NULL || n == NULL)
{
errno = EINVAL;
return -1;
}
buf = *bufptr;
if (buf == NULL || *n < MIN_LINE_SIZE)
{
buf = (char *)realloc (*bufptr, DEFAULT_LINE_SIZE);
if (buf == NULL)
{
return -1;
}
*bufptr = buf;
*n = DEFAULT_LINE_SIZE;
}
CHECK_INIT (_REENT, fp);
_newlib_flockfile_start (fp);
numbytes = *n;
ptr = buf;
cont = 1;
while (cont)
{
/* fill buffer - leaving room for nul-terminator */
while (--numbytes > 0)
{
if ((ch = getc_unlocked (fp)) == EOF)
{
cont = 0;
break;
}
else
{
*ptr++ = ch;
if (ch == delim)
{
cont = 0;
break;
}
}
}
if (cont)
{
/* Buffer is too small so reallocate a larger buffer. */
pos = ptr - buf;
newsize = (*n << 1);
buf = realloc (buf, newsize);
if (buf == NULL)
{
cont = 0;
break;
}
/* After reallocating, continue in new buffer */
*bufptr = buf;
*n = newsize;
ptr = buf + pos;
numbytes = newsize - pos;
}
}
_newlib_flockfile_end (fp);
/* if no input data, return failure */
if (ptr == buf)
return -1;
/* otherwise, nul-terminate and return number of bytes read */
*ptr = '\0';
return (ssize_t)(ptr - buf);
}

View File

@ -0,0 +1,54 @@
/* Copyright 2002, Red Hat Inc. - all rights reserved */
/*
FUNCTION
<<getline>>---read a line from a file
INDEX
getline
ANSI_SYNOPSIS
#include <stdio.h>
ssize_t getline(char **<[bufptr]>, size_t *<[n]>, FILE *<[fp]>);
TRAD_SYNOPSIS
#include <stdio.h>
ssize_t getline(<[bufptr]>, <[n]>, <[fp]>)
char **<[bufptr]>;
size_t *<[n]>;
FILE *<[fp]>;
DESCRIPTION
<<getline>> reads a file <[fp]> up to and possibly including the
newline character. The line is read into a buffer pointed to
by <[bufptr]> and designated with size *<[n]>. If the buffer is
not large enough, it will be dynamically grown by <<getdelim>>.
As the buffer is grown, the pointer to the size <[n]> will be
updated.
<<getline>> is equivalent to getdelim(bufptr, n, '\n', fp);
RETURNS
<<getline>> returns <<-1>> if no characters were successfully read,
otherwise, it returns the number of bytes successfully read.
at end of file, the result is nonzero.
PORTABILITY
<<getline>> is a glibc extension.
No supporting OS subroutines are directly required.
*/
#include <_ansi.h>
#include <stdio.h>
extern ssize_t _EXFUN(__getdelim, (char **, size_t *, int, FILE *));
ssize_t
_DEFUN(__getline, (lptr, n, fp),
char **lptr _AND
size_t *n _AND
FILE *fp)
{
return __getdelim (lptr, n, '\n', fp);
}

View File

@ -0,0 +1,113 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
FUNCTION
<<gets>>---get character string (obsolete, use <<fgets>> instead)
INDEX
gets
INDEX
_gets_r
ANSI_SYNOPSIS
#include <stdio.h>
char *gets(char *<[buf]>);
char *_gets_r(struct _reent *<[reent]>, char *<[buf]>);
TRAD_SYNOPSIS
#include <stdio.h>
char *gets(<[buf]>)
char *<[buf]>;
char *_gets_r(<[reent]>, <[buf]>)
struct _reent *<[reent]>;
char *<[buf]>;
DESCRIPTION
Reads characters from standard input until a newline is found.
The characters up to the newline are stored in <[buf]>. The
newline is discarded, and the buffer is terminated with a 0.
This is a @emph{dangerous} function, as it has no way of checking
the amount of space available in <[buf]>. One of the attacks
used by the Internet Worm of 1988 used this to overrun a
buffer allocated on the stack of the finger daemon and
overwrite the return address, causing the daemon to execute
code downloaded into it over the connection.
The alternate function <<_gets_r>> is a reentrant version. The extra
argument <[reent]> is a pointer to a reentrancy structure.
RETURNS
<<gets>> returns the buffer passed to it, with the data filled
in. If end of file occurs with some data already accumulated,
the data is returned with no other indication. If end of file
occurs with no data in the buffer, NULL is returned.
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include "local.h"
char *
_DEFUN(_gets_r, (ptr, buf),
struct _reent *ptr _AND
char *buf)
{
register int c;
register char *s = buf;
FILE *fp;
_REENT_SMALL_CHECK_INIT (ptr);
fp = _stdin_r (ptr);
CHECK_INIT (ptr, fp);
_newlib_flockfile_start (fp);
while ((c = __sgetc_r (ptr, fp)) != '\n')
if (c == EOF)
if (s == buf)
{
_newlib_flockfile_exit (fp);
return NULL;
}
else
break;
else
*s++ = c;
*s = 0;
_newlib_flockfile_end (fp);
return buf;
}
#ifndef _REENT_ONLY
char *
_DEFUN(gets, (buf),
char *buf)
{
return _gets_r (_REENT, buf);
}
#endif

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/* doc in siprintf.c */
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include <stdarg.h>
#include "local.h"
#ifndef _REENT_ONLY
int
_DEFUN(iprintf, (fmt),
const char *fmt _DOTS)
{
int ret;
va_list ap;
struct _reent *ptr = _REENT;
_REENT_SMALL_CHECK_INIT (ptr);
va_start (ap, fmt);
ret = _vfiprintf_r (ptr, _stdout_r (ptr), fmt, ap);
va_end (ap);
return ret;
}
#endif /* ! _REENT_ONLY */
int
_DEFUN(_iprintf_r, (ptr, fmt),
struct _reent *ptr _AND
const char *fmt _DOTS)
{
int ret;
va_list ap;
_REENT_SMALL_CHECK_INIT (ptr);
va_start (ap, fmt);
ret = _vfiprintf_r (ptr, _stdout_r (ptr), fmt, ap);
va_end (ap);
return ret;
}

View File

@ -0,0 +1,78 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#ifdef _HAVE_STDC
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include "local.h"
#ifndef _REENT_ONLY
int
#ifdef _HAVE_STDC
iscanf(_CONST char *fmt, ...)
#else
iscanf(fmt, va_alist)
char *fmt;
va_dcl
#endif
{
int ret;
va_list ap;
_REENT_SMALL_CHECK_INIT (_REENT);
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
va_start (ap);
#endif
ret = __svfiscanf_r (_REENT, _stdin_r (_REENT), fmt, ap);
va_end (ap);
return ret;
}
#endif /* !_REENT_ONLY */
int
#ifdef _HAVE_STDC
_iscanf_r(struct _reent *ptr, _CONST char *fmt, ...)
#else
_iscanf_r(ptr, fmt, va_alist)
struct _reent *ptr;
char *fmt;
va_dcl
#endif
{
int ret;
va_list ap;
_REENT_SMALL_CHECK_INIT (ptr);
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
va_start (ap);
#endif
ret = __svfiscanf_r (ptr, _stdin_r (ptr), fmt, ap);
va_end (ap);
return (ret);
}

View File

@ -182,6 +182,7 @@ extern int _EXFUN(__stextmode,(int));
extern _VOID _EXFUN(__sinit,(struct _reent *));
extern _VOID _EXFUN(_cleanup_r,(struct _reent *));
extern _VOID _EXFUN(__smakebuf_r,(struct _reent *, FILE *));
extern int _EXFUN(__swhatbuf_r,(struct _reent *, FILE *, size_t *, int *));
extern int _EXFUN(_fwalk,(struct _reent *, int (*)(FILE *)));
extern int _EXFUN(_fwalk_reent,(struct _reent *, int (*)(struct _reent *, FILE *)));
struct _glue * _EXFUN(__sfmoreglue,(struct _reent *,int n));

View File

@ -39,13 +39,10 @@ _DEFUN(__smakebuf_r, (ptr, fp),
struct _reent *ptr _AND
register FILE *fp)
{
register size_t size, couldbetty;
register _PTR p;
#ifdef __USE_INTERNAL_STAT64
struct stat64 st;
#else
struct stat st;
#endif
int flags;
size_t size;
int couldbetty;
if (fp->_flags & __SNBF)
{
@ -53,49 +50,7 @@ _DEFUN(__smakebuf_r, (ptr, fp),
fp->_bf._size = 1;
return;
}
#ifdef __USE_INTERNAL_STAT64
if (fp->_file < 0 || _fstat64_r (ptr, fp->_file, &st) < 0)
#else
if (fp->_file < 0 || _fstat_r (ptr, fp->_file, &st) < 0)
#endif
{
couldbetty = 0;
/* Check if we are be called by asprintf family for initial buffer. */
if (fp->_flags & __SMBF)
size = _DEFAULT_ASPRINTF_BUFSIZE;
else
size = BUFSIZ;
#ifdef _FSEEK_OPTIMIZATION
/* do not try to optimise fseek() */
fp->_flags |= __SNPT;
#endif
}
else
{
couldbetty = (st.st_mode & S_IFMT) == S_IFCHR;
#ifdef HAVE_BLKSIZE
size = st.st_blksize <= 0 ? BUFSIZ : st.st_blksize;
#else
size = BUFSIZ;
#endif
#ifdef _FSEEK_OPTIMIZATION
/*
* Optimize fseek() only if it is a regular file.
* (The test for __sseek is mainly paranoia.)
*/
if ((st.st_mode & S_IFMT) == S_IFREG && fp->_seek == __sseek)
{
fp->_flags |= __SOPT;
#ifdef HAVE_BLKSIZE
fp->_blksize = st.st_blksize;
#else
fp->_blksize = 1024;
#endif
}
else
fp->_flags |= __SNPT;
#endif
}
flags = __swhatbuf_r (ptr, fp, &size, &couldbetty);
if ((p = _malloc_r (ptr, size)) == NULL)
{
if (!(fp->_flags & __SSTR))
@ -113,5 +68,60 @@ _DEFUN(__smakebuf_r, (ptr, fp),
fp->_bf._size = size;
if (couldbetty && _isatty_r (ptr, fp->_file))
fp->_flags |= __SLBF;
fp->_flags |= flags;
}
}
/*
* Internal routine to determine `proper' buffering for a file.
*/
int
_DEFUN(__swhatbuf_r, (ptr, fp, bufsize, couldbetty),
struct _reent *ptr _AND
FILE *fp _AND
size_t *bufsize _AND
int *couldbetty)
{
#ifdef _FSEEK_OPTIMIZATION
const int snpt = __SNPT;
#else
const int snpt = 0;
#endif
#ifdef __USE_INTERNAL_STAT64
struct stat64 st;
if (fp->_file < 0 || _fstat64_r (ptr, fp->_file, &st) < 0)
#else
struct stat st;
if (fp->_file < 0 || _fstat_r (ptr, fp->_file, &st) < 0)
#endif
{
*couldbetty = 0;
/* Check if we are be called by asprintf family for initial buffer. */
if (fp->_flags & __SMBF)
*bufsize = _DEFAULT_ASPRINTF_BUFSIZE;
else
*bufsize = BUFSIZ;
return (0);
}
/* could be a tty iff it is a character device */
*couldbetty = S_ISCHR(st.st_mode);
#ifdef HAVE_BLKSIZE
if (st.st_blksize > 0)
{
/*
* Optimise fseek() only if it is a regular file. (The test for
* __sseek is mainly paranoia.) It is safe to set _blksize
* unconditionally; it will only be used if __SOPT is also set.
*/
*bufsize = st.st_blksize;
fp->_blksize = st.st_blksize;
return ((st.st_mode & S_IFMT) == S_IFREG ? __SOPT : snpt);
}
#endif
*bufsize = BUFSIZ;
return (snpt);
}

View File

@ -0,0 +1,414 @@
/* Copyright (C) 2007 Eric Blake
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
/*
FUNCTION
<<open_memstream>>, <<open_wmemstream>>---open a write stream around an arbitrary-length string
INDEX
open_memstream
INDEX
open_wmemstream
ANSI_SYNOPSIS
#include <stdio.h>
FILE *open_memstream(char **restrict <[buf]>,
size_t *restrict <[size]>);
#include <wchar.h>
FILE *open_wmemstream(wchar_t **restrict <[buf]>,
size_t *restrict <[size]>);
DESCRIPTION
<<open_memstream>> creates a seekable, byte-oriented <<FILE>> stream that
wraps an arbitrary-length buffer, created as if by <<malloc>>. The current
contents of *<[buf]> are ignored; this implementation uses *<[size]>
as a hint of the maximum size expected, but does not fail if the hint
was wrong. The parameters <[buf]> and <[size]> are later stored
through following any call to <<fflush>> or <<fclose>>, set to the
current address and usable size of the allocated string; although
after fflush, the pointer is only valid until another stream operation
that results in a write. Behavior is undefined if the user alters
either *<[buf]> or *<[size]> prior to <<fclose>>.
<<open_wmemstream>> is like <<open_memstream>> just with the associated
stream being wide-oriented. The size set in <[size]> in subsequent
operations is the number of wide characters.
The stream is write-only, since the user can directly read *<[buf]>
after a flush; see <<fmemopen>> for a way to wrap a string with a
readable stream. The user is responsible for calling <<free>> on
the final *<[buf]> after <<fclose>>.
Any time the stream is flushed, a NUL byte is written at the current
position (but is not counted in the buffer length), so that the string
is always NUL-terminated after at most *<[size]> bytes (or wide characters
in case of <<open_wmemstream>>). However, data previously written beyond
the current stream offset is not lost, and the NUL value written during a
flush is restored to its previous value when seeking elsewhere in the string.
RETURNS
The return value is an open FILE pointer on success. On error,
<<NULL>> is returned, and <<errno>> will be set to EINVAL if <[buf]>
or <[size]> is NULL, ENOMEM if memory could not be allocated, or
EMFILE if too many streams are already open.
PORTABILITY
POSIX.1-2008
Supporting OS subroutines required: <<sbrk>>.
*/
#include <stdio.h>
#include <wchar.h>
#include <errno.h>
#include <string.h>
#include <sys/lock.h>
#include <stdint.h>
#include "local.h"
#ifndef __LARGE64_FILES
# define OFF_T off_t
#else
# define OFF_T _off64_t
#endif
/* Describe details of an open memstream. */
typedef struct memstream {
void *storage; /* storage to free on close */
char **pbuf; /* pointer to the current buffer */
size_t *psize; /* pointer to the current size, smaller of pos or eof */
size_t pos; /* current position */
size_t eof; /* current file size */
size_t max; /* current malloc buffer size, always > eof */
union {
char c;
wchar_t w;
} saved; /* saved character that lived at *psize before NUL */
int8_t wide; /* wide-oriented (>0) or byte-oriented (<0) */
} memstream;
/* Write up to non-zero N bytes of BUF into the stream described by COOKIE,
returning the number of bytes written or EOF on failure. */
static _READ_WRITE_RETURN_TYPE
_DEFUN(memwriter, (ptr, cookie, buf, n),
struct _reent *ptr _AND
void *cookie _AND
const char *buf _AND
_READ_WRITE_BUFSIZE_TYPE n)
{
memstream *c = (memstream *) cookie;
char *cbuf = *c->pbuf;
/* size_t is unsigned, but off_t is signed. Don't let stream get so
big that user cannot do ftello. */
if (sizeof (OFF_T) == sizeof (size_t) && (ssize_t) (c->pos + n) < 0)
{
ptr->_errno = EFBIG;
return EOF;
}
/* Grow the buffer, if necessary. Choose a geometric growth factor
to avoid quadratic realloc behavior, but use a rate less than
(1+sqrt(5))/2 to accomodate malloc overhead. Overallocate, so
that we can add a trailing \0 without reallocating. The new
allocation should thus be max(prev_size*1.5, c->pos+n+1). */
if (c->pos + n >= c->max)
{
size_t newsize = c->max * 3 / 2;
if (newsize < c->pos + n + 1)
newsize = c->pos + n + 1;
cbuf = _realloc_r (ptr, cbuf, newsize);
if (! cbuf)
return EOF; /* errno already set to ENOMEM */
*c->pbuf = cbuf;
c->max = newsize;
}
/* If we have previously done a seek beyond eof, ensure all
intermediate bytes are NUL. */
if (c->pos > c->eof)
memset (cbuf + c->eof, '\0', c->pos - c->eof);
memcpy (cbuf + c->pos, buf, n);
c->pos += n;
/* If the user has previously written further, remember what the
trailing NUL is overwriting. Otherwise, extend the stream. */
if (c->pos > c->eof)
c->eof = c->pos;
else if (c->wide > 0)
c->saved.w = *(wchar_t *)(cbuf + c->pos);
else
c->saved.c = cbuf[c->pos];
cbuf[c->pos] = '\0';
*c->psize = (c->wide > 0) ? c->pos / sizeof (wchar_t) : c->pos;
return n;
}
/* Seek to position POS relative to WHENCE within stream described by
COOKIE; return resulting position or fail with EOF. */
static _fpos_t
_DEFUN(memseeker, (ptr, cookie, pos, whence),
struct _reent *ptr _AND
void *cookie _AND
_fpos_t pos _AND
int whence)
{
memstream *c = (memstream *) cookie;
OFF_T offset = (OFF_T) pos;
if (whence == SEEK_CUR)
offset += c->pos;
else if (whence == SEEK_END)
offset += c->eof;
if (offset < 0)
{
ptr->_errno = EINVAL;
offset = -1;
}
else if ((size_t) offset != offset)
{
ptr->_errno = ENOSPC;
offset = -1;
}
#ifdef __LARGE64_FILES
else if ((_fpos_t) offset != offset)
{
ptr->_errno = EOVERFLOW;
offset = -1;
}
#endif /* __LARGE64_FILES */
else
{
if (c->pos < c->eof)
{
if (c->wide > 0)
*(wchar_t *)((*c->pbuf) + c->pos) = c->saved.w;
else
(*c->pbuf)[c->pos] = c->saved.c;
c->saved.w = L'\0';
}
c->pos = offset;
if (c->pos < c->eof)
{
if (c->wide > 0)
{
c->saved.w = *(wchar_t *)((*c->pbuf) + c->pos);
*(wchar_t *)((*c->pbuf) + c->pos) = L'\0';
*c->psize = c->pos / sizeof (wchar_t);
}
else
{
c->saved.c = (*c->pbuf)[c->pos];
(*c->pbuf)[c->pos] = '\0';
*c->psize = c->pos;
}
}
else if (c->wide > 0)
*c->psize = c->eof / sizeof (wchar_t);
else
*c->psize = c->eof;
}
return (_fpos_t) offset;
}
/* Seek to position POS relative to WHENCE within stream described by
COOKIE; return resulting position or fail with EOF. */
#ifdef __LARGE64_FILES
static _fpos64_t
_DEFUN(memseeker64, (ptr, cookie, pos, whence),
struct _reent *ptr _AND
void *cookie _AND
_fpos64_t pos _AND
int whence)
{
_off64_t offset = (_off64_t) pos;
memstream *c = (memstream *) cookie;
if (whence == SEEK_CUR)
offset += c->pos;
else if (whence == SEEK_END)
offset += c->eof;
if (offset < 0)
{
ptr->_errno = EINVAL;
offset = -1;
}
else if ((size_t) offset != offset)
{
ptr->_errno = ENOSPC;
offset = -1;
}
else
{
if (c->pos < c->eof)
{
if (c->wide > 0)
*(wchar_t *)((*c->pbuf) + c->pos) = c->saved.w;
else
(*c->pbuf)[c->pos] = c->saved.c;
c->saved.w = L'\0';
}
c->pos = offset;
if (c->pos < c->eof)
{
if (c->wide > 0)
{
c->saved.w = *(wchar_t *)((*c->pbuf) + c->pos);
*(wchar_t *)((*c->pbuf) + c->pos) = L'\0';
*c->psize = c->pos / sizeof (wchar_t);
}
else
{
c->saved.c = (*c->pbuf)[c->pos];
(*c->pbuf)[c->pos] = '\0';
*c->psize = c->pos;
}
}
else if (c->wide > 0)
*c->psize = c->eof / sizeof (wchar_t);
else
*c->psize = c->eof;
}
return (_fpos64_t) offset;
}
#endif /* __LARGE64_FILES */
/* Reclaim resources used by stream described by COOKIE. */
static int
_DEFUN(memcloser, (ptr, cookie),
struct _reent *ptr _AND
void *cookie)
{
memstream *c = (memstream *) cookie;
char *buf;
/* Be nice and try to reduce any unused memory. */
buf = _realloc_r (ptr, *c->pbuf,
c->wide > 0 ? (*c->psize + 1) * sizeof (wchar_t)
: *c->psize + 1);
if (buf)
*c->pbuf = buf;
_free_r (ptr, c->storage);
return 0;
}
/* Open a memstream that tracks a dynamic buffer in BUF and SIZE.
Return the new stream, or fail with NULL. */
static FILE *
_DEFUN(internal_open_memstream_r, (ptr, buf, size, wide),
struct _reent *ptr _AND
char **buf _AND
size_t *size _AND
int wide)
{
FILE *fp;
memstream *c;
if (!buf || !size)
{
ptr->_errno = EINVAL;
return NULL;
}
if ((fp = __sfp (ptr)) == NULL)
return NULL;
if ((c = (memstream *) _malloc_r (ptr, sizeof *c)) == NULL)
{
_newlib_sfp_lock_start ();
fp->_flags = 0; /* release */
#ifndef __SINGLE_THREAD__
__lock_close_recursive (fp->_lock);
#endif
_newlib_sfp_lock_end ();
return NULL;
}
/* Use *size as a hint for initial sizing, but bound the initial
malloc between 64 bytes (same as asprintf, to avoid frequent
mallocs on small strings) and 64k bytes (to avoid overusing the
heap if *size was garbage). */
c->max = *size;
if (wide == 1)
c->max *= sizeof(wchar_t);
if (c->max < 64)
c->max = 64;
#if (SIZE_MAX >= 64 * 1024)
else if (c->max > 64 * 1024)
c->max = 64 * 1024;
#endif
*size = 0;
*buf = _malloc_r (ptr, c->max);
if (!*buf)
{
_newlib_sfp_lock_start ();
fp->_flags = 0; /* release */
#ifndef __SINGLE_THREAD__
__lock_close_recursive (fp->_lock);
#endif
_newlib_sfp_lock_end ();
_free_r (ptr, c);
return NULL;
}
if (wide == 1)
**((wchar_t **)buf) = L'\0';
else
**buf = '\0';
c->storage = c;
c->pbuf = buf;
c->psize = size;
c->pos = 0;
c->eof = 0;
c->saved.w = L'\0';
c->wide = (int8_t) wide;
_newlib_flockfile_start (fp);
fp->_file = -1;
fp->_flags = __SWR;
fp->_cookie = c;
fp->_read = NULL;
fp->_write = memwriter;
fp->_seek = memseeker;
#ifdef __LARGE64_FILES
fp->_seek64 = memseeker64;
fp->_flags |= __SL64;
#endif
fp->_close = memcloser;
ORIENT (fp, wide);
_newlib_flockfile_end (fp);
return fp;
}
FILE *
_DEFUN(_open_memstream_r, (ptr, buf, size),
struct _reent *ptr _AND
char **buf _AND
size_t *size)
{
return internal_open_memstream_r (ptr, buf, size, -1);
}
FILE *
_DEFUN(_open_wmemstream_r, (ptr, buf, size),
struct _reent *ptr _AND
wchar_t **buf _AND
size_t *size)
{
return internal_open_memstream_r (ptr, (char **)buf, size, 1);
}
#ifndef _REENT_ONLY
FILE *
_DEFUN(open_memstream, (buf, size),
char **buf _AND
size_t *size)
{
return _open_memstream_r (_REENT, buf, size);
}
FILE *
_DEFUN(open_wmemstream, (buf, size),
wchar_t **buf _AND
size_t *size)
{
return _open_wmemstream_r (_REENT, buf, size);
}
#endif /* !_REENT_ONLY */

View File

@ -0,0 +1,93 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
FUNCTION
<<putc_unlocked>>---non-thread-safe version of putc (macro)
INDEX
putc_unlocked
INDEX
_putc_unlocked_r
SYNOPSIS
#include <stdio.h>
int putc_unlocked(int <[ch]>, FILE *<[fp]>);
#include <stdio.h>
int _putc_unlocked_r(struct _reent *<[ptr]>, int <[ch]>, FILE *<[fp]>);
DESCRIPTION
<<putc_unlocked>> is a non-thread-safe version of <<putc>> declared in
<<stdio.h>>. <<putc_unlocked>> may only safely be used within a scope
protected by flockfile() (or ftrylockfile()) and funlockfile(). These
functions may safely be used in a multi-threaded program if and only
if they are called while the invoking thread owns the ( FILE *)
object, as is the case after a successful call to the flockfile() or
ftrylockfile() functions. If threads are disabled, then
<<putc_unlocked>> is equivalent to <<putc>>.
The function <<_putc_unlocked_r>> is simply the reentrant version of
<<putc_unlocked>> that takes an additional reentrant structure pointer
argument: <[ptr]>.
RETURNS
See <<putc>>.
PORTABILITY
POSIX 1003.1 requires <<putc_unlocked>>. <<putc_unlocked>> may be
implemented as a macro, so arguments should not have side-effects.
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "%W% (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#include <_ansi.h>
#include <stdio.h>
/*
* A subroutine version of the macro putc_unlocked.
*/
#undef putc_unlocked
int
_DEFUN(_putc_unlocked_r, (ptr, c, fp),
struct _reent *ptr _AND
int c _AND
register FILE *fp)
{
/* CHECK_INIT is (eventually) called by __swbuf. */
return __sputc_r (ptr, c, fp);
}
#ifndef _REENT_ONLY
int
_DEFUN(putc_unlocked, (c, fp),
int c _AND
register FILE *fp)
{
/* CHECK_INIT is (eventually) called by __swbuf. */
return __sputc_r (_REENT, c, fp);
}
#endif /* !_REENT_ONLY */

View File

@ -0,0 +1,82 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
FUNCTION
<<putchar_unlocked>>---non-thread-safe version of putchar (macro)
INDEX
putchar_unlocked
SYNOPSIS
#include <stdio.h>
int putchar_unlocked(int <[ch]>);
DESCRIPTION
<<putchar_unlocked>> is a non-thread-safe version of <<putchar>>
declared in <<stdio.h>>. <<putchar_unlocked>> may only safely be used
within a scope protected by flockfile() (or ftrylockfile()) and
funlockfile(). These functions may safely be used in a multi-threaded
program if and only if they are called while the invoking thread owns
the ( FILE *) object, as is the case after a successful call to the
flockfile() or ftrylockfile() functions. If threads are disabled,
then <<putchar_unlocked>> is equivalent to <<putchar>>.
RETURNS
See <<putchar>>.
PORTABILITY
POSIX 1003.1 requires <<putchar_unlocked>>. <<putchar_unlocked>> may
be implemented as a macro.
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>. */
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "%W% (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
/*
* A subroutine version of the macro putchar_unlocked.
*/
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#undef putchar_unlocked
int
_DEFUN(_putchar_unlocked_r, (ptr, c),
struct _reent *ptr _AND
int c)
{
return putc_unlocked (c, _stdout_r (ptr));
}
#ifndef _REENT_ONLY
int
_DEFUN(putchar_unlocked, (c),
int c)
{
/* CHECK_INIT is (eventually) called by __swbuf. */
return _putchar_unlocked_r (_REENT, c);
}
#endif

View File

@ -0,0 +1,90 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#ifdef _HAVE_STDC
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include "local.h"
#ifndef _REENT_ONLY
int
#ifdef _HAVE_STDC
scanf(_CONST char *__restrict fmt, ...)
#else
scanf(fmt, va_alist)
char *fmt;
va_dcl
#endif
{
int ret;
va_list ap;
struct _reent *reent = _REENT;
_REENT_SMALL_CHECK_INIT (reent);
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
va_start (ap);
#endif
ret = _vfscanf_r (reent, _stdin_r (reent), fmt, ap);
va_end (ap);
return ret;
}
#ifdef _NANO_FORMATTED_IO
int
_EXFUN(iscanf, (const char *, ...)
_ATTRIBUTE ((__alias__("scanf"))));
#endif
#endif /* !_REENT_ONLY */
int
#ifdef _HAVE_STDC
_scanf_r(struct _reent *ptr, _CONST char *__restrict fmt, ...)
#else
_scanf_r(ptr, fmt, va_alist)
struct _reent *ptr;
char *fmt;
va_dcl
#endif
{
int ret;
va_list ap;
_REENT_SMALL_CHECK_INIT (ptr);
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
va_start (ap);
#endif
ret = _vfscanf_r (ptr, _stdin_r (ptr), fmt, ap);
va_end (ap);
return (ret);
}
#ifdef _NANO_FORMATTED_IO
int
_EXFUN(_iscanf_r, (struct _reent *, const char *, ...)
_ATTRIBUTE ((__alias__("_scanf_r"))));
#endif

View File

@ -0,0 +1,79 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
FUNCTION
<<setbuf>>---specify full buffering for a file or stream
INDEX
setbuf
ANSI_SYNOPSIS
#include <stdio.h>
void setbuf(FILE *<[fp]>, char *<[buf]>);
TRAD_SYNOPSIS
#include <stdio.h>
void setbuf(<[fp]>, <[buf]>)
FILE *<[fp]>;
char *<[buf]>;
DESCRIPTION
<<setbuf>> specifies that output to the file or stream identified by <[fp]>
should be fully buffered. All output for this file will go to a
buffer (of size <<BUFSIZ>>, specified in `<<stdio.h>>'). Output will
be passed on to the host system only when the buffer is full, or when
an input operation intervenes.
You may, if you wish, supply your own buffer by passing a pointer to
it as the argument <[buf]>. It must have size <<BUFSIZ>>. You can
also use <<NULL>> as the value of <[buf]>, to signal that the
<<setbuf>> function is to allocate the buffer.
WARNINGS
You may only use <<setbuf>> before performing any file operation other
than opening the file.
If you supply a non-null <[buf]>, you must ensure that the associated
storage continues to be available until you close the stream
identified by <[fp]>.
RETURNS
<<setbuf>> does not return a result.
PORTABILITY
Both ANSI C and the System V Interface Definition (Issue 2) require
<<setbuf>>. However, they differ on the meaning of a <<NULL>> buffer
pointer: the SVID issue 2 specification says that a <<NULL>> buffer
pointer requests unbuffered output. For maximum portability, avoid
<<NULL>> buffer pointers.
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
#include <_ansi.h>
#include <stdio.h>
#include "local.h"
_VOID
_DEFUN(setbuf, (fp, buf),
FILE *__restrict fp _AND
char *__restrict buf)
{
_CAST_VOID setvbuf (fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
}

View File

@ -0,0 +1,81 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
Modified copy of setbuf.c to support the setbuffer function
defined as part of BSD.
Modifications by Gareth Pearce, 2001.
*/
/*
FUNCTION
<<setbuffer>>---specify full buffering for a file or stream with size
INDEX
setbuffer
ANSI_SYNOPSIS
#include <stdio.h>
void setbuffer(FILE *<[fp]>, char *<[buf]>, int <[size]>);
TRAD_SYNOPSIS
#include <stdio.h>
void setbuffer(<[fp]>, <[buf]>, <[size]>)
FILE *<[fp]>;
char *<[buf]>;
int <[size]>;
DESCRIPTION
<<setbuffer>> specifies that output to the file or stream identified by
<[fp]> should be fully buffered. All output for this file will go to a
buffer (of size <[size]>). Output will be passed on to the host system
only when the buffer is full, or when an input operation intervenes.
You may, if you wish, supply your own buffer by passing a pointer to
it as the argument <[buf]>. It must have size <[size]>. You can
also use <<NULL>> as the value of <[buf]>, to signal that the
<<setbuffer>> function is to allocate the buffer.
WARNINGS
You may only use <<setbuffer>> before performing any file operation
other than opening the file.
If you supply a non-null <[buf]>, you must ensure that the associated
storage continues to be available until you close the stream
identified by <[fp]>.
RETURNS
<<setbuffer>> does not return a result.
PORTABILITY
This function comes from BSD not ANSI or POSIX.
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
#include <_ansi.h>
#include <stdio.h>
#include "local.h"
_VOID
_DEFUN(setbuffer, (fp, buf, size),
FILE * fp _AND
char *buf _AND
int size)
{
_CAST_VOID setvbuf (fp, buf, buf ? _IOFBF : _IONBF, (size_t) size);
}

View File

@ -0,0 +1,68 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
Modified copy of setbuf.c to support setlinebuf function
defined as part of BSD.
Modifications by Gareth Pearce, 2001.
*/
/*
FUNCTION
<<setlinebuf>>---specify line buffering for a file or stream
INDEX
setlinebuf
ANSI_SYNOPSIS
#include <stdio.h>
void setlinebuf(FILE *<[fp]>);
TRAD_SYNOPSIS
#include <stdio.h>
void setlinebuf(<[fp]>)
FILE *<[fp]>;
DESCRIPTION
<<setlinebuf>> specifies that output to the file or stream identified by
<[fp]> should be line buffered. This causes the file or stream to pass
on output to the host system at every newline, as well as when the
buffer is full, or when an input operation intervenes.
WARNINGS
You may only use <<setlinebuf>> before performing any file operation
other than opening the file.
RETURNS
<<setlinebuf>> returns as per setvbuf.
PORTABILITY
This function comes from BSD not ANSI or POSIX.
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
#include <_ansi.h>
#include <stdio.h>
#include "local.h"
int
_DEFUN(setlinebuf, (fp),
FILE * fp)
{
return (setvbuf (fp, (char *) NULL, _IOLBF, (size_t) 0));
}

View File

@ -104,21 +104,20 @@ _DEFUN(setvbuf, (fp, buf, mode, size),
{
int ret = 0;
struct _reent *reent = _REENT;
size_t iosize;
int ttyflag;
CHECK_INIT (reent, fp);
_newlib_flockfile_start (fp);
/*
* Verify arguments. The `int' limit on `size' is due to this
* particular implementation.
* particular implementation. Note, buf and size are ignored
* when setting _IONBF.
*/
if ((mode != _IOFBF && mode != _IOLBF && mode != _IONBF) || (int)(_POINTER_INT) size < 0)
{
_newlib_flockfile_exit (fp);
if (mode != _IONBF)
if ((mode != _IOFBF && mode != _IOLBF) || (int)(_POINTER_INT) size < 0)
return (EOF);
}
/*
* Write current buffer, if any; drop read count, if any.
@ -126,34 +125,49 @@ _DEFUN(setvbuf, (fp, buf, mode, size),
* Free old buffer if it was from malloc(). Clear line and
* non buffer flags, and clear malloc flag.
*/
_newlib_flockfile_start (fp);
_fflush_r (reent, fp);
fp->_r = 0;
fp->_lbfsize = 0;
if (HASUB(fp))
FREEUB(reent, fp);
fp->_r = fp->_lbfsize = 0;
if (fp->_flags & __SMBF)
_free_r (reent, (_PTR) fp->_bf._base);
fp->_flags &= ~(__SLBF | __SNBF | __SMBF);
fp->_flags &= ~(__SLBF | __SNBF | __SMBF | __SOPT | __SNPT | __SEOF);
if (mode == _IONBF)
goto nbf;
/*
* Allocate buffer if needed. */
* Find optimal I/O size for seek optimization. This also returns
* a `tty flag' to suggest that we check isatty(fd), but we do not
* care since our caller told us how to buffer.
*/
fp->_flags |= __swhatbuf_r (reent, fp, &iosize, &ttyflag);
if (size == 0)
{
buf = NULL;
size = iosize;
}
/* Allocate buffer if needed. */
if (buf == NULL)
{
/* we need this here because malloc() may return a pointer
even if size == 0 */
if (!size) size = BUFSIZ;
if ((buf = malloc (size)) == NULL)
{
/*
* Unable to honor user's request. We will return
* failure, but try again with file system size.
*/
ret = EOF;
/* Try another size... */
buf = malloc (BUFSIZ);
size = BUFSIZ;
if (size != iosize)
{
size = iosize;
buf = malloc (size);
}
}
if (buf == NULL)
{
/* Can't allocate it, let's try another approach */
/* No luck; switch to unbuffered I/O. */
nbf:
fp->_flags |= __SNBF;
fp->_w = 0;
@ -164,35 +178,53 @@ nbf:
}
fp->_flags |= __SMBF;
}
/*
* Now put back whichever flag is needed, and fix _lbfsize
* if line buffered. Ensure output flush on exit if the
* stream will be buffered at all.
* If buf is NULL then make _lbfsize 0 to force the buffer
* to be flushed and hence malloced on first use
* We're committed to buffering from here, so make sure we've
* registered to flush buffers on exit.
*/
if (!reent->__sdidinit)
__sinit(reent);
switch (mode)
{
case _IOLBF:
#ifdef _FSEEK_OPTIMIZATION
/*
* Kill any seek optimization if the buffer is not the
* right size.
*
* SHOULD WE ALLOW MULTIPLES HERE (i.e., ok iff (size % iosize) == 0)?
*/
if (size != iosize)
fp->_flags |= __SNPT;
#endif
/*
* Fix up the FILE fields, and set __cleanup for output flush on
* exit (since we are buffered in some way).
*/
if (mode == _IOLBF)
fp->_flags |= __SLBF;
fp->_lbfsize = buf ? -size : 0;
/* FALLTHROUGH */
case _IOFBF:
/* no flag */
reent->__cleanup = _cleanup_r;
fp->_bf._base = fp->_p = (unsigned char *) buf;
fp->_bf._size = size;
break;
}
/*
* Patch up write count if necessary.
*/
/* fp->_lbfsize is still 0 */
if (fp->_flags & __SWR)
fp->_w = fp->_flags & (__SLBF | __SNBF) ? 0 : size;
{
/*
* Begin or continue writing: see __swsetup(). Note
* that __SNBF is impossible (it was handled earlier).
*/
if (fp->_flags & __SLBF)
{
fp->_w = 0;
fp->_lbfsize = -fp->_bf._size;
}
else
fp->_w = size;
}
else
{
/* begin/continue reading, or stay in intermediate state */
fp->_w = 0;
}
_newlib_flockfile_end (fp);
return 0;

View File

@ -0,0 +1,113 @@
/*
FUNCTION
<<stdio_ext>>,<<__fbufsize>>,<<__fpending>>,<<__flbf>>,<<__freadable>>,<<__fwritable>>,<<__freading>>,<<__fwriting>>---access internals of FILE structure
INDEX
__fbufsize
INDEX
__fpending
INDEX
__flbf
INDEX
__freadable
INDEX
__fwritable
INDEX
__freading
INDEX
__fwriting
ANSI_SYNOPSIS
#include <stdio.h>
#include <stdio_ext.h>
size_t __fbufsize(FILE *<[fp]>);
size_t __fpending(FILE *<[fp]>);
int __flbf(FILE *<[fp]>);
int __freadable(FILE *<[fp]>);
int __fwritable(FILE *<[fp]>);
int __freading(FILE *<[fp]>);
int __fwriting(FILE *<[fp]>);
DESCRIPTION
These functions provides access to the internals of the FILE structure <[fp]>.
RETURNS
<<__fbufsize>> returns the number of bytes in the buffer of stream <[fp]>.
<<__fpending>> returns the number of bytes in the output buffer of stream <[fp]>.
<<__flbf>> returns nonzero if stream <[fp]> is line-buffered, and <<0>> if not.
<<__freadable>> returns nonzero if stream <[fp]> may be read, and <<0>> if not.
<<__fwritable>> returns nonzero if stream <[fp]> may be written, and <<0>> if not.
<<__freading>> returns nonzero if stream <[fp]> if the last operation on
it was a read, or if it read-only, and <<0>> if not.
<<__fwriting>> returns nonzero if stream <[fp]> if the last operation on
it was a write, or if it write-only, and <<0>> if not.
PORTABILITY
These functions originate from Solaris and are also provided by GNU libc.
No supporting OS subroutines are required.
*/
#ifndef __rtems__
#include <_ansi.h>
#include <stdio.h>
/* Subroutine versions of the inline or macro functions. */
size_t
_DEFUN(__fbufsize, (fp),
FILE * fp)
{
return (size_t) fp->_bf._size;
}
size_t
_DEFUN(__fpending, (fp),
FILE * fp)
{
return fp->_p - fp->_bf._base;
}
int
_DEFUN(__flbf, (fp),
FILE * fp)
{
return (fp->_flags & __SLBF) != 0;
}
int
_DEFUN(__freadable, (fp),
FILE * fp)
{
return (fp->_flags & (__SRD | __SRW)) != 0;
}
int
_DEFUN(__fwritable, (fp),
FILE * fp)
{
return (fp->_flags & (__SWR | __SRW)) != 0;
}
int
_DEFUN(__freading, (fp),
FILE * fp)
{
return (fp->_flags & __SRD) != 0;
}
int
_DEFUN(__fwriting, (fp),
FILE * fp)
{
return (fp->_flags & __SWR) != 0;
}
#endif /* __rtems__ */

View File

@ -0,0 +1,65 @@
/*
* Copyright (c) 1990, 2007 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/* This code was based on vsiprintf.c */
/* doc in vfprintf.c */
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "%W% (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#include <_ansi.h>
#include <stdio.h>
#include <limits.h>
#include <stdarg.h>
#include "local.h"
#ifndef _REENT_ONLY
int
_DEFUN(vasiprintf, (strp, fmt, ap),
char **strp _AND
const char *fmt _AND
va_list ap)
{
return _vasiprintf_r (_REENT, strp, fmt, ap);
}
#endif /* !_REENT_ONLY */
int
_DEFUN(_vasiprintf_r, (ptr, strp, fmt, ap),
struct _reent *ptr _AND
char **strp _AND
const char *fmt _AND
va_list ap)
{
int ret;
FILE f;
f._flags = __SWR | __SSTR | __SMBF ;
f._bf._base = f._p = NULL;
f._bf._size = f._w = 0;
f._file = -1; /* No file. */
ret = _svfiprintf_r (ptr, &f, fmt, ap);
if (ret >= 0)
{
*f._p = 0;
*strp = (char *) f._bf._base;
}
return ret;
}

View File

@ -0,0 +1,77 @@
/*
* Copyright (c) 1990, 2007 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/* This code was based on vsprintf.c */
/* doc in vfprintf.c */
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "%W% (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#include <_ansi.h>
#include <stdio.h>
#include <limits.h>
#include <stdarg.h>
#include "local.h"
#ifndef _REENT_ONLY
int
_DEFUN(vasprintf, (strp, fmt, ap),
char **strp _AND
const char *fmt _AND
va_list ap)
{
return _vasprintf_r (_REENT, strp, fmt, ap);
}
#ifdef _NANO_FORMATTED_IO
int
_EXFUN(vasiprintf, (char **, const char *, __VALIST)
_ATTRIBUTE ((__alias__("vasprintf"))));
#endif
#endif /* !_REENT_ONLY */
int
_DEFUN(_vasprintf_r, (ptr, strp, fmt, ap),
struct _reent *ptr _AND
char **strp _AND
const char *fmt _AND
va_list ap)
{
int ret;
FILE f;
f._flags = __SWR | __SSTR | __SMBF ;
f._bf._base = f._p = NULL;
f._bf._size = f._w = 0;
f._file = -1; /* No file. */
ret = _svfprintf_r (ptr, &f, fmt, ap);
if (ret >= 0)
{
*f._p = 0;
*strp = (char *) f._bf._base;
}
return ret;
}
#ifdef _NANO_FORMATTED_IO
int
_EXFUN(_vasiprintf_r, (struct _reent *, char **, const char *, __VALIST)
_ATTRIBUTE ((__alias__("_vasprintf_r"))));
#endif

View File

@ -1332,7 +1332,7 @@ reswitch: switch (ch) {
expsize = exponent (expstr, expt, ch);
size = expsize + ndig;
if (ndig > 1 || flags & ALT)
++size;
size += decp_len;
# ifdef _WANT_IO_C99_FORMATS
flags &= ~GROUPING;
# endif
@ -1341,18 +1341,20 @@ reswitch: switch (ch) {
if (expt > 0) {
size = expt;
if (prec || flags & ALT)
size += prec + 1;
size += prec + decp_len;
} else /* "0.X" */
size = (prec || flags & ALT)
? prec + 2
? prec + 1 + decp_len
: 1;
} else if (expt >= ndig) { /* fixed g fmt */
size = expt;
if (flags & ALT)
++size;
} else
size = ndig + (expt > 0 ?
1 : 2 - expt);
size += decp_len;
} else {
size = ndig + decp_len;
if (expt <= 0)
size += 1 - expt;
}
# ifdef _WANT_IO_C99_FORMATS
if ((flags & GROUPING) && expt > 0) {
/* space for thousands' grouping */

View File

@ -0,0 +1,128 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
FUNCTION
<<viprintf>>, <<vfiprintf>>, <<vsiprintf>>, <<vsniprintf>>, <<vasiprintf>>, <<vasniprintf>>---format argument list (integer only)
INDEX
viprintf
INDEX
_viprintf_r
INDEX
vfiprintf
INDEX
_vfiprintf_r
INDEX
vsiprintf
INDEX
_vsiprintf_r
INDEX
vsniprintf
INDEX
_vsniprintf_r
INDEX
vasiprintf
INDEX
_vasiprintf_r
INDEX
vasniprintf
INDEX
_vasniprintf_r
ANSI_SYNOPSIS
#include <stdio.h>
#include <stdarg.h>
int viprintf(const char *<[fmt]>, va_list <[list]>);
int vfiprintf(FILE *<[fp]>, const char *<[fmt]>, va_list <[list]>);
int vsiprintf(char *<[str]>, const char *<[fmt]>, va_list <[list]>);
int vsniprintf(char *<[str]>, size_t <[size]>, const char *<[fmt]>,
va_list <[list]>);
int vasiprintf(char **<[strp]>, const char *<[fmt]>, va_list <[list]>);
char *vasniprintf(char *<[str]>, size_t *<[size]>, const char *<[fmt]>,
va_list <[list]>);
int _viprintf_r(struct _reent *<[reent]>, const char *<[fmt]>,
va_list <[list]>);
int _vfiprintf_r(struct _reent *<[reent]>, FILE *<[fp]>,
const char *<[fmt]>, va_list <[list]>);
int _vsiprintf_r(struct _reent *<[reent]>, char *<[str]>,
const char *<[fmt]>, va_list <[list]>);
int _vsniprintf_r(struct _reent *<[reent]>, char *<[str]>,
size_t <[size]>, const char *<[fmt]>, va_list <[list]>);
int _vasiprintf_r(struct _reent *<[reent]>, char **<[str]>,
const char *<[fmt]>, va_list <[list]>);
char *_vasniprintf_r(struct _reent *<[reent]>, char *<[str]>,
size_t *<[size]>, const char *<[fmt]>, va_list <[list]>);
DESCRIPTION
<<viprintf>>, <<vfiprintf>>, <<vasiprintf>>, <<vsiprintf>>,
<<vsniprintf>>, and <<vasniprintf>> are (respectively) variants of
<<iprintf>>, <<fiprintf>>, <<asiprintf>>, <<siprintf>>, <<sniprintf>>,
and <<asniprintf>>. They differ only in allowing their caller to pass
the variable argument list as a <<va_list>> object (initialized by
<<va_start>>) rather than directly accepting a variable number of
arguments. The caller is responsible for calling <<va_end>>.
<<_viprintf_r>>, <<_vfiprintf_r>>, <<_vasiprintf_r>>,
<<_vsiprintf_r>>, <<_vsniprintf_r>>, and <<_vasniprintf_r>> are
reentrant versions of the above.
RETURNS
The return values are consistent with the corresponding functions:
PORTABILITY
All of these functions are newlib extensions.
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#ifdef _HAVE_STDC
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include "local.h"
#ifndef _REENT_ONLY
int
_DEFUN(viprintf, (fmt, ap),
_CONST char *fmt _AND
va_list ap)
{
struct _reent *reent = _REENT;
_REENT_SMALL_CHECK_INIT (reent);
return _vfiprintf_r (reent, _stdout_r (reent), fmt, ap);
}
#endif /* !_REENT_ONLY */
int
_DEFUN(_viprintf_r, (ptr, fmt, ap),
struct _reent *ptr _AND
_CONST char *fmt _AND
va_list ap)
{
_REENT_SMALL_CHECK_INIT (ptr);
return _vfiprintf_r (ptr, _stdout_r (ptr), fmt, ap);
}

View File

@ -0,0 +1,147 @@
/*-
* Code created by modifying iscanf.c which has following copyright.
*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
FUNCTION
<<viscanf>>, <<vfiscanf>>, <<vsiscanf>>---format argument list
INDEX
viscanf
INDEX
_viscanf_r
INDEX
vfiscanf
INDEX
_vfiscanf_r
INDEX
vsiscanf
INDEX
_vsiscanf_r
ANSI_SYNOPSIS
#include <stdio.h>
#include <stdarg.h>
int viscanf(const char *<[fmt]>, va_list <[list]>);
int vfiscanf(FILE *<[fp]>, const char *<[fmt]>, va_list <[list]>);
int vsiscanf(const char *<[str]>, const char *<[fmt]>, va_list <[list]>);
int _viscanf_r(struct _reent *<[reent]>, const char *<[fmt]>,
va_list <[list]>);
int _vfiscanf_r(struct _reent *<[reent]>, FILE *<[fp]>, const char *<[fmt]>,
va_list <[list]>);
int _vsiscanf_r(struct _reent *<[reent]>, const char *<[str]>,
const char *<[fmt]>, va_list <[list]>);
TRAD_SYNOPSIS
#include <stdio.h>
#include <varargs.h>
int viscanf( <[fmt]>, <[ist]>)
char *<[fmt]>;
va_list <[list]>;
int vfiscanf( <[fp]>, <[fmt]>, <[list]>)
FILE *<[fp]>;
char *<[fmt]>;
va_list <[list]>;
int vsiscanf( <[str]>, <[fmt]>, <[list]>)
char *<[str]>;
char *<[fmt]>;
va_list <[list]>;
int _viscanf_r( <[reent]>, <[fmt]>, <[ist]>)
struct _reent *<[reent]>;
char *<[fmt]>;
va_list <[list]>;
int _vfiscanf_r( <[reent]>, <[fp]>, <[fmt]>, <[list]>)
struct _reent *<[reent]>;
FILE *<[fp]>;
char *<[fmt]>;
va_list <[list]>;
int _vsiscanf_r( <[reent]>, <[str]>, <[fmt]>, <[list]>)
struct _reent *<[reent]>;
char *<[str]>;
char *<[fmt]>;
va_list <[list]>;
DESCRIPTION
<<viscanf>>, <<vfiscanf>>, and <<vsiscanf>> are (respectively) variants
of <<iscanf>>, <<fiscanf>>, and <<siscanf>>. They differ only in
allowing their caller to pass the variable argument list as a
<<va_list>> object (initialized by <<va_start>>) rather than
directly accepting a variable number of arguments.
RETURNS
The return values are consistent with the corresponding functions:
<<viscanf>> returns the number of input fields successfully scanned,
converted, and stored; the return value does not include scanned
fields which were not stored.
If <<viscanf>> attempts to read at end-of-file, the return value
is <<EOF>>.
If no fields were stored, the return value is <<0>>.
The routines <<_viscanf_r>>, <<_vfiscanf_f>>, and <<_vsiscanf_r>> are
reentrant versions which take an additional first parameter which points to the
reentrancy structure.
PORTABILITY
These are newlib extensions.
Supporting OS subroutines required:
*/
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#ifdef _HAVE_STDC
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include "local.h"
#ifndef _REENT_ONLY
int
_DEFUN(viscanf, (fmt, ap),
_CONST char *fmt _AND
va_list ap)
{
struct _reent *reent = _REENT;
_REENT_SMALL_CHECK_INIT (reent);
return __svfiscanf_r (reent, _stdin_r (reent), fmt, ap);
}
#endif /* !_REENT_ONLY */
int
_DEFUN(_viscanf_r, (ptr, fmt, ap),
struct _reent *ptr _AND
_CONST char *fmt _AND
va_list ap)
{
_REENT_SMALL_CHECK_INIT (ptr);
return __svfiscanf_r (ptr, _stdin_r (ptr), fmt, ap);
}

View File

@ -0,0 +1,63 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/* doc in vfprintf.c */
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#ifdef _HAVE_STDC
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include "local.h"
#ifndef _REENT_ONLY
int
_DEFUN(vprintf, (fmt, ap),
_CONST char *fmt _AND
va_list ap)
{
struct _reent *reent = _REENT;
_REENT_SMALL_CHECK_INIT (reent);
return _vfprintf_r (reent, _stdout_r (reent), fmt, ap);
}
#ifdef _NANO_FORMATTED_IO
int
_EXFUN(viprintf, (const char *, __VALIST) _ATTRIBUTE ((__alias__("vprintf"))));
#endif
#endif /* !_REENT_ONLY */
int
_DEFUN(_vprintf_r, (ptr, fmt, ap),
struct _reent *ptr _AND
_CONST char *__restrict fmt _AND
va_list ap)
{
_REENT_SMALL_CHECK_INIT (ptr);
return _vfprintf_r (ptr, _stdout_r (ptr), fmt, ap);
}
#ifdef _NANO_FORMATTED_IO
int
_EXFUN(_viprintf_r, (struct _reent *, const char *, __VALIST)
_ATTRIBUTE ((__alias__("_vprintf_r"))));
#endif

View File

@ -0,0 +1,61 @@
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/* doc in viprintf.c */
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "%W% (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include <limits.h>
#include <stdarg.h>
#include "local.h"
#ifndef _REENT_ONLY
int
_DEFUN(vsiprintf, (str, fmt, ap),
char *str _AND
const char *fmt _AND
va_list ap)
{
return _vsiprintf_r (_REENT, str, fmt, ap);
}
#endif /* !_REENT_ONLY */
int
_DEFUN(_vsiprintf_r, (ptr, str, fmt, ap),
struct _reent *ptr _AND
char *str _AND
const char *fmt _AND
va_list ap)
{
int ret;
FILE f;
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *) str;
f._bf._size = f._w = INT_MAX;
f._file = -1; /* No file. */
ret = _svfiprintf_r (ptr, &f, fmt, ap);
*f._p = 0;
return ret;
}

View File

@ -0,0 +1,65 @@
/*
* Code created by modifying iscanf.c which has following copyright.
*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include <string.h>
#ifdef _HAVE_STDC
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include "local.h"
/*
* vsiscanf
*/
#ifndef _REENT_ONLY
int
_DEFUN(vsiscanf, (str, fmt, ap),
_CONST char *str _AND
_CONST char *fmt _AND
va_list ap)
{
return _vsiscanf_r (_REENT, str, fmt, ap);
}
#endif /* !_REENT_ONLY */
int
_DEFUN(_vsiscanf_r, (ptr, str, fmt, ap),
struct _reent *ptr _AND
_CONST char *str _AND
_CONST char *fmt _AND
va_list ap)
{
FILE f;
f._flags = __SRD | __SSTR;
f._bf._base = f._p = (unsigned char *) str;
f._bf._size = f._r = strlen (str);
f._read = __seofread;
f._ub._base = NULL;
f._lb._base = NULL;
f._file = -1; /* No file. */
return __ssvfiscanf_r (ptr, &f, fmt, ap);
}

View File

@ -0,0 +1,72 @@
/*
* Copyright (c) 1990, 2007 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/* doc in viprintf.c */
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "%W% (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>
#include <limits.h>
#include <stdarg.h>
#include <errno.h>
#include "local.h"
#ifndef _REENT_ONLY
int
_DEFUN(vsniprintf, (str, size, fmt, ap),
char *str _AND
size_t size _AND
const char *fmt _AND
va_list ap)
{
return _vsniprintf_r (_REENT, str, size, fmt, ap);
}
#endif /* !_REENT_ONLY */
int
_DEFUN(_vsniprintf_r, (ptr, str, size, fmt, ap),
struct _reent *ptr _AND
char *str _AND
size_t size _AND
const char *fmt _AND
va_list ap)
{
int ret;
FILE f;
if (size > INT_MAX)
{
ptr->_errno = EOVERFLOW;
return EOF;
}
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *) str;
f._bf._size = f._w = (size > 0 ? size - 1 : 0);
f._file = -1; /* No file. */
ret = _svfiprintf_r (ptr, &f, fmt, ap);
if (ret < EOF)
ptr->_errno = EOVERFLOW;
if (size > 0)
*f._p = 0;
return ret;
}

Some files were not shown because too many files have changed in this diff Show More