RC_$(ARCH) = 1
RC_ARCHS = $(ARCH)
endif
-# temporary disable multi-threaded builds, which are failing; see 3683272
-#BSDMAKE = bsdmake -j 2
-BSDMAKE = bsdmake
+ifdef ALTUSRLOCALLIBSYSTEM
+LIBSYS = $(ALTUSRLOCALLIBSYSTEM)
+else
+LIBSYS = $(NEXT_ROOT)/usr/local/lib/system
+endif
+NJOBS = $(shell perl -e '$$n = `/usr/sbin/sysctl -n hw.ncpu`; printf "%d\n", $$n < 2 ? 2 : ($$n * 1.5)')
+BSDMAKE = bsdmake -j $(NJOBS)
# Remove the arch stuff, since we know better here.
LOCAL_CFLAGS = $(filter-out -arch ppc -arch ppc64 -arch i386,$(RC_CFLAGS))
install: BI-install-profile
endif
-build-static: autopatch build-ppc-static build-ppc64-static build-i386-static
+# Because of 3780028, there are random failures on HFS because the
+# CC_PRINT_OPTIONS_FILE can't be created. So we touch it first.
+ifneq ($(CC_PRINT_OPTIONS_FILE),)
+$(CC_PRINT_OPTIONS_FILE):
+ touch $(CC_PRINT_OPTIONS_FILE)
+endif
+
+build-static: autopatch $(CC_PRINT_OPTIONS_FILE) build-ppc-static build-ppc64-static build-i386-static
@echo "Creating final libc_static.a"
ifeq ($(words $(RC_ARCHS)),1)
cp -p "$(OBJROOT)/obj.$(RC_ARCHS)/libc_static.a" "$(SYMROOT)"
$(foreach A,$(RC_ARCHS),-arch $(A) "$(OBJROOT)/obj.$(A)/libc_static.a") \
-output $(SYMROOT)/libc_static.a
endif
-build-profile: autopatch build-ppc-profile build-ppc64-profile build-i386-profile
+build-profile: autopatch $(CC_PRINT_OPTIONS_FILE) build-ppc-profile build-ppc64-profile build-i386-profile
@echo "Creating final libc_profile.a"
ifeq ($(words $(RC_ARCHS)),1)
cp -p "$(OBJROOT)/obj.$(RC_ARCHS)/libc_profile.a" "$(SYMROOT)"
$(foreach A,$(RC_ARCHS),-arch $(A) "$(OBJROOT)/obj.$(A)/libc_profile.a") \
-output $(SYMROOT)/libc_profile.a
endif
-build-debug: autopatch build-ppc-debug build-ppc64-debug build-i386-debug
+build-debug: autopatch $(CC_PRINT_OPTIONS_FILE) build-ppc-debug build-ppc64-debug build-i386-debug
@echo "Creating final libc_debug.a"
ifeq ($(words $(RC_ARCHS)),1)
cp -p "$(OBJROOT)/obj.$(RC_ARCHS)/libc_debug.a" "$(SYMROOT)"
$(foreach A,$(RC_ARCHS),-arch $(A) "$(OBJROOT)/obj.$(A)/libc_debug.a") \
-output $(SYMROOT)/libc_debug.a
endif
-build-dynamic: autopatch build-ppc-dynamic build-ppc64-dynamic build-i386-dynamic
+build-dynamic: autopatch $(CC_PRINT_OPTIONS_FILE) build-ppc-dynamic build-ppc64-dynamic build-i386-dynamic
@echo "Creating final libc.a"
ifeq ($(words $(RC_ARCHS)),1)
cp -p "$(OBJROOT)/obj.$(RC_ARCHS)/libc.a" "$(SYMROOT)"
-output $(SYMROOT)/libc.a
endif
build-ppc-static:
- @if [ ! -z "$(RC_ppc)" ]; then \
- mkdir -p $(OBJROOT)/obj.ppc ; \
- MAKEOBJDIR="$(OBJROOT)/obj.ppc" MACHINE_ARCH="ppc" \
- MAKEFLAGS="" CFLAGS="-arch ppc $(LOCAL_CFLAGS)" $(BSDMAKE) libc_static.a;\
- fi
+ifneq ($(RC_ppc),)
+ mkdir -p $(OBJROOT)/obj.ppc ; \
+ MAKEOBJDIR="$(OBJROOT)/obj.ppc" MACHINE_ARCH="ppc" \
+ MAKEFLAGS="" CFLAGS="-arch ppc $(LOCAL_CFLAGS)" $(BSDMAKE) libc_static.a
+endif
build-ppc64-static:
- @if [ ! -z "$(RC_ppc64)" ]; then \
- mkdir -p $(OBJROOT)/obj.ppc64 ; \
- MAKEOBJDIR="$(OBJROOT)/obj.ppc64" MACHINE_ARCH="ppc64" \
- MAKEFLAGS="" CFLAGS="-arch ppc64 $(LOCAL_CFLAGS)" $(BSDMAKE) libc_static.a;\
- fi
+ifneq ($(RC_ppc64),)
+ mkdir -p $(OBJROOT)/obj.ppc64 ; \
+ MAKEOBJDIR="$(OBJROOT)/obj.ppc64" MACHINE_ARCH="ppc64" \
+ MAKEFLAGS="" CFLAGS="-arch ppc64 $(LOCAL_CFLAGS)" $(BSDMAKE) libc_static.a
+endif
build-i386-static:
- @if [ ! -z "$(RC_i386)" ]; then \
- mkdir -p $(OBJROOT)/obj.i386 ; \
- MAKEOBJDIR="$(OBJROOT)/obj.i386" MACHINE_ARCH="i386" \
- MAKEFLAGS="" CFLAGS="-arch i386 $(LOCAL_CFLAGS)" $(BSDMAKE) libc_static.a;\
- fi
+ifneq ($(RC_i386),)
+ mkdir -p $(OBJROOT)/obj.i386 ; \
+ MAKEOBJDIR="$(OBJROOT)/obj.i386" MACHINE_ARCH="i386" \
+ MAKEFLAGS="" CFLAGS="-arch i386 $(LOCAL_CFLAGS)" $(BSDMAKE) libc_static.a
+endif
build-ppc-profile:
- @if [ ! -z "$(RC_ppc)" ]; then \
- mkdir -p $(OBJROOT)/obj.ppc ; \
- MAKEOBJDIR="$(OBJROOT)/obj.ppc" MACHINE_ARCH="ppc" \
- MAKEFLAGS="" CFLAGS="-arch ppc $(LOCAL_CFLAGS)" $(BSDMAKE) libc_profile.a;\
- fi
+ifneq ($(RC_ppc),)
+ mkdir -p $(OBJROOT)/obj.ppc ; \
+ MAKEOBJDIR="$(OBJROOT)/obj.ppc" MACHINE_ARCH="ppc" \
+ MAKEFLAGS="" CFLAGS="-arch ppc $(LOCAL_CFLAGS)" $(BSDMAKE) libc_profile.a
+endif
build-ppc64-profile:
- @if [ ! -z "$(RC_ppc64)" ]; then \
- mkdir -p $(OBJROOT)/obj.ppc64 ; \
- MAKEOBJDIR="$(OBJROOT)/obj.ppc64" MACHINE_ARCH="ppc64" \
- MAKEFLAGS="" CFLAGS="-arch ppc64 $(LOCAL_CFLAGS)" $(BSDMAKE) libc_profile.a;\
- fi
+ifneq ($(RC_ppc64),)
+ mkdir -p $(OBJROOT)/obj.ppc64 ; \
+ MAKEOBJDIR="$(OBJROOT)/obj.ppc64" MACHINE_ARCH="ppc64" \
+ MAKEFLAGS="" CFLAGS="-arch ppc64 $(LOCAL_CFLAGS)" $(BSDMAKE) libc_profile.a
+endif
build-i386-profile:
- @if [ ! -z "$(RC_i386)" ]; then \
- mkdir -p $(OBJROOT)/obj.i386 ; \
- MAKEOBJDIR="$(OBJROOT)/obj.i386" MACHINE_ARCH="i386" \
- MAKEFLAGS="" CFLAGS="-arch i386 $(LOCAL_CFLAGS)" $(BSDMAKE) libc_profile.a;\
- fi
+ifneq ($(RC_i386),)
+ mkdir -p $(OBJROOT)/obj.i386 ; \
+ MAKEOBJDIR="$(OBJROOT)/obj.i386" MACHINE_ARCH="i386" \
+ MAKEFLAGS="" CFLAGS="-arch i386 $(LOCAL_CFLAGS)" $(BSDMAKE) libc_profile.a
+endif
build-ppc-debug:
- @if [ ! -z "$(RC_ppc)" ]; then \
- mkdir -p $(OBJROOT)/obj.ppc ; \
- MAKEOBJDIR="$(OBJROOT)/obj.ppc" MACHINE_ARCH="ppc" \
- MAKEFLAGS="" CFLAGS="-arch ppc $(LOCAL_CFLAGS)" $(BSDMAKE) libc_debug.a;\
- fi
+ifneq ($(RC_ppc),)
+ mkdir -p $(OBJROOT)/obj.ppc ; \
+ MAKEOBJDIR="$(OBJROOT)/obj.ppc" MACHINE_ARCH="ppc" \
+ MAKEFLAGS="" CFLAGS="-arch ppc $(LOCAL_CFLAGS)" $(BSDMAKE) libc_debug.a
+endif
build-ppc64-debug:
- @if [ ! -z "$(RC_ppc64)" ]; then \
- mkdir -p $(OBJROOT)/obj.ppc64 ; \
- MAKEOBJDIR="$(OBJROOT)/obj.ppc64" MACHINE_ARCH="ppc64" \
- MAKEFLAGS="" CFLAGS="-arch ppc64 $(LOCAL_CFLAGS)" $(BSDMAKE) libc_debug.a;\
- fi
+ifneq ($(RC_ppc64),)
+ mkdir -p $(OBJROOT)/obj.ppc64 ; \
+ MAKEOBJDIR="$(OBJROOT)/obj.ppc64" MACHINE_ARCH="ppc64" \
+ MAKEFLAGS="" CFLAGS="-arch ppc64 $(LOCAL_CFLAGS)" $(BSDMAKE) libc_debug.a
+endif
build-i386-debug:
- @if [ ! -z "$(RC_i386)" ]; then \
- mkdir -p $(OBJROOT)/obj.i386 ; \
- MAKEOBJDIR="$(OBJROOT)/obj.i386" MACHINE_ARCH="i386" \
- MAKEFLAGS="" CFLAGS="-arch i386 $(LOCAL_CFLAGS)" $(BSDMAKE) libc_debug.a;\
- fi
+ifneq ($(RC_i386),)
+ mkdir -p $(OBJROOT)/obj.i386 ; \
+ MAKEOBJDIR="$(OBJROOT)/obj.i386" MACHINE_ARCH="i386" \
+ MAKEFLAGS="" CFLAGS="-arch i386 $(LOCAL_CFLAGS)" $(BSDMAKE) libc_debug.a
+endif
build-ppc-dynamic:
- @if [ ! -z "$(RC_ppc)" ]; then \
- mkdir -p $(OBJROOT)/obj.ppc ; \
- MAKEOBJDIR="$(OBJROOT)/obj.ppc" MACHINE_ARCH="ppc" \
- MAKEFLAGS="" CFLAGS="-arch ppc $(LOCAL_CFLAGS)" $(BSDMAKE) libc.a;\
- fi
+ifneq ($(RC_ppc),)
+ mkdir -p $(OBJROOT)/obj.ppc ; \
+ MAKEOBJDIR="$(OBJROOT)/obj.ppc" MACHINE_ARCH="ppc" \
+ MAKEFLAGS="" CFLAGS="-arch ppc $(LOCAL_CFLAGS)" $(BSDMAKE) libc.a
+endif
build-ppc64-dynamic:
- @if [ ! -z "$(RC_ppc64)" ]; then \
- mkdir -p $(OBJROOT)/obj.ppc64 ; \
- MAKEOBJDIR="$(OBJROOT)/obj.ppc64" MACHINE_ARCH="ppc64" \
- MAKEFLAGS="" CFLAGS="-arch ppc64 $(LOCAL_CFLAGS)" $(BSDMAKE) libc.a;\
- fi
+ifneq ($(RC_ppc64),)
+ mkdir -p $(OBJROOT)/obj.ppc64 ; \
+ MAKEOBJDIR="$(OBJROOT)/obj.ppc64" MACHINE_ARCH="ppc64" \
+ MAKEFLAGS="" CFLAGS="-arch ppc64 $(LOCAL_CFLAGS)" $(BSDMAKE) libc.a
+endif
build-i386-dynamic:
- @if [ ! -z "$(RC_i386)" ]; then \
- mkdir -p $(OBJROOT)/obj.i386 ; \
- MAKEOBJDIR="$(OBJROOT)/obj.i386" MACHINE_ARCH="i386" \
- MAKEFLAGS="" CFLAGS="-arch i386 $(LOCAL_CFLAGS)" $(BSDMAKE) libc.a;\
- fi
-
+ifneq ($(RC_i386),)
+ mkdir -p $(OBJROOT)/obj.i386 ; \
+ MAKEOBJDIR="$(OBJROOT)/obj.i386" MACHINE_ARCH="i386" \
+ MAKEFLAGS="" CFLAGS="-arch i386 $(LOCAL_CFLAGS)" $(BSDMAKE) libc.a
+endif
build-ppc:
- @if [ ! -z "$(RC_ppc)" ]; then \
- mkdir -p $(OBJROOT)/obj.ppc ; \
- MAKEOBJDIR="$(OBJROOT)/obj.ppc" MACHINE_ARCH="ppc" \
- MAKEFLAGS="" CFLAGS="-arch ppc $(LOCAL_CFLAGS)" $(BSDMAKE) build;\
- fi
+ifneq ($(RC_ppc),)
+ mkdir -p $(OBJROOT)/obj.ppc ; \
+ MAKEOBJDIR="$(OBJROOT)/obj.ppc" MACHINE_ARCH="ppc" \
+ MAKEFLAGS="" CFLAGS="-arch ppc $(LOCAL_CFLAGS)" $(BSDMAKE) build
+endif
build-ppc64:
- @if [ ! -z "$(RC_ppc64)" ]; then \
- mkdir -p $(OBJROOT)/obj.ppc64 ; \
- MAKEOBJDIR="$(OBJROOT)/obj.ppc64" MACHINE_ARCH="ppc64" \
- MAKEFLAGS="" CFLAGS="-arch ppc64 $(LOCAL_CFLAGS)" $(BSDMAKE) build;\
- fi
+ifneq ($(RC_ppc64),)
+ mkdir -p $(OBJROOT)/obj.ppc64 ; \
+ MAKEOBJDIR="$(OBJROOT)/obj.ppc64" MACHINE_ARCH="ppc64" \
+ MAKEFLAGS="" CFLAGS="-arch ppc64 $(LOCAL_CFLAGS)" $(BSDMAKE) build
+endif
build-i386:
- @if [ ! -z "$(RC_i386)" ]; then \
- mkdir -p $(OBJROOT)/obj.i386 ; \
- MAKEOBJDIR="$(OBJROOT)/obj.i386" MACHINE_ARCH="i386" \
- MAKEFLAGS="" CFLAGS="-arch i386 $(LOCAL_CFLAGS)" $(BSDMAKE) build;\
- fi
+ifneq ($(RC_i386),)
+ mkdir -p $(OBJROOT)/obj.i386 ; \
+ MAKEOBJDIR="$(OBJROOT)/obj.i386" MACHINE_ARCH="i386" \
+ MAKEFLAGS="" CFLAGS="-arch i386 $(LOCAL_CFLAGS)" $(BSDMAKE) build
+endif
# We have to separately call bsdmake to patch the FreeBSD files, because of
# the way its cache works, it would otherwise pick a file in ${SYMROOT}, even
# over a .s file.
autopatch:
- @if [ ! -z "$(RC_i386)" ]; then \
- MACHINE_ARCH="i386" $(BSDMAKE) autopatch; \
- fi
- @if [ ! -z "$(RC_ppc)" ]; then \
- MACHINE_ARCH="ppc" $(BSDMAKE) autopatch; \
- fi
- @if [ ! -z "$(RC_ppc64)" ]; then \
- MACHINE_ARCH="ppc64" $(BSDMAKE) autopatch; \
- fi
+ifneq ($(RC_i386),)
+ MACHINE_ARCH="i386" $(BSDMAKE) autopatch
+endif
+ifneq ($(RC_ppc),)
+ MACHINE_ARCH="ppc" $(BSDMAKE) autopatch
+endif
+ifneq ($(RC_ppc64),)
+ MACHINE_ARCH="ppc64" $(BSDMAKE) autopatch
+endif
installsrc:
$(_v) pax -rw . "$(SRCROOT)"
-installhdrs-real:
+installhdrs-real: $(CC_PRINT_OPTIONS_FILE)
MAKEOBJDIR="$(OBJROOT)" DESTDIR="$(DSTROOT)" MAKEFLAGS="" \
$(BSDMAKE) installhdrs
- @if [ ! -z "$(RC_i386)" ]; then \
- mkdir -p "$(OBJROOT)/obj.i386" ; \
- MAKEOBJDIR="$(OBJROOT)/obj.i386" MACHINE_ARCH="i386" \
- MAKEFLAGS="" $(BSDMAKE) installhdrs-md ; \
- fi
- @if [ ! -z "$(RC_ppc)" ]; then \
- mkdir -p "$(OBJROOT)/obj.ppc" ; \
- MAKEOBJDIR="$(OBJROOT)/obj.ppc" MACHINE_ARCH="ppc" \
- MAKEFLAGS="" $(BSDMAKE) installhdrs-md ; \
- fi
- @if [ ! -z "$(RC_ppc64)" ]; then \
- mkdir -p "$(OBJROOT)/obj.ppc64" ; \
- MAKEOBJDIR="$(OBJROOT)/obj.ppc64" MACHINE_ARCH="ppc64" \
- MAKEFLAGS="" $(BSDMAKE) installhdrs-md ; \
- fi
+ifneq ($(RC_i386),)
+ mkdir -p "$(OBJROOT)/obj.i386" ; \
+ MAKEOBJDIR="$(OBJROOT)/obj.i386" MACHINE_ARCH="i386" \
+ MAKEFLAGS="" $(BSDMAKE) installhdrs-md
+endif
+ifneq ($(RC_ppc),)
+ mkdir -p "$(OBJROOT)/obj.ppc" ; \
+ MAKEOBJDIR="$(OBJROOT)/obj.ppc" MACHINE_ARCH="ppc" \
+ MAKEFLAGS="" $(BSDMAKE) installhdrs-md
+endif
+ifneq ($(RC_ppc64),)
+ mkdir -p "$(OBJROOT)/obj.ppc64" ; \
+ MAKEOBJDIR="$(OBJROOT)/obj.ppc64" MACHINE_ARCH="ppc64" \
+ MAKEFLAGS="" $(BSDMAKE) installhdrs-md
+endif
BI-install-static: build-static
mkdir -p $(DSTROOT)/usr/local/lib/system
$(DSTROOT)/usr/local/lib/system; \
ranlib "$(DSTROOT)/usr/local/lib/system/libc_profile.a"; \
fi
+ifneq ($(RC_ppc),)
+ if [ -f "$(OBJROOT)/obj.ppc/libc-ldbl128_profile.a" ]; then \
+ echo "Installing libldbl128_profile.a" ; \
+ $(SRCROOT)/make_libldbl128 "$(OBJROOT)/obj.ppc/libc-ldbl128_profile.a" \
+ "_profile" "$(DSTROOT)/usr/local/lib/system" $(LIBSYS) ; \
+ fi
+endif
BI-install-debug: build-debug
mkdir -p $(DSTROOT)/usr/local/lib/system
if [ -f "$(SYMROOT)/libc_debug.a" ]; then \
$(DSTROOT)/usr/local/lib/system; \
ranlib "$(DSTROOT)/usr/local/lib/system/libc_debug.a"; \
fi
+ifneq ($(RC_ppc),)
+ if [ -f "$(OBJROOT)/obj.ppc/libc-ldbl128_debug.a" ]; then \
+ echo "Installing libldbl128_debug.a" ; \
+ $(SRCROOT)/make_libldbl128 "$(OBJROOT)/obj.ppc/libc-ldbl128_debug.a" \
+ "_debug" "$(DSTROOT)/usr/local/lib/system" $(LIBSYS) ; \
+ fi
+endif
BI-install-dynamic: build-dynamic
mkdir -p $(DSTROOT)/usr/local/lib/system
if [ -f "$(SYMROOT)/libc.a" ]; then \
$(DSTROOT)/usr/local/lib/system; \
ranlib "$(DSTROOT)/usr/local/lib/system/libc.a"; \
fi
+ifneq ($(RC_ppc),)
+ if [ -f "$(OBJROOT)/obj.ppc/libc-ldbl128.a" ]; then \
+ echo "Installing libldbl128.a" ; \
+ $(SRCROOT)/make_libldbl128 "$(OBJROOT)/obj.ppc/libc-ldbl128.a" \
+ "" "$(DSTROOT)/usr/local/lib/system" $(LIBSYS) ; \
+ fi
+endif
# Don't use -j here; it may try to make links before the files are copied
install-man:
#
# Yes, we build everything with -g, and strip it out later...
#
+# -faltivec now disables inlining, so we can't use it globally. Fortunately,
+# only two files need altivec support, so we use file-specific CFLAGS to add
+# the option when needed.
+#
LIB=c
SHLIB_MAJOR= 1
SHLIB_MINOR= 0
-CC_3_3_OR_GREATER != ${.CURDIR}/cc-3.3-or-greater
-.if (${CC_3_3_OR_GREATER} != YES)
-CC = gcc-3.3
-.endif
.if (${MACHINE_ARCH} == unknown)
MACHINE_ARCH != /usr/bin/arch
.endif
-.if (${MACHINE_ARCH} == ppc) || (${MACHINE_ARCH} == ppc64)
-CFLAGS += -faltivec -DALTIVEC
+CC = gcc-3.5
+# always set __DARWIN_UNIX03 to zero (variant will set to one) except for ppc64
+.if (${MACHINE_ARCH} == ppc64)
+CFLAGS += -D__DARWIN_UNIX03=1
+.else
+CFLAGS += -D__DARWIN_UNIX03=0
.endif
-CFLAGS += -DNOID
+CFLAGS += -D__LIBC__ -DNOID -I${.CURDIR}/include
.ifdef ALTLIBCHEADERS
-CFLAGS += -I${ALTLIBCHEADERS}
-.else
-CFLAGS += -I${.CURDIR}/include
+INCLUDEDIR = ${ALTLIBCHEADERS}
+CFLAGS += -I${INCLUDEDIR}
.endif
.ifdef ALTFRAMEWORKSPATH
PRIVINC = -F${ALTFRAMEWORKSPATH} -I${ALTFRAMEWORKSPATH}/System.framework/PrivateHeaders
.endif
CFLAGS += ${PRIVINC}
CFLAGS += -DLIBC_MAJOR=${SHLIB_MAJOR} -no-cpp-precomp -force_cpusubtype_ALL
-CFLAGS += -arch ${MACHINE_ARCH} -fno-common -pipe -Wmost -g
-CFLAGS += -finline-limit=5000 -D__FBSDID=__RCSID -Wno-long-double
+CFLAGS += -fno-common -pipe -Wmost -g -D__FBSDID=__RCSID
+CFLAGS += -finline-limit=1500 --param inline-unit-growth=200 -Winline
AINC= -I${.CURDIR}/${MACHINE_ARCH} -no-cpp-precomp -force_cpusubtype_ALL
AINC+=-arch ${MACHINE_ARCH} -g
CLEANFILES+=tags
INSTALL_PIC_ARCHIVE= yes
PRECIOUSLIB= yes
+# workaround for 3649783
+AINC += -fdollars-in-identifiers
+
+# ppc64 optimizer still blows up on some files, so we use -O0 to turn it
+# off on a per file basis
+.if (${MACHINE_ARCH} == ppc64)
+OPTIMIZE-acl_entry.c = -O0
+# glob-fbsd.c fails with -static -Os (3869444) so turn off optimization
+OPTIMIZE-glob-fbsd.c = -O0
+.endif
+
# If these aren't set give it expected defaults
DSTROOT ?= /
OBJROOT ?= .
.include "${.CURDIR}/Makefile.inc"
.PATH: ${SYMROOT}
.include "Makefile.xbs"
+.if exists(/usr/share/mk/bsd.init.mk)
+.include <bsd.init.mk>
+.endif
.include <bsd.man.mk>
.include "${.CURDIR}/${MACHINE_ARCH}/Makefile.inc"
.endif
+.include "${.CURDIR}/darwin/Makefile.inc"
.include "${.CURDIR}/db/Makefile.inc"
.include "${.CURDIR}/compat-43/Makefile.inc"
.include "${.CURDIR}/emulated/Makefile.inc"
.include "${.CURDIR}/mach/Makefile.inc"
.include "${.CURDIR}/net/Makefile.inc"
.include "${.CURDIR}/nls/Makefile.inc"
-#.include "${.CURDIR}/posix1e/Makefile.inc"
+.include "${.CURDIR}/posix1e/Makefile.inc"
.include "${.CURDIR}/pthreads/Makefile.inc"
.if !defined(NO_QUAD)
#.include "${.CURDIR}/quad/Makefile.inc"
--- /dev/null
+# For the NetBSD auto patching mechanism and compatibility environment
+# setup, original NetBSD sources a put into a NetBSD subdirectory.
+# If a file with the same name, but suffix ".patch" is in that directory,
+# that patch will be applied before use.
+#
+# The NBSD* variables are set, and bracketed by .include of Makefile.nbsd_begin
+# and Makefile.nbsd_end
+#
+# Define (empty) variables so that make doesn't give substitution
+# errors if the included makefiles don't change these:
+
+NBSDMAN1=
+NBSDMAN2=
+NBSDMAN3=
+NBSDMAN4=
+NBSDMAN5=
+NBSDMAN6=
+NBSDMAN7=
+NBSDMAN8=
+NBSDMAN9=
+NBSDMDSRCS=
+NBSDMISRCS=
+NBSDHDRS=
+NBSDSRCS=
--- /dev/null
+# For the NetBSD auto patching mechanism and compatibility environment
+# setup, original NetBSD sources a put into a NetBSD subdirectory.
+# If a file with the same name, but suffix ".patch" is in that directory,
+# that patch will be applied before use.
+#
+# The NBSDMDSRCS, NBSDMISRCS, NBSDORIGHDRS and NBSDSRCS variables must be set,
+# and bracketed by .include of Makefile.nbsd_begin and Makefile.nbsd_end
+#
+# Set up dependencies between the NetBSD source (in a NetBSD subdirectory)
+# and a file with a -nbsd.x suffix (where x is 'c' or 's'). The suffix
+# rules will then compile the file with the simulate NetBSD environment.
+
+NBSDSECTIONS= 1 2 3 4 5 6 7 8 9
+
+.for _src in ${NBSDSRCS}
+${SYMROOT}/${_src:R}-nbsd.${_src:E}: NetBSD/${_src} _AUTOPATCHSYM
+SRCS+= ${_src}
+AUTOPATCHSRCS+= ${SYMROOT}/${_src:R}-nbsd.${_src:E}
+.endfor
+
+.for _src in ${NBSDMDSRCS}
+${SYMROOT}/${_src:R}-nbsd.${_src:E}: NetBSD/${_src} _AUTOPATCHSYM
+MDSRCS+= ${_src}
+AUTOPATCHSRCS+= ${SYMROOT}/${_src:R}-nbsd.${_src:E}
+.endfor
+
+.for _src in ${NBSDMISRCS}
+${SYMROOT}/${_src:R}-nbsd.${_src:E}: NetBSD/${_src} _AUTOPATCHSYM
+MISRCS+= ${_src}
+AUTOPATCHSRCS+= ${SYMROOT}/${_src:R}-nbsd.${_src:E}
+.endfor
+
+.for _src in ${NBSDHDRS}
+${SYMROOT}/${_src}: NetBSD/${_src} _AUTOPATCHSYM
+AUTOPATCHHDRS+= ${SYMROOT}/${_src}
+.endfor
+
+.for _sect in ${NBSDSECTIONS}
+.for _src in ${NBSDMAN${_sect}}
+${_src}: NetBSD/${_src} _AUTOPATCH
+MAN${_sect}+= ${_src}
+AUTOPATCHMAN+= ${_src}
+.endfor
+.endfor
--- /dev/null
+# For the OpenBSD auto patching mechanism and compatibility environment
+# setup, original OpenBSD sources a put into a OpenBSD subdirectory.
+# If a file with the same name, but suffix ".patch" is in that directory,
+# that patch will be applied before use.
+#
+# The OBSD* variables are set, and bracketed by .include of Makefile.obsd_begin
+# and Makefile.obsd_end
+#
+# Define (empty) variables so that make doesn't give substitution
+# errors if the included makefiles don't change these:
+
+OBSDMAN1=
+OBSDMAN2=
+OBSDMAN3=
+OBSDMAN4=
+OBSDMAN5=
+OBSDMAN6=
+OBSDMAN7=
+OBSDMAN8=
+OBSDMAN9=
+OBSDMDSRCS=
+OBSDMISRCS=
+OBSDHDRS=
+OBSDSRCS=
--- /dev/null
+# For the OpenBSD auto patching mechanism and compatibility environment
+# setup, original OpenBSD sources a put into a OpenBSD subdirectory.
+# If a file with the same name, but suffix ".patch" is in that directory,
+# that patch will be applied before use.
+#
+# The OBSDMDSRCS, OBSDMISRCS, OBSDORIGHDRS and OBSDSRCS variables must be set,
+# and bracketed by .include of Makefile.obsd_begin and Makefile.obsd_end
+#
+# Set up dependencies between the OpenBSD source (in a OpenBSD subdirectory)
+# and a file with a -obsd.x suffix (where x is 'c' or 's'). The suffix
+# rules will then compile the file with the simulate OpenBSD environment.
+
+OBSDSECTIONS= 1 2 3 4 5 6 7 8 9
+
+.for _src in ${OBSDSRCS}
+${SYMROOT}/${_src:R}-obsd.${_src:E}: OpenBSD/${_src} _AUTOPATCHSYM
+SRCS+= ${_src}
+AUTOPATCHSRCS+= ${SYMROOT}/${_src:R}-obsd.${_src:E}
+.endfor
+
+.for _src in ${OBSDMDSRCS}
+${SYMROOT}/${_src:R}-obsd.${_src:E}: OpenBSD/${_src} _AUTOPATCHSYM
+MDSRCS+= ${_src}
+AUTOPATCHSRCS+= ${SYMROOT}/${_src:R}-obsd.${_src:E}
+.endfor
+
+.for _src in ${OBSDMISRCS}
+${SYMROOT}/${_src:R}-obsd.${_src:E}: OpenBSD/${_src} _AUTOPATCHSYM
+MISRCS+= ${_src}
+AUTOPATCHSRCS+= ${SYMROOT}/${_src:R}-obsd.${_src:E}
+.endfor
+
+.for _src in ${OBSDHDRS}
+${SYMROOT}/${_src}: OpenBSD/${_src} _AUTOPATCHSYM
+AUTOPATCHHDRS+= ${SYMROOT}/${_src}
+.endfor
+
+.for _sect in ${OBSDSECTIONS}
+.for _src in ${OBSDMAN${_sect}}
+${_src}: OpenBSD/${_src} _AUTOPATCH
+MAN${_sect}+= ${_src}
+AUTOPATCHMAN+= ${_src}
+.endfor
+.endfor
install_libc_profile.a install_libc_debug.a autopatchman maninstall
.SUFFIXES:
-.SUFFIXES: .o .po .So .do .S .s .c .cc .cpp .cxx .m .C
-.SUFFIXES: -fbsd.c -uuid.c .3-uuid.in .3
+.SUFFIXES: .o .po .So .do
+.SUFFIXES: .S .s .c .cc .cpp .cxx .m .C
+.SUFFIXES: -fbsd.c -nbsd.c -obsd.c -uuid.c .3-uuid.in .3
.SUFFIXES: .f .y .l .defs .h
.SUFFIXES: User.c User.o User.po User.So User.do
.SUFFIXES: Server.c Server.o Server.po Server.So Server.do
OBJS+= ${SRCS:N*.h:R:S/$/.o/g}
+DOBJS+= ${OBJS:.o=.do}
POBJS+= ${OBJS:.o=.po} ${STATICOBJS:.o=.po}
SOBJS+= ${OBJS:.o=.So}
+#### 128-bit Long Double libc-ldbl128 for Panther ####################
+.if (${MACHINE_ARCH} == ppc)
+LIB128= ${LIB}-ldbl128
+LDBL_128_SRCS= _hdtoa.c _ldbl_util.c _ldtoa.c asprintf.c err.c fprintf.c \
+ fscanf.c fwprintf.c fwscanf.c gdtoa-strtopdd.c machdep_ldisdd.c \
+ printf.c scanf.c snprintf.c sprintf.c sscanf.c swprintf.c swscanf.c \
+ vasprintf.c vfprintf.c vfscanf.c vfwprintf.c vfwscanf.c vprintf.c \
+ vscanf.c vsnprintf.c vsprintf.c vsscanf.c vswprintf.c vswscanf.c \
+ vwprintf.c vwscanf.c wcstold.c wprintf.c wscanf.c \
+ oldldbl64.s oldsyslog.c LDBL/oldsyslog-LDBL.c \
+ LDBL/err-LDBL.c LDBL/vfprintf-LDBL.c LDBL/vfwprintf-LDBL.c
+LDBL_128_OBJS= ${LDBL_128_SRCS:R:S/$/.o/g}
+LDBL_128_DOBJS= ${LDBL_128_OBJS:.o=.do}
+LDBL_128_POBJS= ${LDBL_128_OBJS:.o=.po}
+LDBL_128_SOBJS= ${LDBL_128_OBJS:.o=.So}
+
+LDBLSRCS2+= oldsyslog.c
+SRCS2+= oldldbl64.s oldsyslog.c
+OBJS2+= ${SRCS2:N*.h:R:S/$/.o/g}
+DOBJS2+= ${OBJS2:.o=.do}
+POBJS2+= ${OBJS2:.o=.po}
+SOBJS2+= ${OBJS2:.o=.So}
+.endif
+
+#### Variant Rules ####################################################
+# The following magic is used for variants to avoid the exponental explosion
+# of suffix rules. To add a variant, select a name (typically all-caps).
+# Add that name to the VARIANTS variable. Create a CFLAGS_XXX variable
+# (XXX is the variant name) that contains the extra flags to pass to the
+# compiler (currently, no slashes are permitted in the flags). Then, just
+# define a XXXSRCS variable with the names of the files to recompile with the
+# additional flags. For auto-patched files, don't use the auto-patched file
+# name. Just use the original file name.
+#
+# Note that this magic also deals with combinations of variants; e.g.,
+# for two variants XXX and YYY, there are three variant combinations,
+# XXX, XXX-YYY and YYY. In this example, you can use XXX-YYYSRCS to
+# specify sources that will build with both the CFLAGS_XXX and CFLAGS_YYY
+# flags set. The variants are always in alphabetic order.
+#
+VARIANTS=
+# Append the 64-bit long double sources (ppc only)
+.if (${MACHINE_ARCH} == ppc)
+VARIANTS+= LDBL
+MDSRCS += ldbl64.s
+.endif
+# build UNIX03 variant except on ppc64
+.if (${MACHINE_ARCH} != ppc64)
+VARIANTS+= UNIX03
+.endif
+CFLAGS+= ${VARIANTCFLAGS}
+
+CFLAGS_UNIX03= -U__DARWIN_UNIX03 -D__DARWIN_UNIX03=1
+CFLAGS_LDBL= -mlong-double-64 -DLDBL_COMPAT
+
+.for _v in ${VARIANTS}
+COMBOARGS+= ${_v}/${CFLAGS_${_v}}
+.endfor
+.ifdef COMBOARGS
+# makeCombos is a perl script that creates all the variant combinations
+# and all the combinations of flags
+VARIANTCOMBOCFLAGS != ${.CURDIR}/makeCombos ${COMBOARGS}
+.endif
+# For each of the variant combinations as target (and possibly suffixed with
+# _D, _P, and _S for the four kinds on compile styles, we create a subdirectory
+# to do the compiling in, and then call bsdmake with the new directory, and
+# setting VARIANTCFLAGS, which are the extra flags to be added to CFLAGS.
+.for _v in ${VARIANTCOMBOCFLAGS}
+VARIANTCOMBOS+= ${_v:H:S,/,,}
+${_v:H:S,/,,}:
+.ifdef ${_v:H:S,/,,}SRCS
+ mkdir -p ${MAKEOBJDIR}/${_v:H:S,/,,}; \
+ MAKEOBJDIR="$(MAKEOBJDIR)/${_v:H:S,/,,}" VARIANTCFLAGS="-DBUILDING_VARIANT ${_v:T:S/@/ /g}" bsdmake -C "${.CURDIR}" build_${_v:H:S,/,,}
+.endif
+${_v:H:S,/,,}_D:
+.ifdef ${_v:H:S,/,,}SRCS
+ mkdir -p ${MAKEOBJDIR}/${_v:H:S,/,,}; \
+ MAKEOBJDIR="$(MAKEOBJDIR)/${_v:H:S,/,,}" VARIANTCFLAGS="-DBUILDING_VARIANT ${_v:T:S/@/ /g}" bsdmake -C "${.CURDIR}" build_${_v:H:S,/,,}_D
+.endif
+${_v:H:S,/,,}_P:
+.ifdef ${_v:H:S,/,,}SRCS
+ mkdir -p ${MAKEOBJDIR}/${_v:H:S,/,,}; \
+ MAKEOBJDIR="$(MAKEOBJDIR)/${_v:H:S,/,,}" VARIANTCFLAGS="-DBUILDING_VARIANT ${_v:T:S/@/ /g}" bsdmake -C "${.CURDIR}" build_${_v:H:S,/,,}_P
+.endif
+${_v:H:S,/,,}_S:
+.ifdef ${_v:H:S,/,,}SRCS
+ mkdir -p ${MAKEOBJDIR}/${_v:H:S,/,,}; \
+ MAKEOBJDIR="$(MAKEOBJDIR)/${_v:H:S,/,,}" VARIANTCFLAGS="-DBUILDING_VARIANT ${_v:T:S/@/ /g}" bsdmake -C "${.CURDIR}" build_${_v:H:S,/,,}_S
+.endif
+.endfor
+
+.for _v in ${VARIANTCOMBOS}
+# Variant suffix rules so the filenames are unique and Libsystem won't complain
+# because of ambiguities with -sectorder
+.SUFFIXES: -${_v}.o -${_v}.do -${_v}.po -${_v}.So
+.o-${_v}.o .do-${_v}.do .po-${_v}.po .So-${_v}.So:
+ mv ${.IMPSRC} ${.TARGET}
+
+# These are the build targets of the above bsdmake calls, which just builds
+# using the standard rules, but with the additional flags.
+VARIANTOBJS+= ${${_v}SRCS:N*.h:R:S/$/-${_v}.o/g:S,^,${_v}/,g}
+build_${_v}: ${${_v}SRCS:N*.h:R:S/$/-${_v}.o/g}
+build_${_v}_D: ${${_v}SRCS:N*.h:R:S/$/-${_v}.do/g} ${${_v}SRCS2:N*.h:R:S/$/-${_v}.do/g}
+build_${_v}_P: ${${_v}SRCS:N*.h:R:S/$/-${_v}.po/g} ${${_v}SRCS2:N*.h:R:S/$/-${_v}.po/g}
+build_${_v}_S: ${${_v}SRCS:N*.h:R:S/$/-${_v}.So/g} ${${_v}SRCS2:N*.h:R:S/$/-${_v}.So/g}
+.endfor
+# These variables, plus VARIANTOBJS above, are the extra binaries that get
+# added to the .a files. Note that these objects are in subdirectories
+# of the main build directory.
+VARIANTDOBJS+= ${VARIANTOBJS:.o=.do}
+VARIANTPOBJS+= ${VARIANTOBJS:.o=.po}
+VARIANTSOBJS+= ${VARIANTOBJS:.o=.So}
#### FreeBSD Rules ##################################################
FBSDFLAGS= -I${.CURDIR}/fbsdcompat -include _fbsd_compat_.h
-fbsd.c.o:
${CC} -static ${FBSDFLAGS} ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \
- -Os -c ${.IMPSRC} -o ${.TARGET}
+ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET}
-fbsd.c.po:
${CC} -pg -DPROFILE ${FBSDFLAGS} ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \
- -Os -c ${.IMPSRC} -o ${.TARGET}
+ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET}
-fbsd.c.So:
${CC} ${FBSDFLAGS} ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \
- -Os -c ${.IMPSRC} -o ${.TARGET}
+ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET}
-fbsd.c.do:
${CC} -g -DDEBUG ${FBSDFLAGS} ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \
-c ${.IMPSRC} -o ${.TARGET}
+#### NetBSD Rules ##################################################
+NBSDFLAGS= -I${.CURDIR}/nbsdcompat -include _nbsd_compat_.h
+
+-nbsd.c.o:
+ ${CC} -static ${NBSDFLAGS} ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \
+ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET}
+-nbsd.c.po:
+ ${CC} -pg -DPROFILE ${NBSDFLAGS} ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \
+ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET}
+-nbsd.c.So:
+ ${CC} ${NBSDFLAGS} ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \
+ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET}
+-nbsd.c.do:
+ ${CC} -g -DDEBUG ${NBSDFLAGS} ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \
+ -c ${.IMPSRC} -o ${.TARGET}
+
+#### OpenBSD Rules ##################################################
+OBSDFLAGS=
+
+-obsd.c.o:
+ ${CC} -static ${OBSDFLAGS} ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \
+ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET}
+-obsd.c.po:
+ ${CC} -pg -DPROFILE ${OBSDFLAGS} ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \
+ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET}
+-obsd.c.So:
+ ${CC} ${OBSDFLAGS} ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \
+ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET}
+-obsd.c.do:
+ ${CC} -g -DDEBUG ${OBSDFLAGS} ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \
+ -c ${.IMPSRC} -o ${.TARGET}
+
#### UUID Rules ######################################################
UUIDFLAGS= -I${.CURDIR}/uuid -include uuid-config.h
-uuid.c.o:
${CC} -static ${UUIDFLAGS} ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \
- -Os -c ${.IMPSRC} -o ${.TARGET}
+ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET}
-uuid.c.po:
${CC} -pg -DPROFILE ${UUIDFLAGS} ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \
- -Os -c ${.IMPSRC} -o ${.TARGET}
+ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET}
-uuid.c.So:
${CC} ${UUIDFLAGS} ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \
- -Os -c ${.IMPSRC} -o ${.TARGET}
+ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET}
-uuid.c.do:
${CC} -g -DDEBUG ${UUIDFLAGS} ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \
-c ${.IMPSRC} -o ${.TARGET}
#### Standard C Rules #################################################
.c.o User.cUser.o Server.cServer.o:
${CC} -static ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \
- -Os -c ${.IMPSRC} -o ${.TARGET}
+ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET}
.c.po User.cUser.po Server.cServer.po:
${CC} -pg -DPROFILE ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \
- -Os -c ${.IMPSRC} -o ${.TARGET}
+ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET}
.c.So User.cUser.So Server.cServer.So:
${CC} ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \
- -Os -c ${.IMPSRC} -o ${.TARGET}
+ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET}
.c.do User.cUser.do Server.cServer.do:
${CC} -g -DDEBUG ${CFLAGS} ${CFLAGS-${.IMPSRC:T}} \
-c ${.IMPSRC} -o ${.TARGET}
.s.o:
${CC} -static -x assembler-with-cpp ${CFLAGS:M-[BIDF]*} \
${CFLAGS-${.IMPSRC:T}:M-[BIDF]*} ${AINC} \
- -Os -c ${.IMPSRC} -o ${.TARGET}
+ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET}
.s.po:
${CC} -pg -DPROFILE -x assembler-with-cpp ${CFLAGS:M-[BIDF]*} \
${CFLAGS-${.IMPSRC:T}:M-[BIDF]*} ${AINC} \
- -Os -c ${.IMPSRC} -o ${.TARGET}
+ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET}
.s.So:
${CC} -x assembler-with-cpp ${CFLAGS:M-[BIDF]*} \
${CFLAGS-${.IMPSRC:T}:M-[BIDF]*} ${AINC} \
- -Os -c ${.IMPSRC} -o ${.TARGET}
+ -Os ${OPTIMIZE-${.IMPSRC:T}} -c ${.IMPSRC} -o ${.TARGET}
.s.do:
${CC} -g -DDEBUG -x assembler-with-cpp ${CFLAGS:M-[BIDF]*} \
${CFLAGS-${.IMPSRC:T}:M-[BIDF]*} ${AINC} \
#### mig Rules ########################################################
.defs.h .defsUser.c .defsServer.c:
- mig -arch ${MACHINE_ARCH} -user ${.PREFIX}User.c -server ${.PREFIX}Server.c -header ${.PREFIX}.h ${.IMPSRC}
+ mig -arch ${MACHINE_ARCH} -cc ${CC} -user ${.PREFIX}User.c -server ${.PREFIX}Server.c -header ${.PREFIX}.h ${.IMPSRC}
gen_mig_defs: ${SRVMIGHDRS} ${MIGHDRS}
gen_md_mig_defs: ${MD_MIGHDRS}
-lib${LIB}_static.a:: ${OBJS} ${STATICOBJS}
+#### Library Rules ####################################################
+lib${LIB}_static.a:: ${VARIANTCOMBOS} ${OBJS} ${STATICOBJS}
@${ECHO} building static ${LIB} library
@rm -f lib${LIB}_static.a
- @${AR} cq lib${LIB}_static.a `lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
+ @${AR} cq lib${LIB}_static.a `lorder ${OBJS} ${STATICOBJS} ${VARIANTOBJS} | tsort -q` ${ARADD}
${RANLIB} lib${LIB}_static.a
-lib${LIB}_profile.a:: ${POBJS}
+lib${LIB}_profile.a:: ${VARIANTCOMBOS:S/$/_P/g} ${POBJS} ${POBJS2}
@${ECHO} building profiled ${LIB} library
@rm -f lib${LIB}_profile.a
- @${AR} cq lib${LIB}_profile.a `lorder ${POBJS} | tsort -q` ${ARADD}
+ @${AR} cq lib${LIB}_profile.a `lorder ${POBJS} ${VARIANTPOBJS} | tsort -q` ${ARADD}
${RANLIB} lib${LIB}_profile.a
+.if (${MACHINE_ARCH} == ppc)
+ @${ECHO} building profiled ${LIB128} library
+ @rm -f lib${LIB128}_profile.a
+ @${AR} cq lib${LIB128}_profile.a ${LDBL_128_POBJS}
+.endif
-DOBJS+= ${OBJS:.o=.do}
-lib${LIB}_debug.a:: ${DOBJS}
+lib${LIB}_debug.a:: ${VARIANTCOMBOS:S/$/_D/g} ${DOBJS} ${DOBJS2}
@${ECHO} building debug ${LIB} library
@rm -f lib${LIB}_debug.a
- @${AR} cq lib${LIB}_debug.a `lorder ${DOBJS} | tsort -q` ${ARADD}
+ @${AR} cq lib${LIB}_debug.a `lorder ${DOBJS} ${VARIANTDOBJS} | tsort -q` ${ARADD}
${RANLIB} lib${LIB}_debug.a
+.if (${MACHINE_ARCH} == ppc)
+ @${ECHO} building debug ${LIB128} library
+ @rm -f lib${LIB128}_debug.a
+ @${AR} cq lib${LIB128}_debug.a ${LDBL_128_DOBJS}
+.endif
-lib${LIB}.a:: ${SOBJS}
+lib${LIB}.a:: ${VARIANTCOMBOS:S/$/_S/g} ${SOBJS} ${SOBJS2}
@${ECHO} building standard ${LIB} library
@rm -f lib${LIB}.a
- @${AR} cq lib${LIB}.a `lorder ${SOBJS} | tsort -q` ${ARADD}
+ @${AR} cq lib${LIB}.a `lorder ${SOBJS} ${VARIANTSOBJS} | tsort -q` ${ARADD}
${RANLIB} lib${LIB}.a
+.if (${MACHINE_ARCH} == ppc)
+ @${ECHO} building standard ${LIB128} library
+ @rm -f lib${LIB128}.a
+ @${AR} cq lib${LIB128}.a ${LDBL_128_SOBJS}
+.endif
CLEANFILES += ${DOBJS} libc_static.a libc_profile.a libc_debug.a
LOCINCDIR = ${DESTDIR}/usr/local/include
SYSTEMFRAMEWORK = ${DESTDIR}/System/Library/Frameworks/System.framework
PRIVHDRS = ${SYSTEMFRAMEWORK}/Versions/B/PrivateHeaders
+KERNELFRAMEWORK = ${DESTDIR}/System/Library/Frameworks/Kernel.framework
+PRIVKERNELHDRS = ${KERNELFRAMEWORK}/Versions/A/PrivateHeaders
installhdrs-md: gen_md_mig_defs
mkdir -p ${INCDIR}/mach/${MACHINE_ARCH}
mkdir -p ${INCDIR}/arpa
mkdir -p ${INCDIR}/libkern
mkdir -p ${INCDIR}/mach
+ mkdir -p ${INCDIR}/machine
mkdir -p ${INCDIR}/malloc
mkdir -p ${INCDIR}/objc
mkdir -p ${INCDIR}/protocols
mkdir -p ${INCDIR}/servers
mkdir -p ${INCDIR}/sys
+ mkdir -p ${INCDIR}/xlocale
${INSTALL} -c -m 444 ${INSTHDRS} ${INCDIR}
${INSTALL} -c -m 444 ${ARPA_INSTHDRS} ${INCDIR}/arpa
${INSTALL} -c -m 444 ${LIBKERN_INSTHDRS} ${INCDIR}/libkern
${INSTALL} -c -m 444 ${MACH_INSTHDRS} ${INCDIR}/mach
+ ${INSTALL} -c -m 444 ${MACHINE_INSTHDRS} ${INCDIR}/machine
${INSTALL} -c -m 444 ${MALLOC_INSTHDRS} ${INCDIR}/malloc
${INSTALL} -c -m 444 ${OBJC_INSTHDRS} ${INCDIR}/objc
${INSTALL} -c -m 444 ${PROTO_INSTHDRS} ${INCDIR}/protocols
${INSTALL} -c -m 444 ${SRVHDRS} ${INCDIR}/servers
${INSTALL} -c -m 444 ${SYS_INSTHDRS} ${INCDIR}/sys
+ ${INSTALL} -c -m 444 ${XLOCALE_INSTHDRS} ${INCDIR}/xlocale
mkdir -p ${LOCINCDIR}
${INSTALL} -c -m 444 ${LOCALHDRS} ${LOCINCDIR}
mkdir -p ${PRIVHDRS}/architecture/ppc
mkdir -p ${PRIVHDRS}/btree
mkdir -p ${PRIVHDRS}/machine
mkdir -p ${PRIVHDRS}/objc
+ mkdir -p ${PRIVHDRS}/uuid
mkdir -p ${PRIVHDRS}/sys
+ mkdir -p ${PRIVKERNELHDRS}/uuid
+ ${INSTALL} -c -m 444 ${PRIV_INSTHDRS} ${PRIVHDRS}
${INSTALL} -c -m 444 ${SRCROOT}/ppc/sys/processor_facilities.h ${PRIVHDRS}/architecture/ppc
${INSTALL} -c -m 444 ${SYMROOT}/btree.h ${PRIVHDRS}/btree
${INSTALL} -c -m 444 ${SYMROOT}/bt_extern.h ${PRIVHDRS}/btree
${INSTALL} -c -m 444 ${SRCROOT}/internat/NXCType.h ${PRIVHDRS}/objc
- ${INSTALL} -c -m 444 ${SRCROOT}/gen/stack_logging.h ${PRIVHDRS}
mv ${DESTDIR}/usr/include/asm.h ${PRIVHDRS}/machine
mv ${INCDIR}/servers/srvbootstrap.h ${INCDIR}/servers/bootstrap.h
@for i in `find ${DESTDIR}/usr/include/mach ${DESTDIR}/usr/include/servers -name \*.h`; do \
fi; \
done
${INSTALL} -c -m 444 ${SYS_INSTHDRS} ${PRIVHDRS}/sys
- mkdir -p ${INCDIR}/uuid
- ${INSTALL} -c -m 444 ${SYMROOT}/uuid.h ${INCDIR}/uuid
+ ${INSTALL} -c -m 444 ${PRIVUUID_INSTHDRS} ${PRIVHDRS}/uuid
+ ${INSTALL} -c -m 444 ${PRIVUUID_INSTHDRS} ${PRIVKERNELHDRS}/uuid
+ ${INSTALL} -c -m 444 ${INSTHDRS_AUTOPATCH:S,^,${SYMROOT}/,} ${INCDIR}
+.for _h in ${STRIP_HDRS}
+ chmod u+w ${INCDIR}/${_h}
+ ed - ${INCDIR}/${_h} < ${.CURDIR}/strip-header.ed
+ chmod u-w ${INCDIR}/${_h}
+.endfor
install_lib${LIB}_static.a:
${INSTALL} -c -m 444 lib${LIB}_static.a ${DESTDIR}/usr/local/lib/system/
+++ /dev/null
-#!/usr/bin/perl
-
-use strict;
-
-use constant VERSION3_3 => '3.3';
-
-sub toint {
- my $str = shift;
- my $vers = 0;
- my @pieces = split(/\./, $str);
- for(my $i = 0; $i < 3; $i++) {
- $vers = 1000 * $vers + $pieces[$i];
- }
- return($vers);
-}
-
-my $info = `cc -v 2>&1`;
-my($version) = $info =~ /gcc\s+version\s+(\S+)/;
-printf "%s\n", (toint($version) >= toint(VERSION3_3) ? 'YES' : 'NO');
.\" SUCH DAMAGE.
.\"
.\" @(#)gethostid.3 8.1 (Berkeley) 6/2/93
-.\" $FreeBSD: src/lib/libc/compat-43/gethostid.3,v 1.11 2002/12/18 12:45:08 ru Exp $
+.\" $FreeBSD: src/lib/libc/compat-43/gethostid.3,v 1.12 2004/07/02 23:52:09 ru Exp $
.\"
.Dd June 2, 1993
.Dt GETHOSTID 3
function
establishes a 32-bit identifier for the
current processor that is intended to be unique among all
-UNIX systems in existence. This is normally a DARPA Internet
-address for the local machine. This call is allowed only to the
+UNIX systems in existence.
+This is normally a DARPA Internet
+address for the local machine.
+This call is allowed only to the
super-user and is normally performed at boot time.
.Pp
The
--- /dev/null
+--- setpgrp.c.orig 2004-10-10 12:08:09.000000000 -0700
++++ setpgrp.c 2004-10-10 12:11:13.000000000 -0700
+@@ -40,8 +40,20 @@
+ #include <sys/types.h>
+ #include <unistd.h>
+
++#if __DARWIN_UNIX03
++pid_t
++setpgrp(void)
++{
++ pid_t pgid = getpgrp();
++ pid_t pid = getpid();
++ if (pgid != pid)
++ setpgid(pid, pid);
++ return pid;
++}
++#else /* !__DARWIN_UNIX03 */
+ int
+ setpgrp(pid_t pid, pid_t pgid)
+ {
+ return(setpgid(pid, pgid));
+ }
++#endif /* __DARWIN_UNIX03 */
setrgid.c setruid.c
.include "Makefile.fbsd_end"
+UNIX03SRCS += setpgrp.c
+
.if ${LIB} == "c"
MAN2+= sigblock.2 sigpause.2 sigsetmask.2 sigvec.2
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
{
sigset_t mask;
- if ((sig < 0) || (sig > NSIG))
- return(EINVAL);
+ if ((sig <= 0) || (sig >= NSIG)) {
+ errno = EINVAL;
+ return(-1);
+ }
sigemptyset(&mask);
sigaddset(&mask, sig);
return(sigprocmask(SIG_BLOCK, &mask,(sigset_t *)0));
{
sigset_t mask;
- if ((sig < 0) || (sig > NSIG))
- return(EINVAL);
+ if ((sig <= 0) || (sig >= NSIG)) {
+ errno = EINVAL;
+ return(-1);
+ }
sigemptyset(&mask);
sigaddset(&mask, sig);
return(sigprocmask(SIG_UNBLOCK, &mask,(sigset_t *)0));
return (signal(sig, SIG_IGN) == SIG_ERR ? -1 : 0);
}
+void (*sigset(int sig, void (*disp)(int)))(int) {
+ sigset_t omask;
+ int blocked;
+ struct sigaction oact;
+
+ if ((sig <= 0) || (sig >= NSIG)) {
+ errno = EINVAL;
+ return (SIG_ERR);
+ }
+ if (-1 == sigprocmask(0, NULL, &omask))
+ return (SIG_ERR);
+ blocked = sigismember(&omask, sig);
+ if (disp == SIG_HOLD) {
+ if (blocked)
+ return (SIG_HOLD);
+ if ((-1 == sigaction(sig, NULL, &oact)) ||
+ (-1 == sighold(sig)))
+ return (SIG_ERR);
+ return (sig_t)oact.sa_handler;
+ } else {
+ if (blocked) {
+ if (-1 == sigrelse(sig))
+ return (SIG_ERR);
+ }
+ sig_t rv = signal(sig, disp);
+ if (rv != SIG_ERR)
+ return blocked ? SIG_HOLD : rv;
+ else
+ return (rv);
+ }
+}
--- /dev/null
+.PATH: ${.CURDIR}/darwin
+
+MISRCS += copyfile.c
+LOCALHDRS += ${.CURDIR}/darwin/copyfile.h
+CFLAGS-copyfile.c = -I${.CURDIR}/darwin
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include <err.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/acl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+#include <syslog.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/errno.h>
+#include <sys/stat.h>
+#include <sys/xattr.h>
+#include <sys/syscall.h>
+#include <sys/param.h>
+#include <sys/acl.h>
+#include <libkern/OSByteOrder.h>
+#include <membership.h>
+
+#include <copyfile.h>
+
+struct _copyfile_state
+{
+ char *src;
+ char *dst;
+ int src_fd;
+ int dst_fd;
+ struct stat sb;
+ filesec_t fsec;
+ copyfile_flags_t flags;
+ void *stats;
+ uint32_t debug;
+};
+
+static int copyfile_open (copyfile_state_t);
+static int copyfile_close (copyfile_state_t);
+static int copyfile_data (copyfile_state_t);
+static int copyfile_stat (copyfile_state_t);
+static int copyfile_security (copyfile_state_t);
+static int copyfile_xattr (copyfile_state_t);
+static int copyfile_pack (copyfile_state_t);
+static int copyfile_unpack (copyfile_state_t);
+
+static copyfile_flags_t copyfile_check (copyfile_state_t);
+static int copyfile_fix_perms(copyfile_state_t, filesec_t *, int);
+
+#define COPYFILE_DEBUG (1<<31)
+
+#ifndef _COPYFILE_TEST
+# define copyfile_warn(str, ...) syslog(LOG_WARNING, str ": %m", ## __VA_ARGS__)
+# define copyfile_debug(d, str, ...) \
+ if (s && (d <= s->debug)) {\
+ syslog(LOG_DEBUG, "%s:%d:%s() " str "\n", __FILE__, __LINE__ , __FUNCTION__, ## __VA_ARGS__); \
+ } else
+#else
+#define copyfile_warn(str, ...) \
+ fprintf(stderr, "%s:%d:%s() " str ": %s\n", __FILE__, __LINE__ , __FUNCTION__, ## __VA_ARGS__, (errno) ? strerror(errno) : "")
+# define copyfile_debug(d, str, ...) \
+ if (s && (d <= s->debug)) {\
+ fprintf(stderr, "%s:%d:%s() " str "\n", __FILE__, __LINE__ , __FUNCTION__, ## __VA_ARGS__); \
+ } else
+#endif
+
+int copyfile(const char *src, const char *dst, copyfile_state_t state, copyfile_flags_t flags)
+{
+ int ret = 0;
+ copyfile_state_t s = state;
+ filesec_t original_fsec;
+ int fix_perms = 0;
+
+ original_fsec = filesec_init();
+ if (s == NULL && (s = copyfile_init()) == NULL)
+ return -1;
+
+ if (src != NULL)
+ {
+ if (s->src_fd != -2 && s->src && !strncmp(src, s->src, MAXPATHLEN))
+ close(s->src_fd);
+ s->src = strdup(src);
+ }
+
+ if (dst != NULL)
+ {
+ if (s->dst_fd != -2 && s->dst && !strncmp(dst, s->dst, MAXPATHLEN))
+ close(s->dst_fd);
+ s->dst = strdup(dst);
+ }
+
+ s->flags = flags;
+
+ if (COPYFILE_DEBUG & s->flags)
+ {
+ char *e;
+ if ((e = getenv("COPYFILE_DEBUG")))
+ {
+ s->debug = strtol(e, NULL, 0);
+ if (s->debug < 1)
+ s->debug = 1;
+ }
+ copyfile_debug(1, "debug value set to: %d\n", s->debug);
+ }
+
+ if (COPYFILE_CHECK & flags)
+ return copyfile_check(s);
+
+ if (copyfile_open(s) < 0)
+ ret = -1;
+ else
+ {
+ if (s->dst_fd == -2 || s->src_fd == -2)
+ return 0;
+
+ if (COPYFILE_PACK & flags)
+ {
+ if (copyfile_pack(s) < 0)
+ {
+ unlink(s->dst);
+ ret = -1;
+ }
+ } else if (COPYFILE_UNPACK & flags)
+ {
+ if (copyfile_unpack(s) < 0)
+ ret = -1;
+ } else
+ {
+ if (COPYFILE_SECURITY & flags)
+ {
+ if (copyfile_security(s) < 0)
+ {
+ copyfile_warn("error processing security information");
+ ret -= 1;
+ }
+ } else if (COPYFILE_UNPACK & flags)
+ {
+ fix_perms = !copyfile_fix_perms(s, &original_fsec, 1);
+ if (copyfile_unpack(s) < 0)
+ ret = -1;
+ } else
+ {
+ if (COPYFILE_SECURITY & flags)
+ {
+ copyfile_warn("error processing stat information");
+ ret -= 1;
+ }
+ }
+ fix_perms = !copyfile_fix_perms(s, &original_fsec, 1);
+
+ if (COPYFILE_XATTR & flags)
+ {
+ if (copyfile_xattr(s) < 0)
+ {
+ copyfile_warn("error processing extended attributes");
+ ret -= 1;
+ }
+ }
+ if (COPYFILE_DATA & flags)
+ {
+ if (copyfile_data(s) < 0)
+ {
+ copyfile_warn("error processing data");
+ ret = -1;
+ if (s->dst && unlink(s->dst))
+ copyfile_warn("%s: remove", s->src);
+ goto exit;
+ }
+ }
+ }
+ }
+exit:
+ if (fix_perms)
+ copyfile_fix_perms(s, &original_fsec, 0);
+
+ filesec_free(original_fsec);
+
+ if (state == NULL)
+ ret -= copyfile_free(s);
+ return ret;
+}
+
+copyfile_state_t copyfile_init(void)
+{
+ copyfile_state_t s = (copyfile_state_t) calloc(1, sizeof(struct _copyfile_state));
+
+ if (s != NULL)
+ {
+ s->src_fd = -2;
+ s->dst_fd = -2;
+ s->fsec = filesec_init();
+ }
+
+ return s;
+}
+
+int copyfile_free(copyfile_state_t s)
+{
+ if (s != NULL)
+ {
+ if (s->fsec)
+ filesec_free(s->fsec);
+
+ if (s->dst)
+ free(s->dst);
+ if (s->src)
+ free(s->src);
+ if (copyfile_close(s) < 0)
+ {
+ copyfile_warn("error closing files");
+ return -1;
+ }
+ free(s);
+ }
+ return 0;
+}
+
+static int copyfile_close(copyfile_state_t s)
+{
+ if (s->src_fd != -2)
+ close(s->src_fd);
+
+ if (s->dst_fd != -2 && close(s->dst_fd))
+ {
+ copyfile_warn("close on %s", s->dst);
+ return -1;
+ }
+ return 0;
+}
+
+static int copyfile_fix_perms(copyfile_state_t s, filesec_t *fsec, int on)
+{
+ filesec_t tmp_fsec;
+ struct stat sb;
+ mode_t mode;
+ acl_t acl;
+
+ if (on)
+ {
+ if(statx_np(s->dst, &sb, *fsec))
+ goto error;
+
+ tmp_fsec = filesec_dup(*fsec);
+
+ if (!filesec_get_property(tmp_fsec, FILESEC_ACL, &acl))
+ {
+ acl_entry_t entry;
+ acl_permset_t permset;
+ uuid_t qual;
+
+ if (mbr_uid_to_uuid(getuid(), qual) != 0)
+ goto error;
+
+ if (acl_create_entry_np(&acl, &entry, ACL_FIRST_ENTRY) == -1)
+ goto error;
+ if (acl_get_permset(entry, &permset) == -1)
+ goto error;
+ if (acl_clear_perms(permset) == -1)
+ goto error;
+ if (acl_add_perm(permset, ACL_WRITE_DATA) == -1)
+ goto error;
+ if (acl_add_perm(permset, ACL_WRITE_ATTRIBUTES) == -1)
+ goto error;
+ if (acl_add_perm(permset, ACL_WRITE_EXTATTRIBUTES) == -1)
+ goto error;
+ if (acl_set_tag_type(entry, ACL_EXTENDED_ALLOW) == -1)
+ goto error;
+
+ if(acl_set_permset(entry, permset) == -1)
+ goto error;
+ if(acl_set_qualifier(entry, qual) == -1)
+ goto error;
+
+ if (filesec_set_property(tmp_fsec, FILESEC_ACL, &acl) != 0)
+ goto error;
+ }
+
+ if (filesec_get_property(tmp_fsec, FILESEC_MODE, &mode) == 0)
+ {
+ if (~mode & S_IWUSR)
+ {
+ mode |= S_IWUSR;
+ if (filesec_set_property(tmp_fsec, FILESEC_MODE, &mode) != 0)
+ goto error;
+ }
+ }
+ if (fchmodx_np(s->dst_fd, tmp_fsec) < 0 && errno != ENOTSUP)
+ copyfile_warn("setting security information");
+ filesec_free(tmp_fsec);
+ } else
+ if (fchmodx_np(s->dst_fd, *fsec) < 0 && errno != ENOTSUP)
+ copyfile_warn("setting security information");
+
+ return 0;
+error:
+ filesec_free(*fsec);
+ return -1;
+}
+
+
+static int copyfile_open(copyfile_state_t s)
+{
+ int oflags = O_EXCL | O_CREAT;
+
+ if (s->src && s->src_fd == -2)
+ {
+ if ((COPYFILE_NOFOLLOW_SRC & s->flags ? lstatx_np : statx_np)
+ (s->src, &s->sb, s->fsec))
+ {
+ copyfile_warn("stat on %s", s->src);
+ return -1;
+ }
+ if ((s->src_fd = open(s->src, O_RDONLY, 0)) < 0)
+ {
+ copyfile_warn("open on %s", s->src);
+ return -1;
+ }
+ }
+
+ if (s->dst && s->dst_fd == -2)
+ {
+ if (COPYFILE_DATA & s->flags || COPYFILE_PACK & s->flags)
+ oflags |= O_WRONLY;
+
+ if (COPYFILE_ACL & ~s->flags)
+ {
+ if (filesec_set_property(s->fsec, FILESEC_ACL, NULL) == -1)
+ {
+ copyfile_debug(1, "unsetting acl attribute on %s", s->dst);
+ }
+ }
+ if (COPYFILE_STAT & ~s->flags)
+ {
+ if (filesec_set_property(s->fsec, FILESEC_MODE, NULL) == -1)
+ {
+ copyfile_debug(1, "unsetting mode attribute on %s", s->dst);
+ }
+ }
+ if (COPYFILE_PACK & s->flags)
+ {
+ mode_t m = S_IRUSR;
+ if (filesec_set_property(s->fsec, FILESEC_MODE, &m) == -1)
+ {
+ mode_t m = S_IRUSR | S_IWUSR;
+ if (filesec_set_property(s->fsec, FILESEC_MODE, &m) == -1)
+ {
+ copyfile_debug(1, "setting mode attribute on %s", s->dst);
+ }
+ }
+ if (filesec_set_property(s->fsec, FILESEC_OWNER, NULL) == -1)
+ {
+ copyfile_debug(1, "unsetting uid attribute on %s", s->dst);
+ }
+ if (filesec_set_property(s->fsec, FILESEC_UUID, NULL) == -1)
+ {
+ copyfile_debug(1, "unsetting uuid attribute on %s", s->dst);
+ }
+ if (filesec_set_property(s->fsec, FILESEC_GROUP, NULL) == -1)
+ {
+ copyfile_debug(1, "unsetting gid attribute on %s", s->dst);
+ }
+ }
+
+ if (COPYFILE_UNLINK & s->flags && unlink(s->dst) < 0)
+ {
+ copyfile_warn("%s: remove", s->dst);
+ return -1;
+ }
+
+ while((s->dst_fd = openx_np(s->dst, oflags, s->fsec)) < 0)
+ {
+ if (EEXIST == errno)
+ {
+ oflags = oflags & ~O_CREAT;
+ continue;
+ }
+ copyfile_warn("open on %s", s->dst);
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static copyfile_flags_t copyfile_check(copyfile_state_t s)
+{
+ acl_t acl;
+ copyfile_flags_t ret = 0;
+
+ if (!s->src)
+ return ret;
+
+ // check EAs
+ if (COPYFILE_XATTR & s->flags)
+ if (listxattr(s->src, 0, 0, 0) > 0)
+ ret |= COPYFILE_XATTR;
+
+ if (COPYFILE_ACL & s->flags)
+ {
+ (COPYFILE_NOFOLLOW_SRC & s->flags ? lstatx_np : statx_np)
+ (s->src, &s->sb, s->fsec);
+
+ if (filesec_get_property(s->fsec, FILESEC_ACL, &acl) == 0)
+ ret |= COPYFILE_ACL;
+ }
+
+ return ret;
+}
+
+static int copyfile_data(copyfile_state_t s)
+{
+ unsigned int blen;
+ char *bp;
+ int nread;
+ int ret;
+
+ if ((bp = malloc((size_t)s->sb.st_blksize)) == NULL)
+ {
+ blen = 0;
+ warnx("malloc failed");
+ return -1;
+ }
+ blen = s->sb.st_blksize;
+
+ while ((nread = read(s->src_fd, bp, (size_t)blen)) > 0)
+ {
+ if (write(s->dst_fd, bp, (size_t)nread) != nread)
+ {
+ copyfile_warn("writing to %s", s->dst);
+ return -1;
+ }
+ }
+ if (nread < 0)
+ {
+ copyfile_warn("reading from %s", s->src);
+ ret = -1;
+ }
+
+ free(bp);
+
+ if (ftruncate(s->dst_fd, s->sb.st_size) < 0)
+ ret = -1;
+
+ return ret;
+}
+
+static int copyfile_security(copyfile_state_t s)
+{
+ filesec_t fsec_dst = filesec_init();
+
+ int copied = 0;
+ acl_flagset_t flags;
+ struct stat sb;
+ acl_entry_t entry_src = NULL, entry_dst = NULL;
+ acl_t acl_src, acl_dst;
+ int inited_dst = 0, inited_src = 0, ret = 0;
+
+ if (COPYFILE_ACL & s->flags)
+ {
+ if(fstatx_np(s->dst_fd, &sb, fsec_dst))
+ {
+ goto cleanup;
+ }
+
+ if (filesec_get_property(fsec_dst, FILESEC_ACL, &acl_dst))
+ {
+ if (errno == ENOENT)
+ {
+ acl_dst = acl_init(4);
+ inited_dst = 1;
+ }
+ else
+ {
+ ret = -1;
+ goto cleanup;
+ }
+ }
+
+ if (filesec_get_property(s->fsec, FILESEC_ACL, &acl_src))
+ {
+ if (errno == ENOENT)
+ {
+ if (inited_dst)
+ goto no_acl;
+ acl_dst = acl_init(4);
+ inited_src = 1;
+ }
+ else
+ {
+ ret = -1;
+ goto cleanup;
+ }
+ }
+
+ for (;acl_get_entry(acl_src,
+ entry_src == NULL ? ACL_FIRST_ENTRY : ACL_NEXT_ENTRY,
+ &entry_src) == 0;)
+ {
+ acl_get_flagset_np(entry_src, &flags);
+ if (!acl_get_flag_np(flags, ACL_ENTRY_INHERITED))
+ {
+ if ((ret = acl_create_entry(&acl_dst, &entry_dst)) == -1)
+ goto cleanup;
+
+ if ((ret = acl_copy_entry(entry_dst, entry_src)) == -1)
+ goto cleanup;
+
+ copyfile_debug(1, "copied acl entry from %s to %s", s->src, s->dst);
+ copied++;
+ }
+ }
+
+ if (!filesec_set_property(s->fsec, FILESEC_ACL, &acl_dst))
+ {
+ copyfile_debug(1, "altered acl");
+ }
+ }
+no_acl:
+ if (fchmodx_np(s->dst_fd, s->fsec) < 0 && errno != ENOTSUP)
+ copyfile_warn("setting security information: %s", s->dst);
+
+cleanup:
+ filesec_free(fsec_dst);
+ if (inited_src) acl_free(acl_src);
+ if (inited_dst) acl_free(acl_dst);
+
+ return ret;
+}
+
+static int copyfile_stat(copyfile_state_t s)
+{
+ struct timeval tval[2];
+ /*
+ * NFS doesn't support chflags; ignore errors unless there's reason
+ * to believe we're losing bits. (Note, this still won't be right
+ * if the server supports flags and we were trying to *remove* flags
+ * on a file that we copied, i.e., that we didn't create.)
+ */
+ if (chflags(s->dst, (u_long)s->sb.st_flags))
+ if (errno != EOPNOTSUPP || s->sb.st_flags != 0)
+ copyfile_warn("%s: set flags (was: 0%07o)", s->dst, s->sb.st_flags);
+
+ tval[0].tv_sec = s->sb.st_atime;
+ tval[1].tv_sec = s->sb.st_mtime;
+ tval[0].tv_usec = tval[1].tv_usec = 0;
+ if (utimes(s->dst, tval))
+ copyfile_warn("%s: set times", s->dst);
+ return 0;
+}
+
+static int copyfile_xattr(copyfile_state_t s)
+{
+ char *name;
+ char *namebuf;
+ size_t xa_size;
+ void *xa_dataptr;
+ size_t bufsize = 4096;
+ ssize_t asize;
+ ssize_t nsize;
+ int ret = 0;
+ int flags = 0;
+
+ if (COPYFILE_NOFOLLOW_SRC & s->flags)
+ flags |= XATTR_NOFOLLOW;
+
+ /* delete EAs on destination */
+ if ((nsize = flistxattr(s->dst_fd, 0, 0, 0)) > 0)
+ {
+ if ((namebuf = (char *) malloc(nsize)) == NULL)
+ return -1;
+ else
+ nsize = flistxattr(s->dst_fd, namebuf, nsize, 0);
+
+ if (nsize > 0)
+ for (name = namebuf; name < namebuf + nsize; name += strlen(name) + 1)
+ fremovexattr(s->dst_fd, name,flags);
+
+ free(namebuf);
+ } else if (nsize < 0)
+ {
+ if (errno == ENOTSUP)
+ return 0;
+ else
+ return -1;
+ }
+
+ /* get name list of EAs on source */
+ if ((nsize = flistxattr(s->src_fd, 0, 0, 0)) < 0)
+ {
+ if (errno == ENOTSUP)
+ return 0;
+ else
+ return -1;
+ } else if (nsize == 0)
+ return 0;
+
+ if ((namebuf = (char *) malloc(nsize)) == NULL)
+ return -1;
+ else
+ nsize = flistxattr(s->src_fd, namebuf, nsize, 0);
+
+ if (nsize <= 0)
+ return nsize;
+
+ if ((xa_dataptr = (void *) malloc(bufsize)) == NULL)
+ return -1;
+
+ for (name = namebuf; name < namebuf + nsize; name += strlen(name) + 1)
+ {
+ if ((xa_size = fgetxattr(s->src_fd, name, 0, 0, 0, flags)) < 0)
+ {
+ ret = -1;
+ continue;
+ }
+
+ if (xa_size > bufsize)
+ {
+ bufsize = xa_size;
+ if ((xa_dataptr =
+ (void *) realloc((void *) xa_dataptr, bufsize)) == NULL)
+ {
+ ret = -1;
+ continue;
+ }
+ }
+
+ if ((asize = fgetxattr(s->src_fd, name, xa_dataptr, xa_size, 0, flags)) < 0)
+ {
+ ret = -1;
+ continue;
+ }
+
+ if (xa_size != asize)
+ xa_size = asize;
+
+ if (fsetxattr(s->dst_fd, name, xa_dataptr, xa_size, 0, flags) < 0)
+ {
+ ret = -1;
+ continue;
+ }
+ }
+ free((void *) xa_dataptr);
+ return ret;
+}
+
+
+#ifdef _COPYFILE_TEST
+#define COPYFILE_OPTION(x) { #x, COPYFILE_ ## x },
+
+struct {char *s; int v;} opts[] = {
+ COPYFILE_OPTION(ACL)
+ COPYFILE_OPTION(STAT)
+ COPYFILE_OPTION(XATTR)
+ COPYFILE_OPTION(DATA)
+ COPYFILE_OPTION(SECURITY)
+ COPYFILE_OPTION(METADATA)
+ COPYFILE_OPTION(ALL)
+ COPYFILE_OPTION(NOFOLLOW_SRC)
+ COPYFILE_OPTION(NOFOLLOW_DST)
+ COPYFILE_OPTION(NOFOLLOW)
+ COPYFILE_OPTION(EXCL)
+ COPYFILE_OPTION(MOVE)
+ COPYFILE_OPTION(UNLINK)
+ COPYFILE_OPTION(PACK)
+ COPYFILE_OPTION(UNPACK)
+ COPYFILE_OPTION(CHECK)
+ COPYFILE_OPTION(VERBOSE)
+ COPYFILE_OPTION(DEBUG)
+ {NULL, 0}
+};
+
+int main(int c, char *v[])
+{
+ int i;
+ int flags = 0;
+
+ if (c < 3)
+ errx(1, "insufficient arguments");
+
+ while(c-- > 3)
+ {
+ for (i = 0; opts[i].s != NULL; ++i)
+ {
+ if (strcasecmp(opts[i].s, v[c]) == 0)
+ {
+ printf("option %d: %s <- %d\n", c, opts[i].s, opts[i].v);
+ flags |= opts[i].v;
+ break;
+ }
+ }
+ }
+
+ return copyfile(v[1], v[2], NULL, flags);
+}
+#endif
+/*
+ * Apple Double Create
+ *
+ * Create an Apple Double "._" file from a file's extented attributes
+ *
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ */
+
+
+#define offsetof(type, member) ((size_t)(&((type *)0)->member))
+
+#define XATTR_MAXATTRLEN (4*1024)
+
+
+/*
+ Typical "._" AppleDouble Header File layout:
+ ------------------------------------------------------------
+ MAGIC 0x00051607
+ VERSION 0x00020000
+ FILLER 0
+ COUNT 2
+ .-- AD ENTRY[0] Finder Info Entry (must be first)
+ .--+-- AD ENTRY[1] Resource Fork Entry (must be last)
+ | '-> FINDER INFO
+ | ///////////// Fixed Size Data (32 bytes)
+ | EXT ATTR HDR
+ | /////////////
+ | ATTR ENTRY[0] --.
+ | ATTR ENTRY[1] --+--.
+ | ATTR ENTRY[2] --+--+--.
+ | ... | | |
+ | ATTR ENTRY[N] --+--+--+--.
+ | ATTR DATA 0 <-' | | |
+ | //////////// | | |
+ | ATTR DATA 1 <----' | |
+ | ///////////// | |
+ | ATTR DATA 2 <-------' |
+ | ///////////// |
+ | ... |
+ | ATTR DATA N <----------'
+ | /////////////
+ | Attribute Free Space
+ |
+ '----> RESOURCE FORK
+ ///////////// Variable Sized Data
+ /////////////
+ /////////////
+ /////////////
+ /////////////
+ /////////////
+ ...
+ /////////////
+
+ ------------------------------------------------------------
+
+ NOTE: The EXT ATTR HDR, ATTR ENTRY's and ATTR DATA's are
+ stored as part of the Finder Info. The length in the Finder
+ Info AppleDouble entry includes the length of the extended
+ attribute header, attribute entries, and attribute data.
+*/
+
+
+/*
+ * On Disk Data Structures
+ *
+ * Note: Motorola 68K alignment and big-endian.
+ *
+ * See RFC 1740 for additional information about the AppleDouble file format.
+ *
+ */
+
+#define ADH_MAGIC 0x00051607
+#define ADH_VERSION 0x00020000
+#define ADH_MACOSX "Mac OS X "
+
+/*
+ * AppleDouble Entry ID's
+ */
+#define AD_DATA 1 /* Data fork */
+#define AD_RESOURCE 2 /* Resource fork */
+#define AD_REALNAME 3 /* FileÕs name on home file system */
+#define AD_COMMENT 4 /* Standard Mac comment */
+#define AD_ICONBW 5 /* Mac black & white icon */
+#define AD_ICONCOLOR 6 /* Mac color icon */
+#define AD_UNUSED 7 /* Not used */
+#define AD_FILEDATES 8 /* File dates; create, modify, etc */
+#define AD_FINDERINFO 9 /* Mac Finder info & extended info */
+#define AD_MACINFO 10 /* Mac file info, attributes, etc */
+#define AD_PRODOSINFO 11 /* Pro-DOS file info, attrib., etc */
+#define AD_MSDOSINFO 12 /* MS-DOS file info, attributes, etc */
+#define AD_AFPNAME 13 /* Short name on AFP server */
+#define AD_AFPINFO 14 /* AFP file info, attrib., etc */
+#define AD_AFPDIRID 15 /* AFP directory ID */
+#define AD_ATTRIBUTES AD_FINDERINFO
+
+
+#define ATTR_FILE_PREFIX "._"
+#define ATTR_HDR_MAGIC 0x41545452 /* 'ATTR' */
+
+#define ATTR_BUF_SIZE 4096 /* default size of the attr file and how much we'll grow by */
+
+/* Implementation Limits */
+#define ATTR_MAX_SIZE (128*1024) /* 128K maximum attribute data size */
+#define ATTR_MAX_NAME_LEN 128
+#define ATTR_MAX_HDR_SIZE (65536+18)
+
+/*
+ * Note: ATTR_MAX_HDR_SIZE is the largest attribute header
+ * size supported (including the attribute entries). All of
+ * the attribute entries must reside within this limit.
+ */
+
+
+#pragma options align=mac68k
+
+#define FINDERINFOSIZE 32
+
+typedef struct apple_double_entry
+{
+ u_int32_t type; /* entry type: see list, 0 invalid */
+ u_int32_t offset; /* entry data offset from the beginning of the file. */
+ u_int32_t length; /* entry data length in bytes. */
+} apple_double_entry_t;
+
+
+typedef struct apple_double_header
+{
+ u_int32_t magic; /* == ADH_MAGIC */
+ u_int32_t version; /* format version: 2 = 0x00020000 */
+ u_int32_t filler[4];
+ u_int16_t numEntries; /* number of entries which follow */
+ apple_double_entry_t entries[2]; /* 'finfo' & 'rsrc' always exist */
+ u_int8_t finfo[FINDERINFOSIZE]; /* Must start with Finder Info (32 bytes) */
+ u_int8_t pad[2]; /* get better alignment inside attr_header */
+} apple_double_header_t;
+
+
+/* Entries are aligned on 4 byte boundaries */
+typedef struct attr_entry
+{
+ u_int32_t offset; /* file offset to data */
+ u_int32_t length; /* size of attribute data */
+ u_int16_t flags;
+ u_int8_t namelen; /* length of name including NULL termination char */
+ u_int8_t name[1]; /* NULL-terminated UTF-8 name (up to 128 bytes max) */
+} attr_entry_t;
+
+
+/* Header + entries must fit into 64K */
+typedef struct attr_header
+{
+ apple_double_header_t appledouble;
+ u_int32_t magic; /* == ATTR_HDR_MAGIC */
+ u_int32_t debug_tag; /* for debugging == file id of owning file */
+ u_int32_t total_size; /* total size of attribute header + entries + data */
+ u_int32_t data_start; /* file offset to attribute data area */
+ u_int32_t data_length; /* length of attribute data area */
+ u_int32_t reserved[3];
+ u_int16_t flags;
+ u_int16_t num_attrs;
+} attr_header_t;
+
+
+#pragma options align=reset
+
+#define SWAP16(x) OSSwapBigToHostInt16(x)
+#define SWAP32(x) OSSwapBigToHostInt32(x)
+#define SWAP64(x) OSSwapBigToHostInt64(x)
+
+#define ATTR_ALIGN 3L /* Use four-byte alignment */
+
+#define ATTR_ENTRY_LENGTH(namelen) \
+ ((sizeof(attr_entry_t) - 1 + (namelen) + ATTR_ALIGN) & (~ATTR_ALIGN))
+
+#define ATTR_NEXT(ae) \
+ (attr_entry_t *)((u_int8_t *)(ae) + ATTR_ENTRY_LENGTH((ae)->namelen))
+
+#define XATTR_SECURITY_NAME "com.apple.acl.text"
+
+/*
+ * Endian swap Apple Double header
+ */
+static void
+swap_adhdr(apple_double_header_t *adh)
+{
+#if BYTE_ORDER == LITTLE_ENDIAN
+ int count;
+ int i;
+
+ count = (adh->magic == ADH_MAGIC) ? adh->numEntries : SWAP16(adh->numEntries);
+
+ adh->magic = SWAP32 (adh->magic);
+ adh->version = SWAP32 (adh->version);
+ adh->numEntries = SWAP16 (adh->numEntries);
+
+ for (i = 0; i < count; i++)
+ {
+ adh->entries[i].type = SWAP32 (adh->entries[i].type);
+ adh->entries[i].offset = SWAP32 (adh->entries[i].offset);
+ adh->entries[i].length = SWAP32 (adh->entries[i].length);
+ }
+#endif
+}
+
+/*
+ * Endian swap extended attributes header
+ */
+static void
+swap_attrhdr(attr_header_t *ah)
+{
+#if BYTE_ORDER == LITTLE_ENDIAN
+ attr_entry_t *ae;
+ int count;
+ int i;
+
+ count = (ah->magic == ATTR_HDR_MAGIC) ? ah->num_attrs : SWAP16(ah->num_attrs);
+
+ ah->magic = SWAP32 (ah->magic);
+ ah->debug_tag = SWAP32 (ah->debug_tag);
+ ah->total_size = SWAP32 (ah->total_size);
+ ah->data_start = SWAP32 (ah->data_start);
+ ah->data_length = SWAP32 (ah->data_length);
+ ah->flags = SWAP16 (ah->flags);
+ ah->num_attrs = SWAP16 (ah->num_attrs);
+
+ ae = (attr_entry_t *)(&ah[1]);
+ for (i = 0; i < count; i++, ae++)
+ {
+ ae->offset = SWAP32 (ae->offset);
+ ae->length = SWAP32 (ae->length);
+ ae->flags = SWAP16 (ae->flags);
+ }
+#endif
+}
+
+static u_int32_t emptyfinfo[8] = {0};
+
+static int copyfile_unpack(copyfile_state_t s)
+{
+ int bytes;
+ void * buffer;
+ apple_double_header_t *adhdr;
+ size_t hdrsize;
+ int error = 0;
+
+ if (s->sb.st_size < ATTR_MAX_HDR_SIZE)
+ hdrsize = s->sb.st_size;
+ else
+ hdrsize = ATTR_MAX_HDR_SIZE;
+
+ buffer = calloc(1, hdrsize);
+ bytes = pread(s->src_fd, buffer, hdrsize, 0);
+
+ if (bytes < 0)
+ {
+ copyfile_debug(1, "pread returned: %d", bytes);
+ error = -1;
+ goto exit;
+ }
+ if (bytes < hdrsize)
+ {
+ copyfile_debug(1,
+ "pread couldn't read entire header: %d of %d",
+ (int)bytes, (int)s->sb.st_size);
+ error = -1;
+ goto exit;
+ }
+ adhdr = (apple_double_header_t *)buffer;
+
+ /*
+ * Check for Apple Double file.
+ */
+ if (bytes < sizeof(apple_double_header_t) - 2 ||
+ SWAP32(adhdr->magic) != ADH_MAGIC ||
+ SWAP32(adhdr->version) != ADH_VERSION ||
+ SWAP16(adhdr->numEntries) != 2 ||
+ SWAP32(adhdr->entries[0].type) != AD_FINDERINFO)
+ {
+ if (COPYFILE_VERBOSE & s->flags)
+ copyfile_warn("Not a valid Apple Double header");
+ error = -1;
+ goto exit;
+ }
+ swap_adhdr(adhdr);
+
+ /*
+ * Extract the extended attributes.
+ *
+ * >>> WARNING <<<
+ * This assumes that the data is already in memory (not
+ * the case when there are lots of attributes or one of
+ * the attributes is very large.
+ */
+ if (adhdr->entries[0].length > FINDERINFOSIZE)
+ {
+ attr_header_t *attrhdr;
+ attr_entry_t *entry;
+ int count;
+ int i;
+
+ attrhdr = (attr_header_t *)buffer;
+ swap_attrhdr(attrhdr);
+ if (attrhdr->magic != ATTR_HDR_MAGIC)
+ {
+ if (COPYFILE_VERBOSE & s->flags)
+ copyfile_warn("bad attribute header");
+ error = -1;
+ goto exit;
+ }
+ count = attrhdr->num_attrs;
+ entry = (attr_entry_t *)&attrhdr[1];
+ for (i = 0; i < count; i++)
+ {
+ void * dataptr;
+
+ copyfile_debug(2, "extracting \"%s\" (%d bytes)",
+ entry->name, entry->length);
+ dataptr = (char *)attrhdr + entry->offset;
+
+ if (COPYFILE_ACL & s->flags && strncmp(entry->name, XATTR_SECURITY_NAME, strlen(XATTR_SECURITY_NAME)) == 0)
+ {
+ acl_t acl;
+ if ((acl = acl_from_text(dataptr)) != NULL)
+ {
+ if (filesec_set_property(s->fsec, FILESEC_ACL, &acl) < 0)
+ {
+ acl_t acl;
+ if ((acl = acl_from_text(dataptr)) != NULL)
+ {
+ if (filesec_set_property(s->fsec, FILESEC_ACL, &acl) < 0)
+ {
+ copyfile_debug(1, "setting acl");
+ }
+ else if (fchmodx_np(s->dst_fd, s->fsec) < 0 && errno != ENOTSUP)
+ copyfile_warn("setting security information");
+ acl_free(acl);
+ }
+ } else
+ if (COPYFILE_XATTR & s->flags && (fsetxattr(s->dst_fd, entry->name, dataptr, entry->length, 0, 0))) {
+ if (COPYFILE_VERBOSE & s->flags)
+ copyfile_warn("error %d setting attribute %s", error, entry->name);
+ goto exit;
+ }
+ else if (fchmodx_np(s->dst_fd, s->fsec) < 0 && errno != ENOTSUP)
+ copyfile_warn("setting security information");
+ acl_free(acl);
+ }
+ } else
+ if (COPYFILE_XATTR & s->flags && (fsetxattr(s->dst_fd, entry->name, dataptr, entry->length, 0, 0))) {
+ if (COPYFILE_VERBOSE & s->flags)
+ copyfile_warn("error %d setting attribute %s", error, entry->name);
+ break;
+ }
+ entry = ATTR_NEXT(entry);
+ }
+ }
+
+ /*
+ * Extract the Finder Info.
+ */
+ if (bcmp((u_int8_t*)buffer + adhdr->entries[0].offset, emptyfinfo, sizeof(emptyfinfo)) != 0)
+ {
+ copyfile_debug(1, " extracting \"%s\" (32 bytes)", XATTR_FINDERINFO_NAME);
+ error = fsetxattr(s->dst_fd, XATTR_FINDERINFO_NAME, (u_int8_t*)buffer + adhdr->entries[0].offset, sizeof(emptyfinfo), 0, 0);
+ if (error)
+ goto exit;
+ }
+
+ /*
+ * Extract the Resource Fork.
+ */
+ if (adhdr->entries[1].type == AD_RESOURCE &&
+ adhdr->entries[1].length > 0)
+ {
+ void * rsrcforkdata;
+ size_t length;
+ off_t offset;
+
+ length = adhdr->entries[1].length;
+ offset = adhdr->entries[1].offset;
+ rsrcforkdata = malloc(length);
+
+ bytes = pread(s->src_fd, rsrcforkdata, length, offset);
+ if (bytes < length)
+ {
+ if (bytes == -1)
+ {
+ copyfile_debug(1, "couldn't read resource fork");
+ }
+ else
+ {
+ copyfile_debug(1,
+ "couldn't read resource fork (only read %d bytes of %d)",
+ (int)bytes, (int)length);
+ }
+ error = -1;
+ goto exit;
+ }
+ error = fsetxattr(s->dst_fd, XATTR_RESOURCEFORK_NAME, rsrcforkdata, bytes, 0, 0);
+ if (error)
+ {
+ copyfile_debug(1, "error %d setting resource fork attribute", error);
+ error = -1;
+ goto exit;
+ }
+ copyfile_debug(1, "extracting \"%s\" (%d bytes)",
+ XATTR_RESOURCEFORK_NAME, (int)length);
+ free(rsrcforkdata);
+ }
+exit:
+ free(buffer);
+ return error;
+}
+
+static int copyfile_pack_acl(copyfile_state_t s, void **buf, ssize_t *len)
+{
+ int ret = 0;
+ acl_t acl;
+ char *acl_text;
+
+ if (filesec_get_property(s->fsec, FILESEC_ACL, &acl) < 0)
+ {
+ if (errno != ENOENT)
+ {
+ ret = -1;
+ if (COPYFILE_VERBOSE & s->flags)
+ copyfile_warn("getting acl");
+ }
+ goto err;
+ }
+
+ if ((acl_text = acl_to_text(acl, len)) != NULL)
+ {
+ *buf = malloc(*len);
+ memcpy(*buf, acl_text, *len);
+ acl_free(acl_text);
+ }
+ copyfile_debug(1, "copied acl (%ld) %p", *len, *buf);
+err:
+ return ret;
+}
+
+static int copyfile_pack_rsrcfork(copyfile_state_t s, attr_header_t *filehdr)
+{
+ int datasize;
+ char *databuf;
+
+ /* Get the resource fork size */
+ if ((datasize = fgetxattr(s->src_fd, XATTR_RESOURCEFORK_NAME, NULL, 0, 0, 0)) < 0)
+ {
+ if (COPYFILE_VERBOSE & s->flags)
+ copyfile_warn("skipping attr \"%s\" due to error %d", XATTR_RESOURCEFORK_NAME, errno);
+ return -1;
+ }
+
+ if ((databuf = malloc(datasize)) == NULL)
+ {
+ copyfile_warn("malloc");
+ return -1;
+ }
+
+ if (fgetxattr(s->src_fd, XATTR_RESOURCEFORK_NAME, databuf, datasize, 0, 0) != datasize)
+ {
+ if (COPYFILE_VERBOSE & s->flags)
+ copyfile_warn("couldn't read entire resource fork");
+ return -1;
+ }
+
+ /* Write the resource fork to disk. */
+ if (pwrite(s->dst_fd, databuf, datasize, filehdr->appledouble.entries[1].offset) != datasize)
+ {
+ if (COPYFILE_VERBOSE & s->flags)
+ copyfile_warn("couldn't write resource fork");
+ }
+ copyfile_debug(1, "copied %d bytes of \"%s\" data @ offset 0x%08x",
+ datasize, XATTR_RESOURCEFORK_NAME, filehdr->appledouble.entries[1].offset);
+ filehdr->appledouble.entries[1].length = datasize;
+ free(databuf);
+
+ return 0;
+}
+
+
+static int copyfile_pack(copyfile_state_t s)
+{
+ char *attrnamebuf;
+ void *databuf;
+ attr_header_t *filehdr;
+ attr_entry_t *entry;
+ ssize_t listsize;
+ char *nameptr;
+ int namelen;
+ int entrylen;
+ ssize_t datasize;
+ int offset = 0;
+ int hasrsrcfork = 0;
+ int error = 0;
+
+ filehdr = (attr_header_t *) calloc(1, ATTR_MAX_SIZE);
+ attrnamebuf = calloc(1, ATTR_MAX_HDR_SIZE);
+
+ /*
+ * Fill in the Apple Double Header defaults.
+ */
+ filehdr->appledouble.magic = SWAP32 (ADH_MAGIC);
+ filehdr->appledouble.version = SWAP32 (ADH_VERSION);
+ filehdr->appledouble.numEntries = SWAP16 (2);
+ filehdr->appledouble.entries[0].type = SWAP32 (AD_FINDERINFO);
+ filehdr->appledouble.entries[0].offset = SWAP32 (offsetof(apple_double_header_t, finfo));
+ filehdr->appledouble.entries[0].length = SWAP32 (FINDERINFOSIZE);
+ filehdr->appledouble.entries[1].type = SWAP32 (AD_RESOURCE);
+ filehdr->appledouble.entries[1].offset = SWAP32 (offsetof(apple_double_header_t, pad));
+ filehdr->appledouble.entries[1].length = 0;
+ bcopy(ADH_MACOSX, filehdr->appledouble.filler, sizeof(filehdr->appledouble.filler));
+
+ /*
+ * Fill in the initial Attribute Header.
+ */
+ filehdr->magic = SWAP32 (ATTR_HDR_MAGIC);
+ filehdr->debug_tag = SWAP32 (s->sb.st_ino);
+ filehdr->data_start = SWAP32 (sizeof(attr_header_t));
+
+ /*
+ * Collect the attribute names.
+ */
+ entry = (attr_entry_t *)((char *)filehdr + sizeof(attr_header_t));
+
+ /*
+ * Test if there are acls to copy
+ */
+ if (COPYFILE_ACL & s->flags)
+ {
+ if (filesec_get_property(s->fsec, FILESEC_ACL, &datasize) < 0)
+ {
+ copyfile_debug(1, "no acl entries found (%d)", datasize < 0 ? errno : 0);
+ } else
+ {
+ offset = strlen(XATTR_SECURITY_NAME) + 1;
+ strcpy(attrnamebuf, XATTR_SECURITY_NAME);
+ }
+ }
+
+ if (COPYFILE_XATTR & s->flags)
+ {
+ if ((listsize = flistxattr(s->src_fd, attrnamebuf + offset, ATTR_MAX_HDR_SIZE, 0)) <= 0)
+ {
+ copyfile_debug(1, "no extended attributes found (%d)", errno);
+ }
+ if (listsize > ATTR_MAX_HDR_SIZE)
+ {
+ copyfile_debug(1, "extended attribute list too long");
+ listsize = ATTR_MAX_HDR_SIZE;
+ }
+
+ listsize += offset;
+
+ for (nameptr = attrnamebuf; nameptr < attrnamebuf + listsize; nameptr += namelen)
+ {
+ namelen = strlen(nameptr) + 1;
+ /* Skip over FinderInfo or Resource Fork names */
+ if (strncmp(nameptr, XATTR_FINDERINFO_NAME, strlen(XATTR_FINDERINFO_NAME)) == 0 ||
+ strncmp(nameptr, XATTR_RESOURCEFORK_NAME, strlen(XATTR_RESOURCEFORK_NAME)) == 0)
+ continue;
+
+ entry->namelen = namelen;
+ entry->flags = 0;
+ bcopy(nameptr, &entry->name[0], namelen);
+ copyfile_debug(2, "copied name [%s]", entry->name);
+
+ entrylen = ATTR_ENTRY_LENGTH(namelen);
+ entry = (attr_entry_t *)(((char *)entry) + entrylen);
+
+ /* Update the attributes header. */
+ filehdr->num_attrs++;
+ filehdr->data_start += entrylen;
+ }
+ }
+
+ /*
+ * Collect the attribute data.
+ */
+ entry = (attr_entry_t *)((char *)filehdr + sizeof(attr_header_t));
+
+ for (nameptr = attrnamebuf; nameptr < attrnamebuf + listsize; nameptr += namelen + 1)
+ {
+ nameptr = nameptr;
+ namelen = strlen(nameptr);
+
+ if (strncmp(nameptr, XATTR_SECURITY_NAME, strlen(XATTR_SECURITY_NAME)) == 0)
+ copyfile_pack_acl(s, &databuf, &datasize);
+ else
+ /* Check for Finder Info. */
+ if (strncmp(nameptr, XATTR_FINDERINFO_NAME, strlen(XATTR_FINDERINFO_NAME)) == 0)
+ {
+ datasize = fgetxattr(s->src_fd, nameptr, (u_int8_t*)filehdr + filehdr->appledouble.entries[0].offset, 32, 0, 0);
+ if (datasize < 0)
+ {
+ if (COPYFILE_VERBOSE & s->flags)
+ copyfile_warn("skipping attr \"%s\" due to error %d", nameptr, errno);
+ } else if (datasize != 32)
+ {
+ if (COPYFILE_VERBOSE & s->flags)
+ copyfile_warn("unexpected size (%ld) for \"%s\"", datasize, nameptr);
+ } else
+ {
+ if (COPYFILE_VERBOSE & s->flags)
+ copyfile_warn(" copied 32 bytes of \"%s\" data @ offset 0x%08x",
+ XATTR_FINDERINFO_NAME, filehdr->appledouble.entries[0].offset);
+ }
+ continue; /* finder info doesn't have an attribute entry */
+ } else
+ /* Check for Resource Fork. */
+ if (strncmp(nameptr, XATTR_RESOURCEFORK_NAME, strlen(XATTR_RESOURCEFORK_NAME)) == 0)
+ {
+ hasrsrcfork = 1;
+ continue;
+ } else
+ {
+ /* Just a normal attribute. */
+ datasize = fgetxattr(s->src_fd, nameptr, NULL, 0, 0, 0);
+ if (datasize == 0)
+ goto next;
+ if (datasize < 0)
+ {
+ if (COPYFILE_VERBOSE & s->flags)
+ copyfile_warn("skipping attr \"%s\" due to error %d", nameptr, errno);
+ goto next;
+ }
+ if (datasize > XATTR_MAXATTRLEN)
+ {
+ if (COPYFILE_VERBOSE & s->flags)
+ copyfile_warn("skipping attr \"%s\" (too big)", nameptr);
+ goto next;
+ }
+ databuf = malloc(datasize);
+ datasize = fgetxattr(s->src_fd, nameptr, databuf, datasize, 0, 0);
+ }
+
+ entry->length = datasize;
+ entry->offset = filehdr->data_start + filehdr->data_length;
+
+ filehdr->data_length += datasize;
+ /*
+ * >>> WARNING <<<
+ * This assumes that the data is fits in memory (not
+ * the case when there are lots of attributes or one of
+ * the attributes is very large.
+ */
+ bcopy(databuf, (char*)filehdr + entry->offset, datasize);
+ free(databuf);
+
+ copyfile_debug(1, "copied %ld bytes of \"%s\" data @ offset 0x%08x", datasize, nameptr, entry->offset);
+next:
+ /* bump to next entry */
+ entrylen = ATTR_ENTRY_LENGTH(entry->namelen);
+ entry = (attr_entry_t *)((char *)entry + entrylen);
+ }
+
+ if (filehdr->data_length > 0)
+ {
+ /* Now we know where the resource fork data starts. */
+ filehdr->appledouble.entries[1].offset = (filehdr->data_start + filehdr->data_length);
+
+ /* We also know the size of the "Finder Info entry. */
+ filehdr->appledouble.entries[0].length =
+ filehdr->appledouble.entries[1].offset - filehdr->appledouble.entries[0].offset;
+
+ filehdr->total_size = SWAP32 (filehdr->appledouble.entries[1].offset);
+ }
+
+ /* Copy Resource Fork. */
+ if (hasrsrcfork && (error = copyfile_pack_rsrcfork(s, filehdr)))
+ goto exit;
+
+ /* Write the header to disk. */
+ datasize = filehdr->appledouble.entries[1].offset;
+
+ if (pwrite(s->dst_fd, filehdr, datasize, 0) != datasize)
+ {
+ if (COPYFILE_VERBOSE & s->flags)
+ copyfile_warn("couldn't write file header");
+ error = -1;
+ goto exit;
+ }
+exit:
+ free(filehdr);
+ free(attrnamebuf);
+
+ if (error)
+ return error;
+ else
+ return copyfile_stat(s);
+}
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#ifndef _COPYFILE_H_ /* version 0.1 */
+#define _COPYFILE_H_
+
+/*
+ * this is a proposed API to add to libSystem to faciliatate copying
+ * of files and their associated metadata. There are several open
+ * source projects that need modifications to support preserving
+ * extended attributes and acls and this API collapses several hundred
+ * lines of modifications into one or two calls.
+ *
+ * This implementation is incomplete and the interface may change in a
+ * future release.
+ */
+
+/* private */
+#include <stdint.h>
+struct _copyfile_state;
+typedef struct _copyfile_state * copyfile_state_t;
+typedef uint32_t copyfile_flags_t;
+
+/* public */
+
+/* receives:
+ * from path to source file system object
+ * to path to destination file system object
+ * state opaque blob for future extensibility
+ * Must be NULL in current implementation
+ * flags (described below)
+ * returns:
+ * int negative for error
+ */
+
+int copyfile(const char *from, const char *to, copyfile_state_t state, copyfile_flags_t flags);
+int copyfile_free(copyfile_state_t);
+copyfile_state_t copyfile_init(void);
+
+/* Flag for clients to disable their use of copyfile() */
+#define COPYFILE_DISABLE_VAR "COPY_EXTENDED_ATTRIBUTES_DISABLE"
+
+/* flags for copyfile */
+
+#define COPYFILE_ACL (1<<0)
+#define COPYFILE_STAT (1<<1)
+#define COPYFILE_XATTR (1<<2)
+#define COPYFILE_DATA (1<<3)
+
+#define COPYFILE_SECURITY (COPYFILE_STAT | COPYFILE_ACL)
+#define COPYFILE_METADATA (COPYFILE_SECURITY | COPYFILE_XATTR)
+#define COPYFILE_ALL (COPYFILE_METADATA | COPYFILE_DATA)
+
+#define COPYFILE_CHECK (1<<16) /* return flags for xattr or acls if set */
+#define COPYFILE_EXCL (1<<17) /* fail if destination exists */
+#define COPYFILE_NOFOLLOW_SRC (1<<18) /* don't follow if source is a symlink */
+#define COPYFILE_NOFOLLOW_DST (1<<19) /* don't follow if dst is a symlink */
+#define COPYFILE_MOVE (1<<20) /* unlink src after copy */
+#define COPYFILE_UNLINK (1<<21) /* unlink dst before copy */
+#define COPYFILE_NOFOLLOW (COPYFILE_NOFOLLOW_SRC | COPYFILE_NOFOLLOW_DST)
+
+#define COPYFILE_PACK (1<<22)
+#define COPYFILE_UNPACK (1<<23)
+
+#define COPYFILE_VERBOSE (1<<30)
+
+#endif /* _COPYFILE_H_ */
static char sccsid[] = "@(#)bt_debug.c 8.5 (Berkeley) 8/17/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/db/btree/bt_debug.c,v 1.2 2002/03/22 21:52:01 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/db/btree/bt_debug.c,v 1.3 2004/09/10 05:41:41 kuriyama Exp $");
#include <sys/param.h>
(void)fprintf(stderr, "%s: pgsz %d",
F_ISSET(t, B_INMEM) ? "memory" : "disk", t->bt_psize);
if (F_ISSET(t, R_RECNO))
- (void)fprintf(stderr, " keys %lu", t->bt_nrecs);
+ (void)fprintf(stderr, " keys %u", t->bt_nrecs);
#undef X
#define X(flag, name) \
if (F_ISSET(t, flag)) { \
char *sep;
m = (BTMETA *)h;
- (void)fprintf(stderr, "magic %lx\n", m->magic);
- (void)fprintf(stderr, "version %lu\n", m->version);
- (void)fprintf(stderr, "psize %lu\n", m->psize);
- (void)fprintf(stderr, "free %lu\n", m->free);
- (void)fprintf(stderr, "nrecs %lu\n", m->nrecs);
- (void)fprintf(stderr, "flags %lu", m->flags);
+ (void)fprintf(stderr, "magic %x\n", m->magic);
+ (void)fprintf(stderr, "version %u\n", m->version);
+ (void)fprintf(stderr, "psize %u\n", m->psize);
+ (void)fprintf(stderr, "free %u\n", m->free);
+ (void)fprintf(stderr, "nrecs %u\n", m->nrecs);
+ (void)fprintf(stderr, "flags %u", m->flags);
#undef X
#define X(flag, name) \
if (m->flags & flag) { \
bl = GETBLEAF(h, cur);
if (bl->flags & P_BIGKEY)
(void)fprintf(stderr,
- "big key page %lu size %u/",
+ "big key page %u size %u/",
*(pgno_t *)bl->bytes,
*(u_int32_t *)(bl->bytes + sizeof(pgno_t)));
else if (bl->ksize)
- (void)fprintf(stderr, "%s/", bl->bytes);
+ (void)fprintf(stderr, "%.*s/",
+ bl->ksize, bl->bytes);
if (bl->flags & P_BIGDATA)
(void)fprintf(stderr,
- "big data page %lu size %u",
+ "big data page %u size %u",
*(pgno_t *)(bl->bytes + bl->ksize),
*(u_int32_t *)(bl->bytes + bl->ksize +
sizeof(pgno_t)));
rl = GETRLEAF(h, cur);
if (rl->flags & P_BIGDATA)
(void)fprintf(stderr,
- "big data page %lu size %u",
+ "big data page %u size %u",
*(pgno_t *)rl->bytes,
*(u_int32_t *)(rl->bytes + sizeof(pgno_t)));
else if (rl->dsize)
(void)fprintf(stderr, "%d level%s with %ld keys",
levels, levels == 1 ? "" : "s", nkeys);
if (F_ISSET(t, R_RECNO))
- (void)fprintf(stderr, " (%ld header count)", t->bt_nrecs);
+ (void)fprintf(stderr, " (%d header count)", t->bt_nrecs);
(void)fprintf(stderr,
- "\n%lu pages (leaf %ld, internal %ld, overflow %ld)\n",
+ "\n%u pages (leaf %d, internal %d, overflow %d)\n",
pinternal + pleaf + pcont, pleaf, pinternal, pcont);
(void)fprintf(stderr, "%ld cache hits, %ld cache misses\n",
bt_cache_hit, bt_cache_miss);
- (void)fprintf(stderr, "%ld splits (%ld root splits, %ld sort splits)\n",
+ (void)fprintf(stderr, "%lu splits (%lu root splits, %lu sort splits)\n",
bt_split, bt_rootsplit, bt_sortsplit);
pleaf *= t->bt_psize - BTDATAOFF;
if (pleaf)
static char sccsid[] = "@(#)bt_split.c 8.9 (Berkeley) 7/26/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/db/btree/bt_split.c,v 1.5 2003/02/16 17:29:09 nectar Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/db/btree/bt_split.c,v 1.7 2004/09/13 22:07:24 kuriyama Exp $");
#include <sys/types.h>
* the right page.
*/
if (skip <= off) {
- skip = 0;
+ skip = MAX_PAGE_OFFSET;
rval = l;
} else {
rval = r;
for (off = 0; nxt < top; ++off) {
if (skip == nxt) {
++off;
- skip = 0;
+ skip = MAX_PAGE_OFFSET;
}
switch (h->flags & P_TYPE) {
case P_BINTERNAL:
static char sccsid[] = "@(#)hash.c 8.9 (Berkeley) 6/16/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/db/hash/hash.c,v 1.11 2002/03/21 22:46:26 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/db/hash/hash.c,v 1.12 2004/09/10 05:41:41 kuriyama Exp $");
#include "namespace.h"
#include <sys/param.h>
#ifdef DEBUG
(void)fprintf(stderr,
-"%s\n%s%x\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%x\n%s%x\n%s%d\n%s%d\n",
+"%s\n%s%p\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%x\n%s%x\n%s%d\n%s%d\n",
"init_htab:",
"TABLE POINTER ", hashp,
"BUCKET SIZE ", hashp->BSIZE,
---- hash.c.orig Thu Mar 21 14:46:26 2002
-+++ hash.c Sat Oct 18 18:30:33 2003
+--- /Volumes/XDisk/tmp/Libc/db/hash/FreeBSD/hash.c.orig 2004-09-09 22:41:41.000000000 -0700
++++ /Volumes/XDisk/tmp/Libc/db/hash/FreeBSD/hash.c 2004-10-24 17:08:27.000000000 -0700
@@ -58,7 +58,7 @@
#include <db.h>
#include "hash.h"
--- /dev/null
+--- hash.h.orig 2003-10-22 19:07:01.000000000 -0700
++++ hash.h 2004-10-23 22:52:09.000000000 -0700
+@@ -117,6 +117,8 @@
+ * allocate */
+ BUFHEAD bufhead; /* Header of buffer lru list */
+ SEGMENT *dir; /* Hash Bucket directory */
++ /* other flags */
++ int nextkey_eof :1; /* dbm_nextkey() reached EOF */
+ } HTAB;
+
+ /*
---- ndbm.c.orig Wed Oct 22 19:07:02 2003
-+++ ndbm.c Wed Dec 17 09:24:33 2003
+--- ndbm.c.orig 2004-10-28 23:25:13.000000000 -0700
++++ ndbm.c 2004-10-28 23:25:42.000000000 -0700
@@ -51,6 +51,7 @@
#include <string.h>
#include <errno.h>
{
HASHINFO info;
char path[MAXPATHLEN];
+@@ -128,10 +130,14 @@
+ int status;
+ datum retkey;
+ DBT dbtretkey, dbtretdata;
++ HTAB *htab = (HTAB *)(db->internal);
+
+ status = (db->seq)(db, &dbtretkey, &dbtretdata, R_FIRST);
+- if (status)
++ if (status) {
+ dbtretkey.data = NULL;
++ htab->nextkey_eof = 1;
++ } else
++ htab->nextkey_eof = 0;
+ retkey.dptr = dbtretkey.data;
+ retkey.dsize = dbtretkey.size;
+ return (retkey);
+@@ -146,13 +152,20 @@
+ dbm_nextkey(db)
+ DBM *db;
+ {
+- int status;
++ int status = 1;
+ datum retkey;
+ DBT dbtretkey, dbtretdata;
++ HTAB *htab = (HTAB *)(db->internal);
+
+- status = (db->seq)(db, &dbtretkey, &dbtretdata, R_NEXT);
+- if (status)
++ if (htab->nextkey_eof)
+ dbtretkey.data = NULL;
++ else {
++ status = (db->seq)(db, &dbtretkey, &dbtretdata, R_NEXT);
++ if (status) {
++ dbtretkey.data = NULL;
++ htab->nextkey_eof = 1;
++ }
++ }
+ retkey.dptr = dbtretkey.data;
+ retkey.dsize = dbtretkey.size;
+ return (retkey);
.\" SUCH DAMAGE.
.\"
.\" @(#)btree.3 8.4 (Berkeley) 8/18/94
-.\" $FreeBSD: src/lib/libc/db/man/btree.3,v 1.6 2002/12/19 09:40:21 ru Exp $
+.\" $FreeBSD: src/lib/libc/db/man/btree.3,v 1.8 2004/07/02 23:52:10 ru Exp $
.\"
.Dd August 18, 1994
.Dt BTREE 3
access method specific data structure provided to
.Fn dbopen
is defined in the
-.Aq Pa db.h
+.In db.h
include file as follows:
.Bd -literal
typedef struct {
any of the following values:
.Bl -tag -width indent
.It Dv R_DUP
-Permit duplicate keys in the tree, i.e. permit insertion if the key to be
+Permit duplicate keys in the tree, i.e., permit insertion if the key to be
inserted already exists in the tree.
The default behavior, as described in
.Xr dbopen 3 ,
.It Va minkeypage
The minimum number of keys which will be stored on any single page.
This value is used to determine which keys will be stored on overflow
-pages, i.e. if a key or data item is longer than the pagesize divided
+pages, i.e., if a key or data item is longer than the pagesize divided
by the minkeypage value, it will be stored on overflow pages instead
of in the page itself.
If
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/lib/libc/db/man/dbm.3,v 1.7 2002/12/19 09:40:21 ru Exp $
+.\" $FreeBSD: src/lib/libc/db/man/dbm.3,v 1.8 2003/09/08 19:57:13 ru Exp $
.\"
.\" Note: The date here should be updated whenever a non-trivial
.\" change is made to the manual page.
.Pp
.Vt datum
is declared in
-.Aq Pa ndbm.h :
+.In ndbm.h :
.Bd -literal
typedef struct {
char *dptr;
.\" SUCH DAMAGE.
.\"
.\" @(#)dbopen.3 8.5 (Berkeley) 1/2/94
-.\" $FreeBSD: src/lib/libc/db/man/dbopen.3,v 1.8 2002/12/19 09:40:21 ru Exp $
+.\" $FreeBSD: src/lib/libc/db/man/dbopen.3,v 1.10 2004/07/02 23:52:10 ru Exp $
.\"
.Dd January 2, 1994
.Dt DBOPEN 3
argument is of type
.Ft DBTYPE
(as defined in the
-.Aq Pa db.h
+.In db.h
include file) and
may be set to
.Dv DB_BTREE , DB_HASH
The
.Ft DB
structure is defined in the
-.Aq Pa db.h
+.In db.h
include file, and contains at
least the following fields:
.Bd -literal
.Va sync
routines.
Modifications to the database during a sequential scan will be reflected
-in the scan, i.e. records inserted behind the cursor will not be returned
+in the scan, i.e., records inserted behind the cursor will not be returned
while records inserted in front of the cursor will be returned.
.Pp
The
.\" SUCH DAMAGE.
.\"
.\" @(#)hash.3 8.6 (Berkeley) 8/18/94
-.\" $FreeBSD: src/lib/libc/db/man/hash.3,v 1.7 2002/12/19 09:40:21 ru Exp $
+.\" $FreeBSD: src/lib/libc/db/man/hash.3,v 1.8 2003/09/08 19:57:13 ru Exp $
.\"
.Dd August 18, 1994
.Dt HASH 3
The access method specific data structure provided to
.Fn dbopen
is defined in the
-.Aq Pa db.h
+.In db.h
include file as follows:
.Bd -literal
typedef struct {
.\" SUCH DAMAGE.
.\"
.\" @(#)mpool.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/db/man/mpool.3,v 1.12 2003/02/06 11:04:46 charnier Exp $
+.\" $FreeBSD: src/lib/libc/db/man/mpool.3,v 1.13 2004/08/27 14:51:21 roam Exp $
.\"
.Dd June 4, 1993
.Dt MPOOL 3
.Nm mpool
library interface is intended to provide page oriented buffer management
of files.
-The buffers may be shared between processes.
.Pp
The
.Fn mpool_open
function initializes a memory pool.
The
.Fa key
-argument is the byte string used to negotiate between multiple
-processes wishing to share buffers.
-If the file buffers are mapped in shared memory, all processes using
-the same key will share the buffers.
-If
-.Fa key
-is
-.Dv NULL ,
-the buffers are mapped into private memory.
+argument is currently ignored.
The
.Fa fd
argument is a file descriptor for the underlying file, which must be seekable.
-If
-.Fa key
-is
-.No non\- Ns Dv NULL
-and matches a file already being mapped, the
-.Fa fd
-argument is ignored.
.Pp
The
.Fa pagesize
.\" SUCH DAMAGE.
.\"
.\" @(#)recno.3 8.5 (Berkeley) 8/18/94
-.\" $FreeBSD: src/lib/libc/db/man/recno.3,v 1.6 2001/10/01 16:08:50 ru Exp $
+.\" $FreeBSD: src/lib/libc/db/man/recno.3,v 1.8 2004/07/02 23:52:10 ru Exp $
.\"
.Dd August 18, 1994
.Dt RECNO 3
access method specific data structure provided to
.Fn dbopen
is defined in the
-.Aq Pa db.h
+.In db.h
include file as follows:
.Bd -literal
typedef struct {
field of the key should be a pointer to a memory location of type
.Ft recno_t ,
as defined in the
-.Aq Pa db.h
+.In db.h
include file.
This type is normally the largest unsigned integral type available to
the implementation.
Because there can be no meta-data associated with the underlying
.Nm
access method files, any changes made to the default values
-(e.g. fixed record length or byte separator value) must be explicitly
+(e.g.\& fixed record length or byte separator value) must be explicitly
specified each time the file is opened.
.Pp
In the interface specified by
static char sccsid[] = "@(#)mpool.c 8.5 (Berkeley) 7/26/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/db/mpool/mpool.c,v 1.10 2002/03/22 21:52:01 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/db/mpool/mpool.c,v 1.12 2004/09/10 05:41:41 kuriyama Exp $");
#include "namespace.h"
#include <sys/param.h>
++mp->pageread;
#endif
off = mp->pagesize * pgno;
- if (lseek(mp->fd, off, SEEK_SET) != off)
- return (NULL);
- if ((nr = _read(mp->fd, bp->page, mp->pagesize)) != mp->pagesize) {
+ nr = pread(mp->fd, bp->page, mp->pagesize, off);
+ if (nr != mp->pagesize) {
if (nr >= 0)
errno = EFTYPE;
return (NULL);
(mp->pgout)(mp->pgcookie, bp->pgno, bp->page);
off = mp->pagesize * bp->pgno;
- if (lseek(mp->fd, off, SEEK_SET) != off)
- return (RET_ERROR);
- if (_write(mp->fd, bp->page, mp->pagesize) != mp->pagesize)
+ if (pwrite(mp->fd, bp->page, mp->pagesize, off) != mp->pagesize)
return (RET_ERROR);
bp->flags &= ~MPOOL_DIRTY;
int cnt;
char *sep;
- (void)fprintf(stderr, "%lu pages in the file\n", mp->npages);
+ (void)fprintf(stderr, "%u pages in the file\n", mp->npages);
(void)fprintf(stderr,
- "page size %lu, cacheing %lu pages of %lu page max cache\n",
+ "page size %lu, cacheing %u pages of %u page max cache\n",
mp->pagesize, mp->curcache, mp->maxcache);
(void)fprintf(stderr, "%lu page puts, %lu page gets, %lu page new\n",
mp->pageput, mp->pageget, mp->pagenew);
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#define _BYTE_ORDER BYTE_ORDER
#define _LITTLE_ENDIAN LITTLE_ENDIAN
#define __ct_rune_t ct_rune_t
-#define __va_list _BSD_VA_LIST_
+#define __va_list __darwin_va_list
/*
* Do the opposite of FreeBSD namespace.h; that is, map the "hidden" names
#define __makecontext makecontext
#define __pause pause
#define __pselect pselect
+#define __raise raise
#define __signalcontext signalcontext
#define __sleep sleep
#define __strtok_r strtok_r
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* $FreeBSD: src/lib/libc/i386/_fpmath.h,v 1.3 2004/01/18 07:57:01 das Exp $
*/
+#if defined(__ppc__) || defined(__ppc64__)
+
+union IEEEl2bits {
+ long double e;
+ double d[2];
+ struct {
+ unsigned long long sign :1;
+ unsigned long long exp :11;
+ unsigned long long manh :52;
+ unsigned long long sign2 :1;
+ unsigned long long exp2 :11;
+ unsigned long long manl :52;
+ } bits;
+};
+
+#define mask_nbit_l(u) ((void)0)
+#define LDBL_IMPLICIT_NBIT
+
+#define LDBL_MANH_SIZE 52
+#define LDBL_MANL_SIZE 53 // includes hidden bit
+
+#define LDBL_HEAD_TAIL_PAIR
+
+__private_extern__ void _ldbl2array32dd(union IEEEl2bits, uint32_t *);
+
+#define LDBL_TO_ARRAY32(u, a) _ldbl2array32dd(u, a)
+
+#elif defined(__i386__)
+
union IEEEl2bits {
long double e;
struct {
(a)[0] = (uint32_t)(u).bits.manl; \
(a)[1] = (uint32_t)(u).bits.manh; \
} while(0)
+
+#else
+#error unsupported architecture
+#endif
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#ifndef _SYS_CDEFS_H_
-#define _SYS_CDEFS_H_
-//------------------------- Begin Added ----------------------------------
-/*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-/* Copyright 1995 NeXT Computer, Inc. All rights reserved. */
-/*
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Berkeley Software Design, Inc.
- *
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- *
- * @(#)cdefs.h 8.8 (Berkeley) 1/9/95
- */
-
-#ifdef __APPLE__
-/*
- * GCC1 and some versions of GCC2 declare dead (non-returning) and
- * pure (no side effects) functions using "volatile" and "const";
- * unfortunately, these then cause warnings under "-ansi -pedantic".
- * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of
- * these work for GNU C++ (modulo a slight glitch in the C++ grammar
- * in the distribution version of 2.5.5).
- */
-#if defined(__MWERKS__) && (__MWERKS__ > 0x2400)
- /* newer Metrowerks compilers support __attribute__() */
-#elif !defined(__GNUC__) || __GNUC__ < 2 || \
- (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
-#define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
-#define __dead __volatile
-#define __pure __const
-#endif
-#endif
-
-/* Delete pseudo-keywords wherever they are not available or needed. */
-#ifndef __dead
-#define __dead
-#define __pure
-#endif
-#endif // __APPLE__
-//-------------------------- End Added -----------------------------------
-
-#if defined(__cplusplus)
-#define __BEGIN_DECLS extern "C" {
-#define __END_DECLS }
-#else
-#define __BEGIN_DECLS
-#define __END_DECLS
-#endif
-
-/*
- * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
- * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
- * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI
- * mode -- there must be no spaces between its arguments, and for nested
- * __CONCAT's, all the __CONCAT's must be at the left. __CONCAT can also
- * concatenate double-quoted strings produced by the __STRING macro, but
- * this only works with ANSI C.
- *
- * __XSTRING is like __STRING, but it expands any macros in its argument
- * first. It is only available with ANSI C.
- */
-#if defined(__STDC__) || defined(__cplusplus)
-#define __P(protos) protos /* full-blown ANSI C */
-#define __CONCAT1(x,y) x ## y
-#define __CONCAT(x,y) __CONCAT1(x,y)
-#define __STRING(x) #x /* stringify without expanding x */
-#define __XSTRING(x) __STRING(x) /* expand x, then stringify */
-
-#define __const const /* define reserved names to standard */
-#define __signed signed
-#define __volatile volatile
-#if defined(__cplusplus)
-#define __inline inline /* convert to C++ keyword */
-#else
-#ifndef __GNUC__
-#define __inline /* delete GCC keyword */
-#endif /* !__GNUC__ */
-#endif /* !__cplusplus */
-
-#else /* !(__STDC__ || __cplusplus) */
-#define __P(protos) () /* traditional C preprocessor */
-#define __CONCAT(x,y) x/**/y
-#define __STRING(x) "x"
-
-#ifndef __GNUC__
-#define __const /* delete pseudo-ANSI C keywords */
-#define __inline
-#define __signed
-#define __volatile
-/*
- * In non-ANSI C environments, new programs will want ANSI-only C keywords
- * deleted from the program and old programs will want them left alone.
- * When using a compiler other than gcc, programs using the ANSI C keywords
- * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
- * When using "gcc -traditional", we assume that this is the intent; if
- * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
- */
-#ifndef NO_ANSI_KEYWORDS
-#define const /* delete ANSI C keywords */
-#define inline
-#define signed
-#define volatile
-#endif /* !NO_ANSI_KEYWORDS */
-#endif /* !__GNUC__ */
-#endif /* !(__STDC__ || __cplusplus) */
/*
* Compiler-dependent macros to help declare dead (non-returning) and
* a feature that we cannot live without.
*/
#ifdef lint
-#define __dead2
-#define __pure2
-#define __unused
#define __packed
#define __aligned(x)
#define __section(x)
#else
-#if __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 5
-#define __dead2
-#define __pure2
-#define __unused
-#endif
-#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7
-#define __dead2 __attribute__((__noreturn__))
-#define __pure2 __attribute__((__const__))
-#define __unused
-/* XXX Find out what to do for __packed, __aligned and __section */
-#endif
-#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ == 3
-#define __dead2 __attribute__((__noreturn__))
-#define __pure2 __attribute__((__const__))
-#define __unused __attribute__((__unused__))
+#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ >= 3
#define __packed __attribute__((__packed__))
#define __aligned(x) __attribute__((__aligned__(x)))
#define __section(x) __attribute__((__section__(x)))
#define __LONG_LONG_SUPPORTED
#endif
-/*
- * GCC 2.95 provides `__restrict' as an extension to C90 to support the
- * C99-specific `restrict' type qualifier. We happen to use `__restrict' as
- * a way to define the `restrict' type qualifier without disturbing older
- * software that is unaware of C99 keywords.
- */
-#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95)
-#if __STDC_VERSION__ < 199901
-#define __restrict
-#else
-#define __restrict restrict
-#endif
-#endif
-
/*
* We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h>
* require it.
*/
#define __offsetof(type, field) ((size_t)(&((type *)0)->field))
-/*
- * Compiler-dependent macros to declare that functions take printf-like
- * or scanf-like arguments. They are null except for versions of gcc
- * that are known to support the features properly (old versions of gcc-2
- * didn't permit keeping the keywords out of the application namespace).
- */
-#if __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 7
-#define __printflike(fmtarg, firstvararg)
-#define __scanflike(fmtarg, firstvararg)
-#else
-#define __printflike(fmtarg, firstvararg) \
- __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
-#define __scanflike(fmtarg, firstvararg) \
- __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
-#endif
-
/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */
#if __FreeBSD_cc_version >= 300001 && __FreeBSD_cc_version < 500003
#define __printf0like(fmtarg, firstvararg) \
#endif // __APPLE__
#endif /* __GNUC__ */
-#ifdef __APPLE__
-#define __IDSTRING(name,string) \
- static const char name[] __attribute__((__unused__)) = string
-#else // ! __APPLE__
-#ifdef __GNUC__
-#define __IDSTRING(name,string) __asm__(".ident\t\"" string "\"")
-#else
-/*
- * This doesn't work in header files. But it may be better than nothing.
- * The alternative is: #define __IDSTRING(name,string) [nothing]
- */
-#define __IDSTRING(name,string) static const char name[] __unused = string
-#endif
-#endif // __APPLE__
-
/*
* Embed the rcs id of a source file in the resulting library. Note that in
* more recent ELF binutils, we use .ident allowing the ID to be stripped.
#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
- *
- * 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.
+/*
+ * Now include the Apple version of sys/cdefs.h
*/
-/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */
-#if _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 _POSIX_C_SOURCE == 2
-#undef _POSIX_C_SOURCE
-#define _POSIX_C_SOURCE 199209
-#endif
+#include_next <sys/cdefs.h>
-/* Deal with various X/Open Portability Guides and Single UNIX Spec. */
-#ifdef _XOPEN_SOURCE
-#if _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
+/*
+ * Use FreeBSD version of __CONCAT
+ */
+#if defined(__STDC__) || defined(__cplusplus)
+#undef __CONCAT1
+#undef __CONCAT
+#define __CONCAT1(x,y) x ## y
+#define __CONCAT(x,y) __CONCAT1(x,y)
#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 >= 200112
#define __POSIX_VISIBLE 200112
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+--- _hdtoa.c.orig 2004-06-03 15:22:08.000000000 -0700
++++ _hdtoa.c 2004-08-28 17:10:21.000000000 -0700
+@@ -32,6 +32,9 @@
+ #include <limits.h>
+ #include <math.h>
+ #include <stdlib.h>
++#ifdef LDBL_HEAD_TAIL_PAIR
++#include <alloca.h>
++#endif /* LDBL_HEAD_TAIL_PAIR */
+ #include "fpmath.h"
+ #include "gdtoaimp.h"
+
+@@ -301,16 +304,31 @@
+ int pos;
+ int shift; /* for subnormals, # of shifts required to normalize */
+ int sigfigs; /* number of significant hex figures in result */
++#ifdef LDBL_HEAD_TAIL_PAIR
++ uint32_t bits[4];
++ int i;
++#endif /* LDBL_HEAD_TAIL_PAIR */
+
+ u.e = e;
+ *sign = u.bits.sign;
+
++#ifdef LDBL_HEAD_TAIL_PAIR
++ switch (__fpclassifyd(u.d[0])) {
++#else /* LDBL_HEAD_TAIL_PAIR */
+ switch (fpclassify(e)) {
++#endif /* LDBL_HEAD_TAIL_PAIR */
+ case FP_NORMAL:
++#ifdef LDBL_HEAD_TAIL_PAIR
+ sigfigs = (LDBL_MANT_DIG + 3) / 4;
+ impnbit = 1 << ((LDBL_MANT_DIG - 1) % 4);
+ *decpt = u.bits.exp - LDBL_BIAS + 1 -
+ ((LDBL_MANT_DIG - 1) % 4);
++#else /* LDBL_HEAD_TAIL_PAIR */
++ sigfigs = (LDBL_MANT_DIG + 3) / 4;
++ impnbit = 1 << ((LDBL_MANT_DIG - 1) % 4);
++ *decpt = u.bits.exp - LDBL_BIAS + 1 -
++ ((LDBL_MANT_DIG - 1) % 4);
++#endif /* LDBL_HEAD_TAIL_PAIR */
+ break;
+ case FP_ZERO:
+ *decpt = 1;
+@@ -328,13 +346,26 @@
+ /* Don't trust the normalization bit to be off. */
+ u.bits.manh &= ~(~0ULL << (LDBL_MANH_SIZE - 1));
+ #endif
++#ifndef LDBL_HEAD_TAIL_PAIR
+ if (u.bits.manh != 0) {
++#endif /* LDBL_HEAD_TAIL_PAIR */
+ #if LDBL_MANH_SIZE > 32
+ pos = log2_64(u.bits.manh);
+ #else
+ pos = log2_32(u.bits.manh);
+ #endif
+ shift = LDBL_MANH_SIZE - LDBL_NBIT_ADJ - pos;
++#ifdef LDBL_HEAD_TAIL_PAIR
++ sigfigs = (3 + LDBL_MANT_DIG - LDBL_NBIT_ADJ - shift) / 4;
++ // we use DBL_MIN_EXP below because the head double is
++ // subnormal (and the tail double is zero)
++ *decpt = DBL_MIN_EXP + LDBL_NBIT_ADJ;
++ pos = (LDBL_MANT_DIG + 3) % 4;
++ if (pos < shift)
++ *decpt -= pos + ((shift - pos + 3) & ~(4 - 1));
++ else
++ *decpt -= shift;
++#else /* LDBL_HEAD_TAIL_PAIR */
+ } else {
+ #if LDBL_MANL_SIZE > 32
+ pos = log2_64(u.bits.manl);
+@@ -345,8 +376,9 @@
+ LDBL_NBIT_ADJ - pos;
+ }
+ sigfigs = (3 + LDBL_MANT_DIG - LDBL_NBIT_ADJ - shift) / 4;
+- *decpt = LDBL_MIN_EXP + LDBL_NBIT_ADJ -
++ *decpt = DBL_MIN_EXP + LDBL_NBIT_ADJ -
+ ((shift + 3) & ~(4 - 1));
++#endif /* LDBL_HEAD_TAIL_PAIR */
+ impnbit = 0;
+ break;
+ case FP_INFINITE:
+@@ -381,6 +413,19 @@
+ */
+ for (s = s0 + bufsize - 1; s > s0 + sigfigs - 1; s--)
+ *s = 0;
++#ifdef LDBL_HEAD_TAIL_PAIR
++ _ldbl2array32dd(u, bits);
++ i = 0;
++ pos = 8;
++ for (; s > s0; s--) {
++ *s = bits[i] & 0xf;
++ bits[i] >>= 4;
++ if (--pos <= 0) {
++ i++;
++ pos = 8;
++ }
++ }
++#else /* LDBL_HEAD_TAIL_PAIR */
+ for (; s > s0 + sigfigs - (LDBL_MANL_SIZE / 4) - 1 && s > s0; s--) {
+ *s = u.bits.manl & 0xf;
+ u.bits.manl >>= 4;
+@@ -389,6 +434,7 @@
+ *s = u.bits.manh & 0xf;
+ u.bits.manh >>= 4;
+ }
++#endif /* LDBL_HEAD_TAIL_PAIR */
+
+ /*
+ * At this point, we have snarfed all the bits in the
+@@ -398,7 +444,11 @@
+ * in manl instead for small subnormals. We also tack on the
+ * implicit normalization bit if appropriate.
+ */
++#ifdef LDBL_HEAD_TAIL_PAIR
++ *s = bits[i] | impnbit;
++#else /* LDBL_HEAD_TAIL_PAIR */
+ *s = u.bits.manh | u.bits.manl | impnbit;
++#endif /* LDBL_HEAD_TAIL_PAIR */
+
+ /* If ndigits < 0, we are expected to auto-size the precision. */
+ if (ndigits < 0) {
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http:www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include <sys/cdefs.h>
+#include <stdint.h>
+#include <strings.h>
+#include <float.h>
+#include <math.h>
+#include <alloca.h>
+
+#include "fpmath.h"
+
+#define BITS64 64
+#define DBL_BIAS (DBL_MAX_EXP - 1)
+#define DBL_SUBEXP (-DBL_BIAS + 1)
+#define LL_BITS (8 * sizeof(int64_t))
+#define LL_HIGHBIT (1LL << 63)
+
+__private_extern__ void
+_ldbl2array32dd(union IEEEl2bits u, uint32_t *a)
+{
+ int bit, shift, highbit;
+ uint64_t a64[2];
+ int64_t t64;
+
+ bzero(a64, 2 * sizeof(*a64));
+
+ switch (__fpclassifyd(u.d[0])) {
+ case FP_NORMAL:
+ a64[1] = (1LL << (LDBL_MANT_DIG - BITS64 - 1));
+ /* drop through */
+ case FP_SUBNORMAL:
+ a64[1] |= ((uint64_t)u.bits.manh >> (BITS64 - LDBL_MANL_SIZE));
+ a64[0] = ((uint64_t)u.bits.manh << LDBL_MANL_SIZE);
+ break;
+ default:
+ goto done;
+ }
+
+ switch (__fpclassifyd(u.d[1])) {
+ case FP_NORMAL:
+ bit = LDBL_MANT_DIG - (int)u.bits.exp + (int)u.bits.exp2 - 1;
+ t64 = (1LL << bit);
+ break;
+ case FP_SUBNORMAL:
+ bit = LDBL_MANT_DIG - (int)u.bits.exp;
+ t64 = 0;
+ break;
+ default:
+ goto done;
+ }
+ shift = LDBL_MANL_SIZE - bit - 1;
+ if (shift >= 0)
+ t64 |= (u.bits.manl >> shift);
+ else
+ t64 |= (u.bits.manl << (-shift));
+ highbit = ((a64[0] & LL_HIGHBIT) != 0);
+ if (u.bits.sign == u.bits.sign2) {
+ a64[0] += t64;
+ if (highbit && !(a64[0] & LL_HIGHBIT)) /* carry */
+ a64[1]++;
+ } else {
+ a64[0] -= t64;
+ if (!highbit && (a64[0] & LL_HIGHBIT)) /* borrow */
+ a64[1]--;
+ }
+
+ done:
+ a[0] = (uint32_t)a64[0];
+ a[1] = (uint32_t)(a64[0] >> 32);
+ a[2] = (uint32_t)a64[1];
+ a[3] = (uint32_t)(a64[1] >> 32);
+}
--- /dev/null
+--- _ldtoa.c.orig 2004-12-08 22:50:28.000000000 -0800
++++ _ldtoa.c 2004-12-08 22:52:58.000000000 -0800
+@@ -61,14 +61,34 @@
+ char *ret;
+ union IEEEl2bits u;
+ uint32_t bits[(LDBL_MANT_DIG + 31) / 32];
++#if defined(__ppc__) || defined(__ppc64__)
++ int type;
++#endif /* defined(__ppc__) || defined(__ppc64__) */
+
+ u.e = *ld;
++#if defined(__ppc__) || defined(__ppc64__)
++ /*
++ * Subnormal head-tail doubles don't seem to be converted correctly
++ * by gdtoa. So we multiply by 10^32 to make them normal then
++ * subtract 32 from the exponent later.
++ */
++ if ((type = __fpclassify(u.e)) == FP_NORMAL && __fpclassifyd(u.d[1]) == FP_SUBNORMAL)
++ type = FP_SUBNORMAL;
++ if (type == FP_SUBNORMAL)
++ u.e *= 1.0e32L;
++#endif /* defined(__ppc__) || defined(__ppc64__) */
+ *sign = u.bits.sign;
+ be = u.bits.exp - (LDBL_MAX_EXP - 1) - (LDBL_MANT_DIG - 1);
+ LDBL_TO_ARRAY32(u, bits);
+
++#if defined(__ppc__) || defined(__ppc64__)
++ switch (type) {
++ case FP_SUBNORMAL:
++#else /* !defined(__ppc__) && !defined(__ppc64__) */
+ switch (fpclassify(u.e)) {
++#endif /* defined(__ppc__) || defined(__ppc64__) */
+ case FP_NORMAL:
++ case FP_SUPERNORMAL:
+ kind = STRTOG_Normal;
+ #ifdef LDBL_IMPLICIT_NBIT
+ bits[LDBL_MANT_DIG / 32] |= 1 << ((LDBL_MANT_DIG - 1) % 32);
+@@ -77,12 +97,14 @@
+ case FP_ZERO:
+ kind = STRTOG_Zero;
+ break;
++#if !defined(__ppc__) && !defined(__ppc64__)
+ case FP_SUBNORMAL:
+ kind = STRTOG_Denormal;
+ #ifdef LDBL_IMPLICIT_NBIT
+ be++;
+ #endif
+ break;
++#endif /* !defined(__ppc__) && !defined(__ppc64__) */
+ case FP_INFINITE:
+ kind = STRTOG_Infinite;
+ break;
+@@ -96,5 +118,9 @@
+ ret = gdtoa(&fpi, be, (ULong *)bits, &kind, mode, ndigits, decpt, rve);
+ if (*decpt == -32768)
+ *decpt = INT_MAX;
++#if defined(__ppc__) || defined(__ppc64__)
++ else if (type == FP_SUBNORMAL)
++ *decpt -= 32;
++#endif /* defined(__ppc__) || defined(__ppc64__) */
+ return ret;
+ }
****************************************************************/
-/* Please send bug reports to
- David M. Gay
- Bell Laboratories, Room 2C-463
- 600 Mountain Avenue
- Murray Hill, NJ 07974-0636
- U.S.A.
- dmg@bell-labs.com
- */
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
#include "gdtoaimp.h"
****************************************************************/
-/* Please send bug reports to
- David M. Gay
- Bell Laboratories, Room 2C-463
- 600 Mountain Avenue
- Murray Hill, NJ 07974-0636
- U.S.A.
- dmg@bell-labs.com
- */
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
#include "gdtoaimp.h"
/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string.
*
* Inspired by "How to Print Floating-Point Numbers Accurately" by
- * Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 92-101].
+ * Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 112-126].
*
* Modifications:
* 1. Rather than iterating, we use a simple numeric overestimate
****************************************************************/
-/* Please send bug reports to
- David M. Gay
- Bell Laboratories, Room 2C-463
- 600 Mountain Avenue
- Murray Hill, NJ 07974-0636
- U.S.A.
- dmg@bell-labs.com
- */
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
#include "gdtoaimp.h"
/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string.
*
* Inspired by "How to Print Floating-Point Numbers Accurately" by
- * Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 92-101].
+ * Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 112-126].
*
* Modifications:
* 1. Rather than iterating, we use a simple numeric overestimate
****************************************************************/
-/* Please send bug reports to
- David M. Gay
- dmg@acm.org
- */
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
#include "gdtoaimp.h"
{
Bigint *b;
CONST unsigned char *decpt, *s0, *s, *s1;
- int esign, havedig, irv, k, n, nbits, up;
+ int esign, havedig, irv, k, n, nbits, up, zret;
ULong L, lostbits, *x;
Long e, e1;
#ifdef USE_LOCALE
s0 += havedig;
s = s0;
decpt = 0;
+ zret = 0;
+ e = 0;
if (!hexdig[*s]) {
- if (*s == decimalpoint) {
- decpt = ++s;
- if (!hexdig[*s])
- goto ret0;
- }
- else {
- ret0:
- *sp = (char*)s;
- return havedig ? STRTOG_Zero : STRTOG_NoNumber;
- }
+ zret = 1;
+ if (*s != decimalpoint)
+ goto pcheck;
+ decpt = ++s;
+ if (!hexdig[*s])
+ goto pcheck;
while(*s == '0')
s++;
+ if (hexdig[*s])
+ zret = 0;
havedig = 1;
- if (!hexdig[*s])
- goto ret0;
s0 = s;
}
while(hexdig[*s])
while(hexdig[*s])
s++;
}
- e = 0;
if (decpt)
e = -(((Long)(s-decpt)) << 2);
+ pcheck:
s1 = s;
switch(*s) {
case 'p':
e += e1;
}
*sp = (char*)s;
+ if (zret)
+ return havedig ? STRTOG_Zero : STRTOG_NoNumber;
n = s1 - s0 - 1;
for(k = 0; n > 7; n >>= 1)
k++;
--- /dev/null
+--- gdtoa-gethex.c.orig 2005-02-17 01:16:50.000000000 -0800
++++ gdtoa-gethex.c 2005-02-17 01:27:10.000000000 -0800
+@@ -29,6 +29,8 @@
+ /* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
+
++#include "xlocale_private.h"
++
+ #include "gdtoaimp.h"
+
+ #ifdef USE_LOCALE
+@@ -37,10 +39,10 @@
+
+ int
+ #ifdef KR_headers
+-gethex(sp, fpi, exp, bp, sign)
+- CONST char **sp; FPI *fpi; Long *exp; Bigint **bp; int sign;
++gethex(sp, fpi, exp, bp, sign, loc)
++ CONST char **sp; FPI *fpi; Long *exp; Bigint **bp; int sign; locale_t loc;
+ #else
+-gethex( CONST char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign)
++gethex( CONST char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign, locale_t loc)
+ #endif
+ {
+ Bigint *b;
+@@ -49,7 +51,10 @@
+ ULong L, lostbits, *x;
+ Long e, e1;
+ #ifdef USE_LOCALE
+- unsigned char decimalpoint = *localeconv()->decimal_point;
++ unsigned char decimalpoint;
++
++ NORMALIZE_LOCALE(loc);
++ decimalpoint = *localeconv_l(loc)->decimal_point;
+ #else
+ #define decimalpoint '.'
+ #endif
****************************************************************/
-/* Please send bug reports to
- David M. Gay
- Bell Laboratories, Room 2C-463
- 600 Mountain Avenue
- Murray Hill, NJ 07974-0636
- U.S.A.
- dmg@bell-labs.com
- */
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
#include "gdtoaimp.h"
****************************************************************/
-/* Please send bug reports to
- David M. Gay
- Bell Laboratories, Room 2C-463
- 600 Mountain Avenue
- Murray Hill, NJ 07974-0636
- U.S.A.
- dmg@bell-labs.com
- */
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
#include "gdtoaimp.h"
****************************************************************/
-/* Please send bug reports to
- David M. Gay
- Bell Laboratories, Room 2C-463
- 600 Mountain Avenue
- Murray Hill, NJ 07974-0636
- U.S.A.
- dmg@bell-labs.com
- */
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
#include "gdtoaimp.h"
****************************************************************/
-/* Please send bug reports to
- David M. Gay
- Bell Laboratories, Room 2C-463
- 600 Mountain Avenue
- Murray Hill, NJ 07974-0636
- U.S.A.
- dmg@bell-labs.com
- */
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
#include "gdtoaimp.h"
if (!(x & 1)) {
k++;
x >>= 1;
- if (!x & 1)
+ if (!x)
return 32;
}
*y = x;
}
int
-hi0bits
+hi0bits_D2A
#ifdef KR_headers
(x) register ULong x;
#else
#endif
{
Bigint *b;
- int de, i, k;
+#ifndef Sudden_Underflow
+ int i;
+#endif
+ int de, k;
ULong *x, y, z;
#ifdef VAX
ULong d0, d1;
}
else
x[0] = y;
- i = b->wds = (x[1] = z) !=0 ? 2 : 1;
+#ifndef Sudden_Underflow
+ i =
+#endif
+ b->wds = (x[1] = z) !=0 ? 2 : 1;
}
else {
#ifdef DEBUG
#endif
k = lo0bits(&z);
x[0] = z;
- i = b->wds = 1;
+#ifndef Sudden_Underflow
+ i =
+#endif
+ b->wds = 1;
k += 32;
}
#else
****************************************************************/
-/* Please send bug reports to
- David M. Gay
- Bell Laboratories, Room 2C-463
- 600 Mountain Avenue
- Murray Hill, NJ 07974-0636
- U.S.A.
- dmg@bell-labs.com
- */
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
#include "gdtoaimp.h"
****************************************************************/
-/* Please send bug reports to
- David M. Gay
- Bell Laboratories, Room 2C-463
- 600 Mountain Avenue
- Murray Hill, NJ 07974-0636
- U.S.A.
- dmg@bell-labs.com
- */
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
#include "gdtoaimp.h"
****************************************************************/
-/* Please send bug reports to
- David M. Gay
- dmg@acm.org
- */
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
#include "gdtoaimp.h"
#ifdef Avoid_Underflow
int scale;
#endif
- int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign,
+ int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, decpt, dsign,
e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign;
CONST char *s, *s0, *s1;
double aadj, aadj1, adj, rv, rv0;
int rounding;
#endif
- sign = nz0 = nz = 0;
+ sign = nz0 = nz = decpt = 0;
dval(rv) = 0.;
for(s = s00;;s++) switch(*s) {
case '-':
if (c == '.')
#endif
{
+ decpt = 1;
c = *++s;
if (!nd) {
for(; c == '0'; c = *++s)
ULong bits[2];
static FPI fpinan = /* only 52 explicit bits */
{ 52, 1-1023-53+1, 2046-1023-53+1, 1, SI };
- switch(c) {
+ if (!decpt)
+ switch(c) {
case 'i':
case 'I':
if (match(&s,"nf")) {
word1(rv) = bits[0];
}
else {
+#endif
word0(rv) = NAN_WORD0;
word1(rv) = NAN_WORD1;
+#ifndef No_Hex_NaN
}
#endif
goto ret;
--- /dev/null
+--- gdtoa-strtod.c.orig 2005-01-20 20:12:37.000000000 -0800
++++ gdtoa-strtod.c 2005-02-17 01:31:26.000000000 -0800
+@@ -29,6 +29,8 @@
+ /* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
+
++#include "xlocale_private.h"
++
+ #include "gdtoaimp.h"
+
+ #ifdef USE_LOCALE
+@@ -56,11 +58,11 @@
+ #endif
+
+ double
+-strtod
++strtod_l
+ #ifdef KR_headers
+- (s00, se) CONST char *s00; char **se;
++ (s00, se, loc) CONST char *s00; char **se; locale_t loc;
+ #else
+- (CONST char *s00, char **se)
++ (CONST char *s00, char **se, locale_t loc)
+ #endif
+ {
+ #ifdef Avoid_Underflow
+@@ -112,7 +114,7 @@
+ switch(s[1]) {
+ case 'x':
+ case 'X':
+- switch((i = gethex(&s, &fpi, &exp, &bb, sign)) & STRTOG_Retmask) {
++ switch((i = gethex(&s, &fpi, &exp, &bb, sign, loc)) & STRTOG_Retmask) {
+ case STRTOG_NoNumber:
+ s = s00;
+ sign = 0;
+@@ -142,8 +144,9 @@
+ else if (nd < 16)
+ z = 10*z + c - '0';
+ nd0 = nd;
++ NORMALIZE_LOCALE(loc);
+ #ifdef USE_LOCALE
+- if (c == *localeconv()->decimal_point)
++ if (c == *localeconv_l(loc)->decimal_point)
+ #else
+ if (c == '.')
+ #endif
+@@ -966,3 +969,13 @@
+ return sign ? -dval(rv) : dval(rv);
+ }
+
++ double
++strtod
++#ifdef KR_headers
++ (s00, se) CONST char *s00; char **se;
++#else
++ (CONST char *s00, char **se)
++#endif
++{
++ return strtod_l(s00, se, __current_locale());
++}
****************************************************************/
-/* Please send bug reports to
- David M. Gay
- dmg@acm.org
- */
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
#include "gdtoaimp.h"
inex = STRTOG_Inexhi;
b = increment(b);
if ( (j = nb & kmask) !=0)
- j = 32 - j;
+ j = ULbits - j;
if (hi0bits(b->x[b->wds - 1]) != j) {
if (!lostbits)
lostbits = b->x[0] & 1;
#endif
{
int abe, abits, asub;
- int bb0, bb2, bb5, bbe, bd2, bd5, bbbits, bs2;
- int c, denorm, dsign, e, e1, e2, emin, esign, finished, i, inex, irv;
+ int bb0, bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, decpt, denorm;
+ int dsign, e, e1, e2, emin, esign, finished, i, inex, irv;
int j, k, nbits, nd, nd0, nf, nz, nz0, rd, rvbits, rve, rve1, sign;
int sudden_underflow;
CONST char *s, *s0, *s1;
sudden_underflow = fpi->sudden_underflow;
s0 = s;
y = z = 0;
- for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
+ for(decpt = nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
if (nd < 9)
y = 10*y + c - '0';
else if (nd < 16)
if (c == '.')
#endif
{
+ decpt = 1;
c = *++s;
if (!nd) {
for(; c == '0'; c = *++s)
if (!nz && !nz0) {
#ifdef INFNAN_CHECK
/* Check for Nan and Infinity */
- switch(c) {
+ if (!decpt)
+ switch(c) {
case 'i':
case 'I':
if (match(&s,"nf")) {
dval(rv) *= tinytens[j];
}
}
-
+#ifdef IBM
+ /* e2 is a correction to the (base 2) exponent of the return
+ * value, reflecting adjustments above to avoid overflow in the
+ * native arithmetic. For native IBM (base 16) arithmetic, we
+ * must multiply e2 by 4 to change from base 16 to 2.
+ */
+ e2 <<= 2;
+#endif
rvb = d2b(dval(rv), &rve, &rvbits); /* rv = rvb * 2^rve */
rve += e2;
if ((j = rvbits - nbits) > 0) {
break;
if (dsign) {
rvb = increment(rvb);
- if ( (j = rvbits >> kshift) !=0)
- j = 32 - j;
+ if ( (j = rvbits & kmask) !=0)
+ j = ULbits - j;
if (hi0bits(rvb->x[(rvb->wds - 1) >> kshift])
!= j)
rvbits++;
Bfree(bs);
Bfree(delta);
}
- if (!denorm && rvbits < nbits) {
- j = nbits - rvbits;
- rvb = lshift(rvb, j);
+ if (!denorm && (j = nbits - rvbits)) {
+ if (j > 0)
+ rvb = lshift(rvb, j);
+ else
+ rshift(rvb, -j);
rve -= j;
}
*exp = rve;
--- /dev/null
+--- gdtoa-strtodg.c.orig 2005-01-20 20:12:37.000000000 -0800
++++ gdtoa-strtodg.c 2005-02-17 01:32:24.000000000 -0800
+@@ -29,6 +29,8 @@
+ /* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
+
++#include "xlocale_private.h"
++
+ #include "gdtoaimp.h"
+
+ #ifdef USE_LOCALE
+@@ -316,10 +318,10 @@
+ int
+ strtodg
+ #ifdef KR_headers
+- (s00, se, fpi, exp, bits)
+- CONST char *s00; char **se; FPI *fpi; Long *exp; ULong *bits;
++ (s00, se, fpi, exp, bits, loc)
++ CONST char *s00; char **se; FPI *fpi; Long *exp; ULong *bits; locale_t loc;
+ #else
+- (CONST char *s00, char **se, FPI *fpi, Long *exp, ULong *bits)
++ (CONST char *s00, char **se, FPI *fpi, Long *exp, ULong *bits, locale_t loc)
+ #endif
+ {
+ int abe, abits, asub;
+@@ -367,7 +369,7 @@
+ switch(s[1]) {
+ case 'x':
+ case 'X':
+- irv = gethex(&s, fpi, exp, &rvb, sign);
++ irv = gethex(&s, fpi, exp, &rvb, sign, loc);
+ if (irv == STRTOG_NoNumber) {
+ s = s00;
+ sign = 0;
+@@ -389,8 +391,9 @@
+ else if (nd < 16)
+ z = 10*z + c - '0';
+ nd0 = nd;
++ NORMALIZE_LOCALE(loc);
+ #ifdef USE_LOCALE
+- if (c == *localeconv()->decimal_point)
++ if (c == *localeconv_l(loc)->decimal_point)
+ #else
+ if (c == '.')
+ #endif
+@@ -676,6 +679,9 @@
+ rvb->x[0] = 0;
+ *exp = emin;
+ irv = STRTOG_Underflow | STRTOG_Inexlo;
++#ifndef NO_ERRNO
++ errno = ERANGE;
++#endif
+ goto ret;
+ }
+ rvb->x[0] = rvb->wds = rvbits = 1;
****************************************************************/
-/* Please send bug reports to
- David M. Gay
- Bell Laboratories, Room 2C-463
- 600 Mountain Avenue
- Murray Hill, NJ 07974-0636
- U.S.A.
- dmg@bell-labs.com
- */
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
#include "gdtoaimp.h"
strtof(CONST char *s, char **sp)
#endif
{
-#ifdef Sudden_Underflow
- static FPI fpi = { 24, 1-127-24+1, 254-127-24+1, 1, 1 };
-#else
- static FPI fpi = { 24, 1-127-24+1, 254-127-24+1, 1, 0 };
-#endif
+ static FPI fpi = { 24, 1-127-24+1, 254-127-24+1, 1, SI };
ULong bits[1];
Long exp;
int k;
break;
case STRTOG_NaN:
- u.L[0] = 0x7fffffff;
+ u.L[0] = f_QNAN;
}
if (k & STRTOG_Neg)
u.L[0] |= 0x80000000L;
--- /dev/null
+--- gdtoa-strtof.c.orig 2005-01-20 20:12:37.000000000 -0800
++++ gdtoa-strtof.c 2005-02-17 12:49:28.000000000 -0800
+@@ -29,13 +29,15 @@
+ /* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
+
++#include "xlocale_private.h"
++
+ #include "gdtoaimp.h"
+
+ float
+ #ifdef KR_headers
+-strtof(s, sp) CONST char *s; char **sp;
++strtof_l(s, sp, loc) CONST char *s; char **sp; locale_t loc;
+ #else
+-strtof(CONST char *s, char **sp)
++strtof_l(CONST char *s, char **sp, locale_t loc)
+ #endif
+ {
+ static FPI fpi = { 24, 1-127-24+1, 254-127-24+1, 1, SI };
+@@ -44,7 +46,8 @@
+ int k;
+ union { ULong L[1]; float f; } u;
+
+- k = strtodg(s, sp, &fpi, &exp, bits);
++ NORMALIZE_LOCALE(loc);
++ k = strtodg(s, sp, &fpi, &exp, bits, loc);
+ switch(k & STRTOG_Retmask) {
+ case STRTOG_NoNumber:
+ case STRTOG_Zero:
+@@ -71,3 +74,13 @@
+ u.L[0] |= 0x80000000L;
+ return u.f;
+ }
++
++ float
++#ifdef KR_headers
++strtof(s, sp) CONST char *s; char **sp;
++#else
++strtof(CONST char *s, char **sp)
++#endif
++{
++ return strtof_l(s, sp, __current_locale());
++}
--- /dev/null
+/****************************************************************
+
+The author of this software is David M. Gay.
+
+Copyright (C) 1998, 2000 by Lucent Technologies
+All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby
+granted, provided that the above copyright notice appear in all
+copies and that both that the copyright notice and this
+permission notice and warranty disclaimer appear in supporting
+documentation, and that the name of Lucent or any of its entities
+not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior
+permission.
+
+LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
+IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
+
+****************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
+
+#include "gdtoaimp.h"
+
+ int
+#ifdef KR_headers
+strtopdd(s, sp, dd) CONST char *s; char **sp; double *dd;
+#else
+strtopdd(CONST char *s, char **sp, double *dd)
+#endif
+{
+#ifdef Sudden_Underflow
+ static FPI fpi = { 106, 1-1023, 2046-1023-106+1, 1, 1 };
+#else
+ static FPI fpi = { 106, 1-1023-53+1, 2046-1023-106+1, 1, 0 };
+#endif
+ ULong bits[4];
+ Long exp;
+ int i, j, rv;
+ typedef union {
+ double d[2];
+ ULong L[4];
+ } U;
+ U *u;
+
+ rv = strtodg(s, sp, &fpi, &exp, bits);
+ u = (U*)dd;
+ switch(rv & STRTOG_Retmask) {
+ case STRTOG_NoNumber:
+ case STRTOG_Zero:
+ u->d[0] = u->d[1] = 0.;
+ break;
+
+ case STRTOG_Normal:
+ u->L[_1] = (bits[1] >> 21 | bits[2] << 11) & 0xffffffffL;
+ u->L[_0] = bits[2] >> 21 | bits[3] << 11 & 0xfffff
+ | exp + 0x3ff + 105 << 20;
+ exp += 0x3ff + 52;
+ if (bits[1] &= 0x1fffff) {
+ i = hi0bits(bits[1]) - 11;
+ if (i >= exp) {
+ i = exp - 1;
+ exp = 0;
+ }
+ else
+ exp -= i;
+ if (i > 0) {
+ bits[1] = bits[1] << i | bits[0] >> 32-i;
+ bits[0] = bits[0] << i & 0xffffffffL;
+ }
+ }
+ else if (bits[0]) {
+ i = hi0bits(bits[0]) + 21;
+ if (i >= exp) {
+ i = exp - 1;
+ exp = 0;
+ }
+ else
+ exp -= i;
+ if (i < 32) {
+ bits[1] = bits[0] >> 32 - i;
+ bits[0] = bits[0] << i & 0xffffffffL;
+ }
+ else {
+ bits[1] = bits[0] << i - 32;
+ bits[0] = 0;
+ }
+ }
+ else {
+ u->L[2] = u->L[3] = 0;
+ break;
+ }
+ u->L[2+_1] = bits[0];
+ u->L[2+_0] = bits[1] & 0xfffff | exp << 20;
+ break;
+
+ case STRTOG_Denormal:
+ if (bits[3])
+ goto nearly_normal;
+ if (bits[2])
+ goto partly_normal;
+ if (bits[1] & 0xffe00000)
+ goto hardly_normal;
+ /* completely denormal */
+ u->L[2] = u->L[3] = 0;
+ u->L[_1] = bits[0];
+ u->L[_0] = bits[1];
+ break;
+
+ nearly_normal:
+ i = hi0bits(bits[3]) - 11; /* i >= 12 */
+ j = 32 - i;
+ u->L[_0] = (bits[3] << i | bits[2] >> j) & 0xfffff
+ | 65 - i << 20;
+ u->L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL;
+ u->L[2+_0] = bits[1] & (1L << j) - 1;
+ u->L[2+_1] = bits[0];
+ break;
+
+ partly_normal:
+ i = hi0bits(bits[2]) - 11;
+ if (i < 0) {
+ j = -i;
+ i += 32;
+ u->L[_0] = bits[2] >> j & 0xfffff | (33 + j) << 20;
+ u->L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL;
+ u->L[2+_0] = bits[1] & (1L << j) - 1;
+ u->L[2+_1] = bits[0];
+ break;
+ }
+ if (i == 0) {
+ u->L[_0] = bits[2] & 0xfffff | 33 << 20;
+ u->L[_1] = bits[1];
+ u->L[2+_0] = 0;
+ u->L[2+_1] = bits[0];
+ break;
+ }
+ j = 32 - i;
+ u->L[_0] = (bits[2] << i | bits[1] >> j) & 0xfffff
+ | j + 1 << 20;
+ u->L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL;
+ u->L[2+_0] = 0;
+ u->L[2+_1] = bits[0] & (1L << j) - 1;
+ break;
+
+ hardly_normal:
+ j = 11 - hi0bits(bits[1]);
+ i = 32 - j;
+ u->L[_0] = bits[1] >> j & 0xfffff | j + 1 << 20;
+ u->L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL;
+ u->L[2+_0] = 0;
+ u->L[2+_1] = bits[0] & (1L << j) - 1;
+ break;
+
+ case STRTOG_Infinite:
+ u->L[_0] = u->L[2+_0] = 0x7ff00000;
+ u->L[_1] = u->L[2+_1] = 0;
+ break;
+
+ case STRTOG_NaN:
+ u->L[0] = u->L[2] = d_QNAN0;
+ u->L[1] = u->L[3] = d_QNAN1;
+ }
+ if (rv & STRTOG_Neg) {
+ u->L[ _0] |= 0x80000000L;
+ u->L[2+_0] |= 0x80000000L;
+ }
+ return rv;
+ }
--- /dev/null
+--- gdtoa-strtopdd.c.orig 2005-01-20 20:12:37.000000000 -0800
++++ gdtoa-strtopdd.c 2005-02-17 01:34:59.000000000 -0800
+@@ -29,13 +29,25 @@
+ /* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
+
++#include "xlocale_private.h"
++
+ #include "gdtoaimp.h"
+
++#ifdef __APPLE__
++/*
++ * IEEE specifies that the most significant (head) double is required to
++ * be equal to the long double rounded to the nearest double, so that means
++ * the tail double might be the opposite sign as the head. We can do this
++ * adding (long double)0 to the number, which will fix it up.
++ */
++#define fixLDBL(x) ((x) += 0.L)
++#endif /* __APPLE__ */
++
+ int
+ #ifdef KR_headers
+-strtopdd(s, sp, dd) CONST char *s; char **sp; double *dd;
++strtopdd(s, sp, dd, loc) CONST char *s; char **sp; double *dd; locale_t loc;
+ #else
+-strtopdd(CONST char *s, char **sp, double *dd)
++strtopdd(CONST char *s, char **sp, double *dd, locale_t loc)
+ #endif
+ {
+ #ifdef Sudden_Underflow
+@@ -49,10 +61,13 @@
+ typedef union {
+ double d[2];
+ ULong L[4];
++#ifdef __APPLE__
++ long double ld;
++#endif /* __APPLE__ */
+ } U;
+ U *u;
+
+- rv = strtodg(s, sp, &fpi, &exp, bits);
++ rv = strtodg(s, sp, &fpi, &exp, bits, loc);
+ u = (U*)dd;
+ switch(rv & STRTOG_Retmask) {
+ case STRTOG_NoNumber:
+@@ -101,6 +116,9 @@
+ }
+ u->L[2+_1] = bits[0];
+ u->L[2+_0] = bits[1] & 0xfffff | exp << 20;
++#ifdef __APPLE__
++ fixLDBL(u->ld);
++#endif /* __APPLE__ */
+ break;
+
+ case STRTOG_Denormal:
+@@ -124,6 +142,9 @@
+ u->L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL;
+ u->L[2+_0] = bits[1] & (1L << j) - 1;
+ u->L[2+_1] = bits[0];
++#ifdef __APPLE__
++ fixLDBL(u->ld);
++#endif /* __APPLE__ */
+ break;
+
+ partly_normal:
+@@ -135,6 +156,9 @@
+ u->L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL;
+ u->L[2+_0] = bits[1] & (1L << j) - 1;
+ u->L[2+_1] = bits[0];
++#ifdef __APPLE__
++ fixLDBL(u->ld);
++#endif /* __APPLE__ */
+ break;
+ }
+ if (i == 0) {
+@@ -142,6 +166,9 @@
+ u->L[_1] = bits[1];
+ u->L[2+_0] = 0;
+ u->L[2+_1] = bits[0];
++#ifdef __APPLE__
++ fixLDBL(u->ld);
++#endif /* __APPLE__ */
+ break;
+ }
+ j = 32 - i;
+@@ -150,6 +177,9 @@
+ u->L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL;
+ u->L[2+_0] = 0;
+ u->L[2+_1] = bits[0] & (1L << j) - 1;
++#ifdef __APPLE__
++ fixLDBL(u->ld);
++#endif /* __APPLE__ */
+ break;
+
+ hardly_normal:
+@@ -159,20 +189,38 @@
+ u->L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL;
+ u->L[2+_0] = 0;
+ u->L[2+_1] = bits[0] & (1L << j) - 1;
++#ifdef __APPLE__
++ fixLDBL(u->ld);
++#endif /* __APPLE__ */
+ break;
+
+ case STRTOG_Infinite:
++#ifdef __APPLE__
++ u->L[_0] = 0x7ff00000;
++ u->L[_1] = u->L[2+_0] = u->L[2+_1] = 0;
++#else /* __APPLE__ */
+ u->L[_0] = u->L[2+_0] = 0x7ff00000;
+ u->L[_1] = u->L[2+_1] = 0;
++#endif /* __APPLE__ */
+ break;
+
+ case STRTOG_NaN:
++#ifdef __APPLE__
++ u->L[_0] = 0x7fffffff;
++ u->L[_1] = (ULong)-1;
++ u->L[2+_0] = u->L[2+_1] = 0;
++#else /* __APPLE__ */
+ u->L[0] = u->L[2] = d_QNAN0;
+ u->L[1] = u->L[3] = d_QNAN1;
++#endif /* __APPLE__ */
+ }
+ if (rv & STRTOG_Neg) {
+ u->L[ _0] |= 0x80000000L;
++#ifdef __APPLE__
++ u->L[2+_0] ^= 0x80000000L;
++#else /* __APPLE__ */
+ u->L[2+_0] |= 0x80000000L;
++#endif /* __APPLE__ */
+ }
+ return rv;
+ }
****************************************************************/
-/* Please send bug reports to
- David M. Gay
- Bell Laboratories, Room 2C-463
- 600 Mountain Avenue
- Murray Hill, NJ 07974-0636
- U.S.A.
- dmg@bell-labs.com
- */
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
#include "gdtoaimp.h"
break;
case STRTOG_NaN:
- L[_0] = 0x7fffffff;
- L[_1] = (ULong)-1;
+ L[0] = d_QNAN0;
+ L[1] = d_QNAN1;
}
if (k & STRTOG_Neg)
L[_0] |= 0x80000000L;
--- /dev/null
+--- gdtoa-strtord.c.orig 2005-01-20 20:12:37.000000000 -0800
++++ gdtoa-strtord.c 2005-02-17 13:06:38.000000000 -0800
+@@ -67,27 +67,3 @@
+ if (k & STRTOG_Neg)
+ L[_0] |= 0x80000000L;
+ }
+-
+- int
+-#ifdef KR_headers
+-strtord(s, sp, rounding, d) CONST char *s; char **sp; int rounding; double *d;
+-#else
+-strtord(CONST char *s, char **sp, int rounding, double *d)
+-#endif
+-{
+- static FPI fpi0 = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI };
+- FPI *fpi, fpi1;
+- ULong bits[2];
+- Long exp;
+- int k;
+-
+- fpi = &fpi0;
+- if (rounding != FPI_Round_near) {
+- fpi1 = fpi0;
+- fpi1.rounding = rounding;
+- fpi = &fpi1;
+- }
+- k = strtodg(s, sp, fpi, &exp, bits);
+- ULtod((ULong*)d, bits, exp, k);
+- return k;
+- }
****************************************************************/
-/* Please send bug reports to
- David M. Gay
- Bell Laboratories, Room 2C-463
- 600 Mountain Avenue
- Murray Hill, NJ 07974-0636
- U.S.A.
- dmg@bell-labs.com
- */
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
#include "gdtoaimp.h"
****************************************************************/
-/* Please send bug reports to
- David M. Gay
- Bell Laboratories, Room 2C-463
- 600 Mountain Avenue
- Murray Hill, NJ 07974-0636
- U.S.A.
- dmg@bell-labs.com
- */
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
#include "gdtoaimp.h"
****************************************************************/
-/* Please send bug reports to
- David M. Gay
- Bell Laboratories, Room 2C-463
- 600 Mountain Avenue
- Murray Hill, NJ 07974-0636
- U.S.A.
- dmg@bell-labs.com
- */
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
#ifndef GDTOA_H_INCLUDED
#define GDTOA_H_INCLUDED
****************************************************************/
-/* Please send bug reports to
- David M. Gay
- Bell Laboratories, Room 2C-463
- 600 Mountain Avenue
- Murray Hill, NJ 07974-0636
- U.S.A.
- dmg@bell-labs.com
- */
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
#include "gdtoaimp.h"
strtopx(CONST char *s, char **sp, void *V)
#endif
{
-#ifdef Sudden_Underflow
- static FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, 1 };
-#else
- static FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, 0 };
-#endif
+ static FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI };
ULong bits[2];
Long exp;
int k;
L[0] = L[1] = L[2] = L[3] = L[4] = 0;
break;
- case STRTOG_Normal:
case STRTOG_Denormal:
+ L[_0] = 0;
+ goto normal_bits;
+
+ case STRTOG_Normal:
case STRTOG_NaNbits:
+ L[_0] = exp + 0x3fff + 63;
+ normal_bits:
L[_4] = (UShort)bits[0];
L[_3] = (UShort)(bits[0] >> 16);
L[_2] = (UShort)bits[1];
L[_1] = (UShort)(bits[1] >> 16);
- L[_0] = exp + 0x3fff + 63;
break;
case STRTOG_Infinite:
break;
case STRTOG_NaN:
- L[_0] = 0x7fff;
- L[_1] = L[_2] = L[_3] = L[_4] = (UShort)-1;
+ L[0] = ldus_QNAN0;
+ L[1] = ldus_QNAN1;
+ L[2] = ldus_QNAN2;
+ L[3] = ldus_QNAN3;
+ L[4] = ldus_QNAN4;
}
if (k & STRTOG_Neg)
L[_0] |= 0x8000;
--- /dev/null
+--- gdtoa_strtopx.c.orig 2005-01-20 20:12:37.000000000 -0800
++++ gdtoa_strtopx.c 2005-02-17 01:54:02.000000000 -0800
+@@ -29,6 +29,8 @@
+ /* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
+
++#include "xlocale_private.h"
++
+ #include "gdtoaimp.h"
+
+ #undef _0
+@@ -53,9 +55,9 @@
+
+ int
+ #ifdef KR_headers
+-strtopx(s, sp, V) CONST char *s; char **sp; void *V;
++strtopx(s, sp, V, loc) CONST char *s; char **sp; void *V; locale_t loc;
+ #else
+-strtopx(CONST char *s, char **sp, void *V)
++strtopx(CONST char *s, char **sp, void *V, locale_t loc)
+ #endif
+ {
+ static FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI };
+@@ -64,7 +66,7 @@
+ int k;
+ UShort *L = (UShort*)V;
+
+- k = strtodg(s, sp, &fpi, &exp, bits);
++ k = strtodg(s, sp, &fpi, &exp, bits, loc);
+ switch(k & STRTOG_Retmask) {
+ case STRTOG_NoNumber:
+ case STRTOG_Zero:
****************************************************************/
-/* $FreeBSD: src/contrib/gdtoa/gdtoaimp.h,v 1.5 2003/04/09 06:04:35 das Exp $ */
-
/* This is a variation on dtoa.c that converts arbitary binary
floating-point formats to and from decimal notation. It uses
double-precision arithmetic internally, so there are still
double-precision arithmetic (any of IEEE, VAX D_floating,
or IBM mainframe arithmetic).
- Please send bug reports to
- David M. Gay
- Bell Laboratories, Room 2C-463
- 600 Mountain Avenue
- Murray Hill, NJ 07974-0636
- U.S.A.
- dmg@bell-labs.com
+ Please send bug reports to David M. Gay (dmg at acm dot org,
+ with " at " changed at "@" and " dot " changed to ".").
*/
/* On a machine with IEEE extended-precision registers, it is
* biased rounding (add half and chop).
*
* Inspired loosely by William D. Clinger's paper "How to Read Floating
- * Point Numbers Accurately" [Proc. ACM SIGPLAN '90, pp. 92-101].
+ * Point Numbers Accurately" [Proc. ACM SIGPLAN '90, pp. 112-126].
*
* Modifications:
*
* 8-byte pointers, PRIVATE_MEM >= 7400 appears to suffice; with
* 4-byte pointers, PRIVATE_MEM >= 7112 appears adequate.
* #define INFNAN_CHECK on IEEE systems to cause strtod to check for
- * Infinity and NaN (case insensitively). On some systems (e.g.,
- * some HP systems), it may be necessary to #define NAN_WORD0
- * appropriately -- to the most significant word of a quiet NaN.
- * (On HP Series 700/800 machines, -DNAN_WORD0=0x7ff40000 works.)
+ * Infinity and NaN (case insensitively).
* When INFNAN_CHECK is #defined and No_Hex_NaN is not #defined,
* strtodg also accepts (case insensitively) strings of the form
* NaN(x), where x is a string of hexadecimal digits and spaces;
#ifndef GDTOAIMP_H_INCLUDED
#define GDTOAIMP_H_INCLUDED
#include "gdtoa.h"
+#include "gd_qnan.h"
#ifdef DEBUG
#include "stdio.h"
#define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);}
#endif
-#include "limits.h"
#include "stdlib.h"
#include "string.h"
-#include "libc_private.h"
-#include "spinlock.h"
#ifdef KR_headers
#define Char char
#define MALLOC malloc
#endif
-#define INFNAN_CHECK
-#define USE_LOCALE
-
#undef IEEE_Arith
#undef Avoid_Underflow
#ifdef IEEE_MC68k
#define ALL_ON 0xffff
#endif
-#define MULTIPLE_THREADS
-extern spinlock_t __gdtoa_locks[2];
-#define ACQUIRE_DTOA_LOCK(n) do { \
- if (__isthreaded) \
- _SPINLOCK(&__gdtoa_locks[n]); \
-} while(0)
-#define FREE_DTOA_LOCK(n) do { \
- if (__isthreaded) \
- _SPINUNLOCK(&__gdtoa_locks[n]); \
-} while(0)
+#ifndef MULTIPLE_THREADS
+#define ACQUIRE_DTOA_LOCK(n) /*nothing*/
+#define FREE_DTOA_LOCK(n) /*nothing*/
+#endif
#define Kmax 15
#define Bcopy(x,y) memcpy(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int))
#endif /* NO_STRING_H */
-/*
- * Paranoia: Protect exported symbols, including ones in files we don't
- * compile right now. The standard strtof and strtod survive.
- */
-#define dtoa __dtoa
-#define gdtoa __gdtoa
-#define freedtoa __freedtoa
-#define strtodg __strtodg
-#define g_ddfmt __g_ddfmt
-#define g_dfmt __g_dfmt
-#define g_ffmt __g_ffmt
-#define g_Qfmt __g_Qfmt
-#define g_xfmt __g_xfmt
-#define g_xLfmt __g_xLfmt
-#define strtoId __strtoId
-#define strtoIdd __strtoIdd
-#define strtoIf __strtoIf
-#define strtoIQ __strtoIQ
-#define strtoIx __strtoIx
-#define strtoIxL __strtoIxL
-#define strtord __strtord
-#define strtordd __strtordd
-#define strtorf __strtorf
-#define strtorQ __strtorQ
-#define strtorx __strtorx
-#define strtorxL __strtorxL
-#define strtodI __strtodI
-#define strtopd __strtopd
-#define strtopdd __strtopdd
-#define strtopf __strtopf
-#define strtopQ __strtopQ
-#define strtopx __strtopx
-#define strtopxL __strtopxL
-
-/* Protect gdtoa-internal symbols */
-#define Balloc __Balloc_D2A
-#define Bfree __Bfree_D2A
-#define ULtoQ __ULtoQ_D2A
-#define ULtof __ULtof_D2A
-#define ULtod __ULtod_D2A
-#define ULtodd __ULtodd_D2A
-#define ULtox __ULtox_D2A
-#define ULtoxL __ULtoxL_D2A
-#define any_on __any_on_D2A
-#define b2d __b2d_D2A
-#define bigtens __bigtens_D2A
-#define cmp __cmp_D2A
-#define copybits __copybits_D2A
-#define d2b __d2b_D2A
-#define decrement __decrement_D2A
-#define diff __diff_D2A
-#define dtoa_result __dtoa_result_D2A
-#define g__fmt __g__fmt_D2A
-#define gethex __gethex_D2A
-#define hexdig __hexdig_D2A
-#define hexdig_init_D2A __hexdig_init_D2A
-#define hexnan __hexnan_D2A
-#define hi0bits __hi0bits_D2A
-#define i2b __i2b_D2A
-#define increment __increment_D2A
-#define lo0bits __lo0bits_D2A
-#define lshift __lshift_D2A
-#define match __match_D2A
-#define mult __mult_D2A
-#define multadd __multadd_D2A
-#define nrv_alloc __nrv_alloc_D2A
-#define pow5mult __pow5mult_D2A
-#define quorem __quorem_D2A
-#define ratio __ratio_D2A
-#define rshift __rshift_D2A
-#define rv_alloc __rv_alloc_D2A
-#define s2b __s2b_D2A
-#define set_ones __set_ones_D2A
-#define strcp __strcp_D2A
-#define strcp_D2A __strcp_D2A
-#define strtoIg __strtoIg_D2A
-#define sum __sum_D2A
-#define tens __tens_D2A
-#define tinytens __tinytens_D2A
-#define tinytens __tinytens_D2A
-#define trailz __trailz_D2A
-#define ulp __ulp_D2A
+#define Balloc Balloc_D2A
+#define Bfree Bfree_D2A
+#define ULtoQ ULtoQ_D2A
+#define ULtof ULtof_D2A
+#define ULtod ULtod_D2A
+#define ULtodd ULtodd_D2A
+#define ULtox ULtox_D2A
+#define ULtoxL ULtoxL_D2A
+#define any_on any_on_D2A
+#define b2d b2d_D2A
+#define bigtens bigtens_D2A
+#define cmp cmp_D2A
+#define copybits copybits_D2A
+#define d2b d2b_D2A
+#define decrement decrement_D2A
+#define diff diff_D2A
+#define dtoa_result dtoa_result_D2A
+#define g__fmt g__fmt_D2A
+#define gethex gethex_D2A
+#define hexdig hexdig_D2A
+#define hexnan hexnan_D2A
+#define hi0bits(x) hi0bits_D2A((ULong)(x))
+#define i2b i2b_D2A
+#define increment increment_D2A
+#define lo0bits lo0bits_D2A
+#define lshift lshift_D2A
+#define match match_D2A
+#define mult mult_D2A
+#define multadd multadd_D2A
+#define nrv_alloc nrv_alloc_D2A
+#define pow5mult pow5mult_D2A
+#define quorem quorem_D2A
+#define ratio ratio_D2A
+#define rshift rshift_D2A
+#define rv_alloc rv_alloc_D2A
+#define s2b s2b_D2A
+#define set_ones set_ones_D2A
+#define strcp strcp_D2A
+#define strtoIg strtoIg_D2A
+#define sum sum_D2A
+#define tens tens_D2A
+#define tinytens tinytens_D2A
+#define tinytens tinytens_D2A
+#define trailz trailz_D2A
+#define ulp ulp_D2A
extern char *dtoa_result;
extern CONST double bigtens[], tens[], tinytens[];
extern Bigint *diff ANSI((Bigint*, Bigint*));
extern char *dtoa ANSI((double d, int mode, int ndigits,
int *decpt, int *sign, char **rve));
- extern void freedtoa ANSI((char*));
- extern char *gdtoa ANSI((FPI *fpi, int be, ULong *bits, int *kindp,
- int mode, int ndigits, int *decpt, char **rve));
extern char *g__fmt ANSI((char*, char*, char*, int, ULong));
extern int gethex ANSI((CONST char**, FPI*, Long*, Bigint**, int));
extern void hexdig_init_D2A(Void);
extern int hexnan ANSI((CONST char**, FPI*, ULong*));
- extern int hi0bits ANSI((ULong));
+ extern int hi0bits_D2A ANSI((ULong));
extern Bigint *i2b ANSI((int));
extern Bigint *increment ANSI((Bigint*));
extern int lo0bits ANSI((ULong*));
extern Bigint *s2b ANSI((CONST char*, int, int, ULong));
extern Bigint *set_ones ANSI((Bigint*, int));
extern char *strcp ANSI((char*, const char*));
- extern int strtodg ANSI((CONST char*, char**, FPI*, Long*, ULong*));
-
- extern int strtoId ANSI((CONST char *, char **, double *, double *));
- extern int strtoIdd ANSI((CONST char *, char **, double *, double *));
- extern int strtoIf ANSI((CONST char *, char **, float *, float *));
extern int strtoIg ANSI((CONST char*, char**, FPI*, Long*, Bigint**, int*));
- extern int strtoIQ ANSI((CONST char *, char **, void *, void *));
- extern int strtoIx ANSI((CONST char *, char **, void *, void *));
- extern int strtoIxL ANSI((CONST char *, char **, void *, void *));
extern double strtod ANSI((const char *s00, char **se));
- extern int strtopQ ANSI((CONST char *, char **, Void *));
- extern int strtopf ANSI((CONST char *, char **, float *));
- extern int strtopd ANSI((CONST char *, char **, double *));
- extern int strtopdd ANSI((CONST char *, char **, double *));
- extern int strtopx ANSI((CONST char *, char **, Void *));
- extern int strtopxL ANSI((CONST char *, char **, Void *));
- extern int strtord ANSI((CONST char *, char **, int, double *));
- extern int strtordd ANSI((CONST char *, char **, int, double *));
- extern int strtorf ANSI((CONST char *, char **, int, float *));
- extern int strtorQ ANSI((CONST char *, char **, int, void *));
- extern int strtorx ANSI((CONST char *, char **, int, void *));
- extern int strtorxL ANSI((CONST char *, char **, int, void *));
extern Bigint *sum ANSI((Bigint*, Bigint*));
extern int trailz ANSI((Bigint*));
extern double ulp ANSI((double));
#ifdef __cplusplus
}
#endif
-
-
+/*
+ * NAN_WORD0 and NAN_WORD1 are only referenced in strtod.c. Prior to
+ * 20050115, they used to be hard-wired here (to 0x7ff80000 and 0,
+ * respectively), but now are determined by compiling and running
+ * qnan.c to generate gd_qnan.h, which specifies d_QNAN0 and d_QNAN1.
+ * Formerly gdtoaimp.h recommended supplying suitable -DNAN_WORD0=...
+ * and -DNAN_WORD1=... values if necessary. This should still work.
+ * (On HP Series 700/800 machines, -DNAN_WORD0=0x7ff40000 works.)
+ */
#ifdef IEEE_Arith
#ifdef IEEE_MC68k
#define _0 0
#define _1 1
+#ifndef NAN_WORD0
+#define NAN_WORD0 d_QNAN0
+#endif
+#ifndef NAN_WORD1
+#define NAN_WORD1 d_QNAN1
+#endif
#else
#define _0 1
#define _1 0
-#endif
-#else
-#undef INFNAN_CHECK
-#endif
-
-#ifdef INFNAN_CHECK
-
#ifndef NAN_WORD0
-#define NAN_WORD0 0x7ff80000
+#define NAN_WORD0 d_QNAN1
#endif
-
#ifndef NAN_WORD1
-#define NAN_WORD1 0
+#define NAN_WORD1 d_QNAN0
+#endif
+#endif
+#else
+#undef INFNAN_CHECK
#endif
-#endif /* INFNAN_CHECK */
#undef SI
#ifdef Sudden_Underflow
--- /dev/null
+--- gdtoaimp.h.orig 2005-01-20 20:12:37.000000000 -0800
++++ gdtoaimp.h 2005-02-17 02:10:26.000000000 -0800
+@@ -167,6 +167,7 @@
+
+ #ifndef GDTOAIMP_H_INCLUDED
+ #define GDTOAIMP_H_INCLUDED
++#include <xlocale.h>
+ #include "gdtoa.h"
+ #include "gd_qnan.h"
+
+@@ -175,8 +176,11 @@
+ #define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);}
+ #endif
+
++#include "limits.h"
+ #include "stdlib.h"
+ #include "string.h"
++#include "libc_private.h"
++#include "spinlock.h"
+
+ #ifdef KR_headers
+ #define Char char
+@@ -190,6 +194,9 @@
+ #define MALLOC malloc
+ #endif
+
++#define INFNAN_CHECK
++#define USE_LOCALE
++
+ #undef IEEE_Arith
+ #undef Avoid_Underflow
+ #ifdef IEEE_MC68k
+@@ -449,10 +456,16 @@
+ #define ALL_ON 0xffff
+ #endif
+
+-#ifndef MULTIPLE_THREADS
+-#define ACQUIRE_DTOA_LOCK(n) /*nothing*/
+-#define FREE_DTOA_LOCK(n) /*nothing*/
+-#endif
++#define MULTIPLE_THREADS
++extern spinlock_t __gdtoa_locks[2];
++#define ACQUIRE_DTOA_LOCK(n) do { \
++ if (__isthreaded) \
++ _SPINLOCK(&__gdtoa_locks[n]); \
++} while(0)
++#define FREE_DTOA_LOCK(n) do { \
++ if (__isthreaded) \
++ _SPINUNLOCK(&__gdtoa_locks[n]); \
++} while(0)
+
+ #define Kmax 15
+
+@@ -475,51 +488,89 @@
+ #define Bcopy(x,y) memcpy(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int))
+ #endif /* NO_STRING_H */
+
+-#define Balloc Balloc_D2A
+-#define Bfree Bfree_D2A
+-#define ULtoQ ULtoQ_D2A
+-#define ULtof ULtof_D2A
+-#define ULtod ULtod_D2A
+-#define ULtodd ULtodd_D2A
+-#define ULtox ULtox_D2A
+-#define ULtoxL ULtoxL_D2A
+-#define any_on any_on_D2A
+-#define b2d b2d_D2A
+-#define bigtens bigtens_D2A
+-#define cmp cmp_D2A
+-#define copybits copybits_D2A
+-#define d2b d2b_D2A
+-#define decrement decrement_D2A
+-#define diff diff_D2A
+-#define dtoa_result dtoa_result_D2A
+-#define g__fmt g__fmt_D2A
+-#define gethex gethex_D2A
+-#define hexdig hexdig_D2A
+-#define hexnan hexnan_D2A
+-#define hi0bits(x) hi0bits_D2A((ULong)(x))
+-#define i2b i2b_D2A
+-#define increment increment_D2A
+-#define lo0bits lo0bits_D2A
+-#define lshift lshift_D2A
+-#define match match_D2A
+-#define mult mult_D2A
+-#define multadd multadd_D2A
+-#define nrv_alloc nrv_alloc_D2A
+-#define pow5mult pow5mult_D2A
+-#define quorem quorem_D2A
+-#define ratio ratio_D2A
+-#define rshift rshift_D2A
+-#define rv_alloc rv_alloc_D2A
+-#define s2b s2b_D2A
+-#define set_ones set_ones_D2A
+-#define strcp strcp_D2A
+-#define strtoIg strtoIg_D2A
+-#define sum sum_D2A
+-#define tens tens_D2A
+-#define tinytens tinytens_D2A
+-#define tinytens tinytens_D2A
+-#define trailz trailz_D2A
+-#define ulp ulp_D2A
++/*
++ * Paranoia: Protect exported symbols, including ones in files we don't
++ * compile right now. The standard strtof and strtod survive.
++ */
++#define dtoa __dtoa
++#define gdtoa __gdtoa
++#define freedtoa __freedtoa
++#define strtodg __strtodg
++#define g_ddfmt __g_ddfmt
++#define g_dfmt __g_dfmt
++#define g_ffmt __g_ffmt
++#define g_Qfmt __g_Qfmt
++#define g_xfmt __g_xfmt
++#define g_xLfmt __g_xLfmt
++#define strtoId __strtoId
++#define strtoIdd __strtoIdd
++#define strtoIf __strtoIf
++#define strtoIQ __strtoIQ
++#define strtoIx __strtoIx
++#define strtoIxL __strtoIxL
++#define strtord __strtord
++#define strtordd __strtordd
++#define strtorf __strtorf
++#define strtorQ __strtorQ
++#define strtorx __strtorx
++#define strtorxL __strtorxL
++#define strtodI __strtodI
++#define strtopd __strtopd
++#define strtopdd __strtopdd
++#define strtopf __strtopf
++#define strtopQ __strtopQ
++#define strtopx __strtopx
++#define strtopxL __strtopxL
++
++/* Protect gdtoa-internal symbols */
++#define Balloc __Balloc_D2A
++#define Bfree __Bfree_D2A
++#define ULtoQ __ULtoQ_D2A
++#define ULtof __ULtof_D2A
++#define ULtod __ULtod_D2A
++#define ULtodd __ULtodd_D2A
++#define ULtox __ULtox_D2A
++#define ULtoxL __ULtoxL_D2A
++#define any_on __any_on_D2A
++#define b2d __b2d_D2A
++#define bigtens __bigtens_D2A
++#define cmp __cmp_D2A
++#define copybits __copybits_D2A
++#define d2b __d2b_D2A
++#define decrement __decrement_D2A
++#define diff __diff_D2A
++#define dtoa_result __dtoa_result_D2A
++#define g__fmt __g__fmt_D2A
++#define gethex __gethex_D2A
++#define hexdig __hexdig_D2A
++#define hexdig_init_D2A __hexdig_init_D2A
++#define hexnan __hexnan_D2A
++#define hi0bits __hi0bits_D2A
++#define hi0bits_D2A __hi0bits_D2A
++#define i2b __i2b_D2A
++#define increment __increment_D2A
++#define lo0bits __lo0bits_D2A
++#define lshift __lshift_D2A
++#define match __match_D2A
++#define mult __mult_D2A
++#define multadd __multadd_D2A
++#define nrv_alloc __nrv_alloc_D2A
++#define pow5mult __pow5mult_D2A
++#define quorem __quorem_D2A
++#define ratio __ratio_D2A
++#define rshift __rshift_D2A
++#define rv_alloc __rv_alloc_D2A
++#define s2b __s2b_D2A
++#define set_ones __set_ones_D2A
++#define strcp __strcp_D2A
++#define strcp_D2A __strcp_D2A
++#define strtoIg __strtoIg_D2A
++#define sum __sum_D2A
++#define tens __tens_D2A
++#define tinytens __tinytens_D2A
++#define tinytens __tinytens_D2A
++#define trailz __trailz_D2A
++#define ulp __ulp_D2A
+
+ extern char *dtoa_result;
+ extern CONST double bigtens[], tens[], tinytens[];
+@@ -542,8 +593,11 @@
+ extern Bigint *diff ANSI((Bigint*, Bigint*));
+ extern char *dtoa ANSI((double d, int mode, int ndigits,
+ int *decpt, int *sign, char **rve));
++ extern void freedtoa ANSI((char*));
++ extern char *gdtoa ANSI((FPI *fpi, int be, ULong *bits, int *kindp,
++ int mode, int ndigits, int *decpt, char **rve));
+ extern char *g__fmt ANSI((char*, char*, char*, int, ULong));
+- extern int gethex ANSI((CONST char**, FPI*, Long*, Bigint**, int));
++ extern int gethex ANSI((CONST char**, FPI*, Long*, Bigint**, int, locale_t));
+ extern void hexdig_init_D2A(Void);
+ extern int hexnan ANSI((CONST char**, FPI*, ULong*));
+ extern int hi0bits_D2A ANSI((ULong));
+@@ -563,8 +617,29 @@
+ extern Bigint *s2b ANSI((CONST char*, int, int, ULong));
+ extern Bigint *set_ones ANSI((Bigint*, int));
+ extern char *strcp ANSI((char*, const char*));
++ extern int strtodg ANSI((CONST char*, char**, FPI*, Long*, ULong*, locale_t));
++
++ extern int strtoId ANSI((CONST char *, char **, double *, double *));
++ extern int strtoIdd ANSI((CONST char *, char **, double *, double *));
++ extern int strtoIf ANSI((CONST char *, char **, float *, float *));
+ extern int strtoIg ANSI((CONST char*, char**, FPI*, Long*, Bigint**, int*));
++ extern int strtoIQ ANSI((CONST char *, char **, void *, void *));
++ extern int strtoIx ANSI((CONST char *, char **, void *, void *));
++ extern int strtoIxL ANSI((CONST char *, char **, void *, void *));
+ extern double strtod ANSI((const char *s00, char **se));
++ extern double strtod_l ANSI((const char *s00, char **se, locale_t));
++ extern int strtopQ ANSI((CONST char *, char **, Void *));
++ extern int strtopf ANSI((CONST char *, char **, float *));
++ extern int strtopd ANSI((CONST char *, char **, double *));
++ extern int strtopdd ANSI((CONST char *, char **, double *, locale_t));
++ extern int strtopx ANSI((CONST char *, char **, Void *, locale_t));
++ extern int strtopxL ANSI((CONST char *, char **, Void *));
++ extern int strtord ANSI((CONST char *, char **, int, double *));
++ extern int strtordd ANSI((CONST char *, char **, int, double *));
++ extern int strtorf ANSI((CONST char *, char **, int, float *));
++ extern int strtorQ ANSI((CONST char *, char **, int, void *));
++ extern int strtorx ANSI((CONST char *, char **, int, void *));
++ extern int strtorxL ANSI((CONST char *, char **, int, void *));
+ extern Bigint *sum ANSI((Bigint*, Bigint*));
+ extern int trailz ANSI((Bigint*));
+ extern double ulp ANSI((double));
--- /dev/null
+/*-
+ * Copyright (c) 2003 David Schultz <das@FreeBSD.ORG>
+ * 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.
+ */
+
+/*
+ * Machine-dependent glue to integrate David Gay's gdtoa
+ * package into libc for architectures where a long double
+ * is a head/tail pair of doubles
+ */
+
+#include <sys/cdefs.h>
+
+#include "gdtoaimp.h"
+
+long double
+strtold(const char * __restrict s, char ** __restrict sp)
+{
+ long double result;
+
+ strtopdd(s, sp, &result);
+ return result;
+}
--- /dev/null
+--- machdep_ldisdd.c.orig 2004-09-20 17:32:38.000000000 -0700
++++ machdep_ldisdd.c 2005-02-19 03:07:38.000000000 -0800
+@@ -32,13 +32,34 @@
+
+ #include <sys/cdefs.h>
+
++#include "xlocale_private.h"
++
+ #include "gdtoaimp.h"
+
+ long double
+ strtold(const char * __restrict s, char ** __restrict sp)
+ {
++#ifdef LDBL_COMPAT
++ return (long double)strtod_l(s, sp, __current_locale());
++#else /* LDBL_COMPAT */
++ long double result;
++
++ strtopdd(s, sp, (double *)&result, __current_locale());
++ return result;
++#endif /* LDBL_COMPAT */
++}
++
++long double
++strtold_l(const char * __restrict s, char ** __restrict sp, locale_t loc)
++{
++#ifdef LDBL_COMPAT
++ NORMALIZE_LOCALE(loc);
++ return (long double)strtod_l(s, sp, loc);
++#else /* LDBL_COMPAT */
+ long double result;
+
+- strtopdd(s, sp, &result);
++ NORMALIZE_LOCALE(loc);
++ strtopdd(s, sp, (double *)&result, loc);
+ return result;
++#endif /* LDBL_COMPAT */
+ }
--- /dev/null
+--- machdep_ldisx.c.orig 2003-05-20 15:20:48.000000000 -0700
++++ machdep_ldisx.c 2005-02-17 02:00:41.000000000 -0800
+@@ -33,6 +33,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/gdtoa/machdep_ldisx.c,v 1.2 2003/04/09 05:58:43 das Exp $");
+
++#include "xlocale_private.h"
++
+ #include "gdtoaimp.h"
+
+ long double
+@@ -40,6 +42,16 @@
+ {
+ long double result;
+
+- strtopx(s, sp, &result);
++ strtopx(s, sp, &result, __current_locale());
++ return result;
++}
++
++long double
++strtold_l(const char * __restrict s, char ** __restrict sp, locale_t loc)
++{
++ long double result;
++
++ NORMALIZE_LOCALE(loc);
++ strtopx(s, sp, &result, loc);
+ return result;
+ }
.include "Makefile.fbsd_begin"
FBSDMISRCS= _hdtoa.c _ldtoa.c glue.c \
gdtoa-dmisc.c gdtoa-dtoa.c gdtoa-gdtoa.c gdtoa-gethex.c gdtoa-gmisc.c \
- gdtoa-hd_init.c gdtoa-hexnan.c gdtoa-misc.c gdtoa-smisc.c gdtoa-strtoIg.c \
- gdtoa-strtod.c gdtoa-strtodg.c gdtoa-strtof.c gdtoa-strtord.c gdtoa-sum.c \
- gdtoa-ulp.c
+ gdtoa-hd_init.c gdtoa-hexnan.c gdtoa-misc.c gdtoa-smisc.c \
+ gdtoa-strtod.c gdtoa-strtodg.c gdtoa-strtof.c gdtoa-strtord.c \
+ gdtoa-sum.c gdtoa-ulp.c
.if exists(${.CURDIR}/${MACHINE_ARCH}/stdlib/gdtoa.mk)
.include "${.CURDIR}/${MACHINE_ARCH}/stdlib/gdtoa.mk"
.endif
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+#if defined(__ppc__) || defined(__ppc64__)
+
+#define f_QNAN 0x7fc00000
+#define d_QNAN0 0x7ff80000
+#define d_QNAN1 0x0
+#define ld_QNAN0 0x7ff80000
+#define ld_QNAN1 0x0
+#define ld_QNAN2 0x0
+#define ld_QNAN3 0x0
+#define ldus_QNAN0 0x7ff8
+#define ldus_QNAN1 0x0
+#define ldus_QNAN2 0x0
+#define ldus_QNAN3 0x0
+#define ldus_QNAN4 0x0
+
+#elif defined(__i386__)
+
+#define f_QNAN 0xffc00000
+#define d_QNAN0 0x0
+#define d_QNAN1 0xfff80000
+#define ld_QNAN0 0x0
+#define ld_QNAN1 0xc0000000
+#define ld_QNAN2 0xffff
+#define ld_QNAN3 0x0
+#define ldus_QNAN0 0x0
+#define ldus_QNAN1 0x0
+#define ldus_QNAN2 0x0
+#define ldus_QNAN3 0xc000
+#define ldus_QNAN4 0xffff
+
+#else
+#error unknown architecture
+#endif
--- /dev/null
+/*-
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)assert.c 8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/libc/gen/assert.c,v 1.7 2002/02/01 00:57:29 obrien Exp $");
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+void
+__assert(func, file, line, failedexpr)
+ const char *func, *file;
+ int line;
+ const char *failedexpr;
+{
+ if (func == NULL)
+ (void)fprintf(stderr,
+ "Assertion failed: (%s), file %s, line %d.\n", failedexpr,
+ file, line);
+ else
+ (void)fprintf(stderr,
+ "Assertion failed: (%s), function %s, file %s, line %d.\n",
+ failedexpr, func, file, line);
+ abort();
+ /* NOTREACHED */
+}
--- /dev/null
+--- assert.c.orig 2004-09-20 17:32:51.000000000 -0700
++++ assert.c 2004-11-17 15:56:24.000000000 -0800
+@@ -42,7 +42,7 @@
+ #include <stdlib.h>
+
+ void
+-__assert(func, file, line, failedexpr)
++__assert_rtn(func, file, line, failedexpr)
+ const char *func, *file;
+ int line;
+ const char *failedexpr;
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $OpenBSD: basename.3,v 1.12 2000/04/18 03:01:25 aaron Exp $
-.\" $FreeBSD: src/lib/libc/gen/basename.3,v 1.6 2002/12/18 13:33:02 ru Exp $
+.\" $FreeBSD: src/lib/libc/gen/basename.3,v 1.7 2004/07/02 23:52:10 ru Exp $
.\"
.Dd August 17, 1997
.Dt BASENAME 3
and
.Fx 4.2 .
.Sh AUTHORS
-Todd C. Miller <Todd.Miller@courtesan.com>
+.An "Todd C. Miller" Aq Todd.Miller@courtesan.com
.\" SUCH DAMAGE.
.\"
.\" @(#)ctermid.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/gen/ctermid.3,v 1.10 2002/12/18 13:33:02 ru Exp $
+.\" $FreeBSD: src/lib/libc/gen/ctermid.3,v 1.11 2003/09/08 19:57:14 ru Exp $
.\"
.Dd June 4, 1993
.Dt CTERMID 3
.Dv L_ctermid
(as defined in the include
file
-.Aq Pa stdio.h )
+.In stdio.h )
bytes long.
.Pp
The
.\" SUCH DAMAGE.
.\"
.\" @(#)daemon.3 8.1 (Berkeley) 6/9/93
-.\" $FreeBSD: src/lib/libc/gen/daemon.3,v 1.12 2002/01/16 15:21:39 ru Exp $
+.\" $FreeBSD: src/lib/libc/gen/daemon.3,v 1.14 2003/11/10 22:04:51 ghelmer Exp $
.\"
.Dd June 9, 1993
.Dt DAEMON 3
.Xr setsid 2 .
.Sh SEE ALSO
.Xr fork 2 ,
-.Xr setsid 2
+.Xr setsid 2 ,
+.Xr sigaction 2
.Sh HISTORY
The
.Fn daemon
.Fn daemon
before opening any files or sockets, or verify that any file
descriptors obtained have values greater than 2.
+.Pp
+The
+.Fn daemon
+function temporarily ignores
+.Dv SIGHUP
+while calling
+.Xr setsid 2
+to prevent a parent session group leader's calls to
+.Xr fork 2
+and then
+.Xr _exit 2
+from prematurely terminating the child process.
static char sccsid[] = "@(#)daemon.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/gen/daemon.c,v 1.5 2002/02/01 00:57:29 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/gen/daemon.c,v 1.6 2003/11/10 22:01:42 ghelmer Exp $");
#include "namespace.h"
+#include <errno.h>
#include <fcntl.h>
#include <paths.h>
+#include <signal.h>
#include <unistd.h>
#include "un-namespace.h"
daemon(nochdir, noclose)
int nochdir, noclose;
{
+ struct sigaction osa, sa;
int fd;
+ pid_t newgrp;
+ int oerrno;
+ int osa_ok;
+
+ /* A SIGHUP may be thrown when the parent exits below. */
+ sigemptyset(&sa.sa_mask);
+ sa.sa_handler = SIG_IGN;
+ sa.sa_flags = 0;
+ osa_ok = _sigaction(SIGHUP, &sa, &osa);
switch (fork()) {
case -1:
_exit(0);
}
- if (setsid() == -1)
+ newgrp = setsid();
+ oerrno = errno;
+ if (osa_ok != -1)
+ _sigaction(SIGHUP, &osa, NULL);
+
+ if (newgrp == -1) {
+ errno = oerrno;
return (-1);
+ }
if (!nochdir)
(void)chdir("/");
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $OpenBSD: dirname.3,v 1.9 2000/04/18 03:01:25 aaron Exp $
-.\" $FreeBSD: src/lib/libc/gen/dirname.3,v 1.7 2002/12/27 12:15:28 schweikh Exp $
+.\" $FreeBSD: src/lib/libc/gen/dirname.3,v 1.8 2004/07/02 23:52:10 ru Exp $
.\"
.Dd August 17, 1997
.Dt DIRNAME 3
and
.Fx 4.2 .
.Sh AUTHORS
-Todd C. Miller <Todd.Miller@courtesan.com>
+.An "Todd C. Miller" Aq Todd.Miller@courtesan.com
.\" SUCH DAMAGE.
.\"
.\" From: @(#)err.3 8.1 (Berkeley) 6/9/93
-.\" $FreeBSD: src/lib/libc/gen/err.3,v 1.19 2002/08/05 06:49:58 mike Exp $
+.\" $FreeBSD: src/lib/libc/gen/err.3,v 1.20 2004/10/04 14:04:37 jkoshy Exp $
.\"
.Dd March 6, 1999
.Dt ERR 3
.Fn verrx
functions do not return, but exit with the value of the argument
.Fa eval .
+It is recommended that the standard values defined in
+.Xr sysexits 3
+be used for the value of
+.Fa eval .
The
.Fn err_set_exit
function can be used to specify a function which is called before
.Xr exit 3 ,
.Xr fmtmsg 3 ,
.Xr printf 3 ,
-.Xr strerror 3
+.Xr strerror 3 ,
+.Xr sysexits 3
.Sh HISTORY
The
.Fn err
--- /dev/null
+--- err.c.orig 2004-08-30 09:45:37.000000000 -0700
++++ err.c 2004-08-30 09:58:06.000000000 -0700
+@@ -48,8 +48,15 @@
+
+ #include "libc_private.h"
+
+-static FILE *err_file; /* file to use for error output */
+-static void (*err_exit)(int);
++#ifdef BUILDING_VARIANT
++
++__private_extern__ FILE *_e_err_file; /* file to use for error output */
++__private_extern__ void (*_e_err_exit)(int);
++
++#else /* !BUILDING_VARIANT */
++
++__private_extern__ FILE *_e_err_file = NULL; /* file to use for error output */
++__private_extern__ void (*_e_err_exit)(int) = NULL;
+
+ /*
+ * This is declared to take a `void *' so that the caller is not required
+@@ -60,16 +67,17 @@
+ err_set_file(void *fp)
+ {
+ if (fp)
+- err_file = fp;
++ _e_err_file = fp;
+ else
+- err_file = stderr;
++ _e_err_file = stderr;
+ }
+
+ void
+ err_set_exit(void (*ef)(int))
+ {
+- err_exit = ef;
++ _e_err_exit = ef;
+ }
++#endif /* !BUILDING_VARIANT */
+
+ __weak_reference(_err, err);
+
+@@ -107,16 +115,16 @@
+ const char *fmt;
+ va_list ap;
+ {
+- if (err_file == 0)
++ if (_e_err_file == 0)
+ err_set_file((FILE *)0);
+- fprintf(err_file, "%s: ", _getprogname());
++ fprintf(_e_err_file, "%s: ", _getprogname());
+ if (fmt != NULL) {
+- vfprintf(err_file, fmt, ap);
+- fprintf(err_file, ": ");
++ vfprintf(_e_err_file, fmt, ap);
++ fprintf(_e_err_file, ": ");
+ }
+- fprintf(err_file, "%s\n", strerror(code));
+- if (err_exit)
+- err_exit(eval);
++ fprintf(_e_err_file, "%s\n", strerror(code));
++ if (_e_err_exit)
++ _e_err_exit(eval);
+ exit(eval);
+ }
+
+@@ -135,14 +143,14 @@
+ const char *fmt;
+ va_list ap;
+ {
+- if (err_file == 0)
++ if (_e_err_file == 0)
+ err_set_file((FILE *)0);
+- fprintf(err_file, "%s: ", _getprogname());
++ fprintf(_e_err_file, "%s: ", _getprogname());
+ if (fmt != NULL)
+- vfprintf(err_file, fmt, ap);
+- fprintf(err_file, "\n");
+- if (err_exit)
+- err_exit(eval);
++ vfprintf(_e_err_file, fmt, ap);
++ fprintf(_e_err_file, "\n");
++ if (_e_err_exit)
++ _e_err_exit(eval);
+ exit(eval);
+ }
+
+@@ -180,14 +188,14 @@
+ const char *fmt;
+ va_list ap;
+ {
+- if (err_file == 0)
++ if (_e_err_file == 0)
+ err_set_file((FILE *)0);
+- fprintf(err_file, "%s: ", _getprogname());
++ fprintf(_e_err_file, "%s: ", _getprogname());
+ if (fmt != NULL) {
+- vfprintf(err_file, fmt, ap);
+- fprintf(err_file, ": ");
++ vfprintf(_e_err_file, fmt, ap);
++ fprintf(_e_err_file, ": ");
+ }
+- fprintf(err_file, "%s\n", strerror(code));
++ fprintf(_e_err_file, "%s\n", strerror(code));
+ }
+
+ void
+@@ -204,10 +212,10 @@
+ const char *fmt;
+ va_list ap;
+ {
+- if (err_file == 0)
++ if (_e_err_file == 0)
+ err_set_file((FILE *)0);
+- fprintf(err_file, "%s: ", _getprogname());
++ fprintf(_e_err_file, "%s: ", _getprogname());
+ if (fmt != NULL)
+- vfprintf(err_file, fmt, ap);
+- fprintf(err_file, "\n");
++ vfprintf(_e_err_file, fmt, ap);
++ fprintf(_e_err_file, "\n");
+ }
.\" SUCH DAMAGE.
.\"
.\" @(#)exec.3 8.3 (Berkeley) 1/24/94
-.\" $FreeBSD: src/lib/libc/gen/exec.3,v 1.18 2002/12/19 09:40:21 ru Exp $
+.\" $FreeBSD: src/lib/libc/gen/exec.3,v 1.23 2003/09/10 19:24:32 ru Exp $
.\"
.Dd January 24, 1994
.Dt EXEC 3
.Nm execle ,
.Nm exect ,
.Nm execv ,
-.Nm execvp
+.Nm execvp ,
+.Nm execvP
.Nd execute a file
.Sh LIBRARY
.Lb libc
.In unistd.h
.Vt extern char **environ ;
.Ft int
-.Fn execl "const char *path" "const char *arg" ...
+.Fn execl "const char *path" "const char *arg" ... /* "(char *)0" */
.Ft int
-.Fn execlp "const char *file" "const char *arg" ...
+.Fn execlp "const char *file" "const char *arg" ... /* "(char *)0" */
.Ft int
-.Fn execle "const char *path" "const char *arg" ...
+.Fo execle
+.Fa "const char *path" "const char *arg" ...
+.Fa /*
+.Bk -words
+.Fa "(char *)0" "char *const envp[]" */
+.Ek
+.Fc
.Ft int
.Fn exect "const char *path" "char *const argv[]" "char *const envp[]"
.Ft int
.Fn execv "const char *path" "char *const argv[]"
.Ft int
.Fn execvp "const char *file" "char *const argv[]"
+.Ft int
+.Fn execvP "const char *file" "const char *search_path" "char *const argv[]"
.Sh DESCRIPTION
The
.Nm exec
The
.Fn exect ,
.Fn execv ,
+.Fn execvp ,
and
-.Fn execvp
+.Fn execvP
functions provide an array of pointers to null-terminated strings that
represent the argument list available to the new program.
The first argument, by convention, should point to the file name associated
Some of these functions have special semantics.
.Pp
The functions
-.Fn execlp
+.Fn execlp ,
+.Fn execvp ,
and
-.Fn execvp
+.Fn execvP
will duplicate the actions of the shell in searching for an executable file
if the specified file name does not contain a slash
.Dq Li /
character.
-The search path is the path specified in the environment by
+For
+.Fn execlp
+and
+.Fn execvp ,
+search path is the path specified in the environment by
.Dq Ev PATH
variable.
If this variable isn't specified,
the default path is set according to the
.Dv _PATH_DEFPATH
definition in
-.Aq paths.h ,
+.In paths.h ,
which is set to
.Dq Ev /usr/bin:/bin .
+For
+.Fn execvP ,
+the search path is specified as an argument to the function.
In addition, certain errors are treated specially.
.Pp
If an error is ambiguous (for simplicity, we shall consider all
The
.Fn execl ,
.Fn execle ,
-.Fn execlp
-and
+.Fn execlp ,
.Fn execvp
+and
+.Fn execvP
functions
may fail and set
.Va errno
functions
conform to
.St -p1003.1-88 .
+The
+.Fn execvP
+function first appeared in
+.Fx 5.2 .
---- exec.3.orig Tue May 20 15:21:01 2003
-+++ exec.3 Mon Oct 27 23:21:54 2003
+--- exec.3.orig 2003-09-10 12:24:32.000000000 -0700
++++ exec.3 2004-10-24 17:12:17.000000000 -0700
@@ -39,7 +39,6 @@
.Nm execl ,
.Nm execlp ,
.Nm execle ,
-.Nm exect ,
.Nm execv ,
- .Nm execvp
- .Nd execute a file
-@@ -55,8 +54,6 @@
- .Ft int
- .Fn execle "const char *path" "const char *arg" ...
+ .Nm execvp ,
+ .Nm execvP
+@@ -62,8 +61,6 @@
+ .Ek
+ .Fc
.Ft int
-.Fn exect "const char *path" "char *const argv[]" "char *const envp[]"
-.Ft int
.Fn execv "const char *path" "char *const argv[]"
.Ft int
.Fn execvp "const char *file" "char *const argv[]"
-@@ -97,8 +94,7 @@
+@@ -106,7 +103,6 @@
pointer.
.Pp
The
-.Fn exect ,
--.Fn execv ,
-+.Fn execv
+ .Fn execv ,
+ .Fn execvp ,
and
- .Fn execvp
- functions provide an array of pointers to null-terminated strings that
-@@ -113,9 +109,7 @@
+@@ -123,9 +119,7 @@
.Pp
The
.Fn execle
the
.Dv NULL
pointer that terminates the list of arguments in the argument list
-@@ -185,11 +179,6 @@
+@@ -203,11 +197,6 @@
these functions will execute the shell with the path of
the file as its first argument.
(If this attempt fails, no further searching is done.)
.Sh RETURN VALUES
If any of the
.Fn exec
-@@ -218,10 +207,8 @@
+@@ -237,10 +226,8 @@
.Xr malloc 3 .
.Pp
The
static char sccsid[] = "@(#)exec.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/gen/exec.c,v 1.20 2003/01/03 23:16:55 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/gen/exec.c,v 1.22 2003/07/01 12:30:03 bde Exp $");
#include "namespace.h"
#include <sys/param.h>
}
int
-execvp(name, argv)
+execvp(const char *name, char * const *argv)
+{
+ const char *path;
+
+ /* Get the path we're searching. */
+ if ((path = getenv("PATH")) == NULL)
+ path = _PATH_DEFPATH;
+
+ return (execvP(name, path, argv));
+}
+
+int
+execvP(name, path, argv)
const char *name;
+ const char *path;
char * const *argv;
{
char **memp;
int cnt, lp, ln;
char *p;
int eacces, save_errno;
- char *bp, *cur, *path, buf[MAXPATHLEN];
+ char *bp, *cur, buf[MAXPATHLEN];
struct stat sb;
eacces = 0;
/* If it's an absolute or relative path name, it's easy. */
if (index(name, '/')) {
bp = (char *)name;
- cur = path = NULL;
+ cur = NULL;
goto retry;
}
bp = buf;
return (-1);
}
- /* Get the path we're searching. */
- if (!(path = getenv("PATH")))
- path = _PATH_DEFPATH;
cur = alloca(strlen(path) + 1);
if (cur == NULL) {
errno = ENOMEM;
return (-1);
}
strcpy(cur, path);
- path = cur;
- while ( (p = strsep(&cur, ":")) ) {
+ while ((p = strsep(&cur, ":")) != NULL) {
/*
* It's a SHELL path -- double, leading and trailing colons
* mean the current directory.
*/
- if (!*p) {
+ if (*p == '\0') {
p = ".";
lp = 1;
} else
* the user may execute the wrong program.
*/
if (lp + ln + 2 > sizeof(buf)) {
- (void)_write(STDERR_FILENO, "execvp: ", 8);
+ (void)_write(STDERR_FILENO, "execvP: ", 8);
(void)_write(STDERR_FILENO, p, lp);
(void)_write(STDERR_FILENO, ": path too long\n",
16);
buf[lp + ln + 1] = '\0';
retry: (void)_execve(bp, argv, environ);
- switch(errno) {
+ switch (errno) {
case E2BIG:
goto done;
case ELOOP:
---- exec.c.orig Fri Jan 3 15:16:55 2003
-+++ exec.c Sat May 3 14:03:35 2003
+--- exec.c.orig 2004-11-24 00:12:00.000000000 -0800
++++ exec.c 2004-11-24 15:46:54.000000000 -0800
@@ -51,7 +51,8 @@
#include <stdarg.h>
#include "un-namespace.h"
int
execl(const char *name, const char *arg, ...)
+@@ -268,8 +269,9 @@
+ }
+ if (eacces)
+ errno = EACCES;
+- else
++ else if (cur)
+ errno = ENOENT;
++ /* else use existing errno from _execve */
+ done:
+ return (-1);
+ }
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/lib/libc/gen/fmtcheck.3,v 1.8 2002/12/19 09:40:21 ru Exp $
+.\" $FreeBSD: src/lib/libc/gen/fmtcheck.3,v 1.9 2004/07/02 23:52:10 ru Exp $
.Dd October 16, 2002
.Os
.Dt FMTCHECK 3
The
.Xr printf 3
family of functions cannot verify the types of arguments that they are
-passed at run-time. In some cases, like
+passed at run-time.
+In some cases, like
.Xr catgets 3 ,
it is useful or necessary to use a user-supplied format string with no
guarantee that the format string matches the specified arguments.
printf(fmtcheck(user_format, standard_format), arg1, arg2);
.Ed
.Pp
-In the check, field widths, fillers, precisions, etc. are ignored (unless
+In the check, field widths, fillers, precisions, etc.\& are ignored (unless
the field width or precision is an asterisk
.Ql *
-instead of a digit string). Also, any text other than the format specifiers
+instead of a digit string).
+Also, any text other than the format specifiers
is completely ignored.
.Sh RETURN VALUES
If
.Fa fmt_default .
.Sh SECURITY CONSIDERATIONS
Note that the formats may be quite different as long as they accept the
-same arguments. For example,
+same arguments.
+For example,
.Qq Li "%p %o %30s %#llx %-10.*e %n"
is compatible with
.Qq Li "This number %lu %d%% and string %s has %qd numbers and %.*g floats (%n)" .
/* $NetBSD: fmtcheck.c,v 1.2 2000/11/01 01:17:20 briggs Exp $ */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/gen/fmtcheck.c,v 1.5 2002/06/27 13:20:54 deischen Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/gen/fmtcheck.c,v 1.7 2004/05/02 10:55:05 das Exp $");
#include <stdio.h>
#include <string.h>
FMTCHECK_INT,
FMTCHECK_LONG,
FMTCHECK_QUAD,
+ FMTCHECK_PTRDIFFT,
+ FMTCHECK_SIZET,
FMTCHECK_SHORTPOINTER,
FMTCHECK_INTPOINTER,
FMTCHECK_LONGPOINTER,
FMTCHECK_QUADPOINTER,
+ FMTCHECK_PTRDIFFTPOINTER,
+ FMTCHECK_SIZETPOINTER,
+#ifndef NO_FLOATING_POINT
FMTCHECK_DOUBLE,
FMTCHECK_LONGDOUBLE,
+#endif
FMTCHECK_STRING,
FMTCHECK_WIDTH,
FMTCHECK_PRECISION,
static EFT
get_next_format_from_precision(const char **pf)
{
- int sh, lg, quad, longdouble;
+ int sh, lg, quad, longdouble, ptrdifft, sizet;
const char *f;
- sh = lg = quad = longdouble = 0;
+ sh = lg = quad = longdouble = ptrdifft = sizet = 0;
f = *pf;
switch (*f) {
f++;
quad = 1;
break;
+ case 't':
+ f++;
+ ptrdifft = 1;
+ break;
+ case 'z':
+ f++;
+ sizet = 1;
+ break;
case 'L':
f++;
longdouble = 1;
RETURN(pf,f,FMTCHECK_LONG);
if (quad)
RETURN(pf,f,FMTCHECK_QUAD);
+ if (ptrdifft)
+ RETURN(pf,f,FMTCHECK_PTRDIFFT);
+ if (sizet)
+ RETURN(pf,f,FMTCHECK_SIZET);
RETURN(pf,f,FMTCHECK_INT);
}
if (*f == 'n') {
RETURN(pf,f,FMTCHECK_LONGPOINTER);
if (quad)
RETURN(pf,f,FMTCHECK_QUADPOINTER);
+ if (ptrdifft)
+ RETURN(pf,f,FMTCHECK_PTRDIFFTPOINTER);
+ if (sizet)
+ RETURN(pf,f,FMTCHECK_SIZETPOINTER);
RETURN(pf,f,FMTCHECK_INTPOINTER);
}
if (strchr("DOU", *f)) {
- if (sh + lg + quad + longdouble)
+ if (sh + lg + quad + longdouble + ptrdifft + sizet)
RETURN(pf,f,FMTCHECK_UNKNOWN);
RETURN(pf,f,FMTCHECK_LONG);
}
- if (strchr("eEfg", *f)) {
+#ifndef NO_FLOATING_POINT
+ if (strchr("aAeEfFgG", *f)) {
if (longdouble)
RETURN(pf,f,FMTCHECK_LONGDOUBLE);
- if (sh + lg + quad)
+ if (sh + lg + quad + ptrdifft + sizet)
RETURN(pf,f,FMTCHECK_UNKNOWN);
RETURN(pf,f,FMTCHECK_DOUBLE);
}
+#endif
if (*f == 'c') {
- if (sh + lg + quad + longdouble)
+ if (sh + lg + quad + longdouble + ptrdifft + sizet)
RETURN(pf,f,FMTCHECK_UNKNOWN);
RETURN(pf,f,FMTCHECK_INT);
}
if (*f == 's') {
- if (sh + lg + quad + longdouble)
+ if (sh + lg + quad + longdouble + ptrdifft + sizet)
RETURN(pf,f,FMTCHECK_UNKNOWN);
RETURN(pf,f,FMTCHECK_STRING);
}
if (*f == 'p') {
- if (sh + lg + quad + longdouble)
+ if (sh + lg + quad + longdouble + ptrdifft + sizet)
RETURN(pf,f,FMTCHECK_UNKNOWN);
RETURN(pf,f,FMTCHECK_LONG);
}
.\" SUCH DAMAGE.
.\"
.\" @(#)fnmatch.3 8.3 (Berkeley) 4/28/95
-.\" $FreeBSD: src/lib/libc/gen/fnmatch.3,v 1.14 2002/12/18 13:33:02 ru Exp $
+.\" $FreeBSD: src/lib/libc/gen/fnmatch.3,v 1.18 2004/07/18 06:56:40 tjr Exp $
.\"
-.Dd April 28, 1995
+.Dd July 18, 2004
.Dt FNMATCH 3
.Os
.Sh NAME
.Nm fnmatch
-.Nd match filename or pathname
+.Nd test whether a filename or pathname matches a shell-style pattern
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.Tn OR
of any of the following
constants, which are defined in the include file
-.Pa fnmatch.h .
+.In fnmatch.h .
.Bl -tag -width FNM_PATHNAME
.It Dv FNM_NOESCAPE
Normally, every occurrence of a backslash
.Fa pattern
matching.
.It Dv FNM_CASEFOLD
-Ignore case distinctions in both the
+Ignore case distinctions in both the
.Fa pattern
and the
.Fa string .
.Xr glob 3 ,
.Xr regex 3
.Sh STANDARDS
-The
+The current implementation of the
.Fn fnmatch
-function conforms to
+function
+.Em does not
+conform to
.St -p1003.2 .
+Collating symbol expressions, equivalence class expressions and
+character class expressions are not supported.
.Sh HISTORY
The
.Fn fnmatch
static char sccsid[] = "@(#)fnmatch.c 8.2 (Berkeley) 4/16/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/gen/fnmatch.c,v 1.15 2002/02/01 01:32:19 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/gen/fnmatch.c,v 1.16 2004/07/29 03:13:10 tjr Exp $");
/*
* Function fnmatch() as specified in POSIX 1003.2-1992, section B.6.
* Compares a filename or pathname to a pattern.
*/
-#include <ctype.h>
+/*
+ * Some notes on multibyte character support:
+ * 1. Patterns with illegal byte sequences match nothing.
+ * 2. Illegal byte sequences in the "string" argument are handled by treating
+ * them as single-byte characters with a value of the first byte of the
+ * sequence cast to wchar_t.
+ * 3. Multibyte conversion state objects (mbstate_t) are passed around and
+ * used for most, but not all, conversions. Further work will be required
+ * to support state-dependent encodings.
+ */
+
#include <fnmatch.h>
+#include <limits.h>
#include <string.h>
-#include <stdio.h>
+#include <wchar.h>
+#include <wctype.h>
#include "collate.h"
#define RANGE_NOMATCH 0
#define RANGE_ERROR (-1)
-static int rangematch(const char *, char, int, char **);
+static int rangematch(const char *, wchar_t, int, char **, mbstate_t *);
+static int fnmatch1(const char *, const char *, int, mbstate_t, mbstate_t);
int
fnmatch(pattern, string, flags)
const char *pattern, *string;
int flags;
+{
+ static const mbstate_t initial;
+
+ return (fnmatch1(pattern, string, flags, initial, initial));
+}
+
+static int
+fnmatch1(pattern, string, flags, patmbs, strmbs)
+ const char *pattern, *string;
+ int flags;
+ mbstate_t patmbs, strmbs;
{
const char *stringstart;
char *newp;
- char c, test;
+ char c;
+ wchar_t pc, sc;
+ size_t pclen, sclen;
- for (stringstart = string;;)
- switch (c = *pattern++) {
+ for (stringstart = string;;) {
+ pclen = mbrtowc(&pc, pattern, MB_LEN_MAX, &patmbs);
+ if (pclen == (size_t)-1 || pclen == (size_t)-2)
+ return (FNM_NOMATCH);
+ pattern += pclen;
+ sclen = mbrtowc(&sc, string, MB_LEN_MAX, &strmbs);
+ if (sclen == (size_t)-1 || sclen == (size_t)-2) {
+ sc = (unsigned char)*string;
+ sclen = 1;
+ memset(&strmbs, 0, sizeof(strmbs));
+ }
+ switch (pc) {
case EOS:
- if ((flags & FNM_LEADING_DIR) && *string == '/')
+ if ((flags & FNM_LEADING_DIR) && sc == '/')
return (0);
- return (*string == EOS ? 0 : FNM_NOMATCH);
+ return (sc == EOS ? 0 : FNM_NOMATCH);
case '?':
- if (*string == EOS)
+ if (sc == EOS)
return (FNM_NOMATCH);
- if (*string == '/' && (flags & FNM_PATHNAME))
+ if (sc == '/' && (flags & FNM_PATHNAME))
return (FNM_NOMATCH);
- if (*string == '.' && (flags & FNM_PERIOD) &&
+ if (sc == '.' && (flags & FNM_PERIOD) &&
(string == stringstart ||
((flags & FNM_PATHNAME) && *(string - 1) == '/')))
return (FNM_NOMATCH);
- ++string;
+ string += sclen;
break;
case '*':
c = *pattern;
while (c == '*')
c = *++pattern;
- if (*string == '.' && (flags & FNM_PERIOD) &&
+ if (sc == '.' && (flags & FNM_PERIOD) &&
(string == stringstart ||
((flags & FNM_PATHNAME) && *(string - 1) == '/')))
return (FNM_NOMATCH);
}
/* General case, use recursion. */
- while ((test = *string) != EOS) {
- if (!fnmatch(pattern, string, flags & ~FNM_PERIOD))
+ while (sc != EOS) {
+ if (!fnmatch1(pattern, string,
+ flags & ~FNM_PERIOD, patmbs, strmbs))
return (0);
- if (test == '/' && flags & FNM_PATHNAME)
+ sclen = mbrtowc(&sc, string, MB_LEN_MAX,
+ &strmbs);
+ if (sclen == (size_t)-1 ||
+ sclen == (size_t)-2) {
+ sc = (unsigned char)*string;
+ sclen = 1;
+ memset(&strmbs, 0, sizeof(strmbs));
+ }
+ if (sc == '/' && flags & FNM_PATHNAME)
break;
- ++string;
+ string += sclen;
}
return (FNM_NOMATCH);
case '[':
- if (*string == EOS)
+ if (sc == EOS)
return (FNM_NOMATCH);
- if (*string == '/' && (flags & FNM_PATHNAME))
+ if (sc == '/' && (flags & FNM_PATHNAME))
return (FNM_NOMATCH);
- if (*string == '.' && (flags & FNM_PERIOD) &&
+ if (sc == '.' && (flags & FNM_PERIOD) &&
(string == stringstart ||
((flags & FNM_PATHNAME) && *(string - 1) == '/')))
return (FNM_NOMATCH);
- switch (rangematch(pattern, *string, flags, &newp)) {
+ switch (rangematch(pattern, sc, flags, &newp,
+ &patmbs)) {
case RANGE_ERROR:
goto norm;
case RANGE_MATCH:
case RANGE_NOMATCH:
return (FNM_NOMATCH);
}
- ++string;
+ string += sclen;
break;
case '\\':
if (!(flags & FNM_NOESCAPE)) {
- if ((c = *pattern++) == EOS) {
- c = '\\';
- --pattern;
- }
+ pclen = mbrtowc(&pc, pattern, MB_LEN_MAX,
+ &patmbs);
+ if (pclen == (size_t)-1 || pclen == (size_t)-2)
+ return (FNM_NOMATCH);
+ if (pclen == 0)
+ pc = '\\';
+ pattern += pclen;
}
/* FALLTHROUGH */
default:
norm:
- if (c == *string)
+ if (pc == sc)
;
else if ((flags & FNM_CASEFOLD) &&
- (tolower((unsigned char)c) ==
- tolower((unsigned char)*string)))
+ (towlower(pc) == towlower(sc)))
;
else
return (FNM_NOMATCH);
- string++;
+ string += sclen;
break;
}
+ }
/* NOTREACHED */
}
static int
-rangematch(pattern, test, flags, newp)
+rangematch(pattern, test, flags, newp, patmbs)
const char *pattern;
- char test;
+ wchar_t test;
int flags;
char **newp;
+ mbstate_t *patmbs;
{
int negate, ok;
- char c, c2;
+ wchar_t c, c2;
+ size_t pclen;
+ const char *origpat;
/*
* A bracket expression starting with an unquoted circumflex
++pattern;
if (flags & FNM_CASEFOLD)
- test = tolower((unsigned char)test);
+ test = towlower(test);
/*
* A right bracket shall lose its special meaning and represent
* -- POSIX.2 2.8.3.2
*/
ok = 0;
- c = *pattern++;
- do {
- if (c == '\\' && !(flags & FNM_NOESCAPE))
- c = *pattern++;
- if (c == EOS)
+ origpat = pattern;
+ for (;;) {
+ if (*pattern == ']' && pattern > origpat) {
+ pattern++;
+ break;
+ } else if (*pattern == '\0') {
return (RANGE_ERROR);
-
- if (c == '/' && (flags & FNM_PATHNAME))
+ } else if (*pattern == '/' && (flags & FNM_PATHNAME)) {
+ pattern++;
+ return (RANGE_NOMATCH);
+ } else if (*pattern == '\\' && !(flags & FNM_NOESCAPE))
+ pattern++;
+ pclen = mbrtowc(&c, pattern, MB_LEN_MAX, patmbs);
+ if (pclen == (size_t)-1 || pclen == (size_t)-2)
return (RANGE_NOMATCH);
+ pattern += pclen;
if (flags & FNM_CASEFOLD)
- c = tolower((unsigned char)c);
+ c = towlower(c);
- if (*pattern == '-'
- && (c2 = *(pattern+1)) != EOS && c2 != ']') {
- pattern += 2;
- if (c2 == '\\' && !(flags & FNM_NOESCAPE))
- c2 = *pattern++;
+ if (*pattern == '-' && *(pattern + 1) != EOS &&
+ *(pattern + 1) != ']') {
+ if (*++pattern == '\\' && !(flags & FNM_NOESCAPE))
+ if (*pattern != EOS)
+ pattern++;
+ pclen = mbrtowc(&c2, pattern, MB_LEN_MAX, patmbs);
+ if (pclen == (size_t)-1 || pclen == (size_t)-2)
+ return (RANGE_NOMATCH);
+ pattern += pclen;
if (c2 == EOS)
return (RANGE_ERROR);
if (flags & FNM_CASEFOLD)
- c2 = tolower((unsigned char)c2);
+ c2 = towlower(c2);
if (__collate_load_error ?
c <= test && test <= c2 :
ok = 1;
} else if (c == test)
ok = 1;
- } while ((c = *pattern++) != ']');
+ }
*newp = (char *)pattern;
return (ok == negate ? RANGE_NOMATCH : RANGE_MATCH);
--- /dev/null
+--- fnmatch.c.orig 2004-11-25 11:38:00.000000000 -0800
++++ fnmatch.c 2005-02-25 00:23:44.000000000 -0800
+@@ -40,6 +40,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/gen/fnmatch.c,v 1.16 2004/07/29 03:13:10 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ /*
+ * Function fnmatch() as specified in POSIX 1003.2-1992, section B.6.
+ * Compares a filename or pathname to a pattern.
+@@ -70,8 +72,8 @@
+ #define RANGE_NOMATCH 0
+ #define RANGE_ERROR (-1)
+
+-static int rangematch(const char *, wchar_t, int, char **, mbstate_t *);
+-static int fnmatch1(const char *, const char *, int, mbstate_t, mbstate_t);
++static int rangematch(const char *, wchar_t, int, char **, mbstate_t *, locale_t);
++static int fnmatch1(const char *, const char *, int, mbstate_t, mbstate_t, locale_t);
+
+ int
+ fnmatch(pattern, string, flags)
+@@ -80,14 +82,15 @@
+ {
+ static const mbstate_t initial;
+
+- return (fnmatch1(pattern, string, flags, initial, initial));
++ return (fnmatch1(pattern, string, flags, initial, initial, __current_locale()));
+ }
+
+ static int
+-fnmatch1(pattern, string, flags, patmbs, strmbs)
++fnmatch1(pattern, string, flags, patmbs, strmbs, loc)
+ const char *pattern, *string;
+ int flags;
+ mbstate_t patmbs, strmbs;
++ locale_t loc;
+ {
+ const char *stringstart;
+ char *newp;
+@@ -96,11 +99,11 @@
+ size_t pclen, sclen;
+
+ for (stringstart = string;;) {
+- pclen = mbrtowc(&pc, pattern, MB_LEN_MAX, &patmbs);
++ pclen = mbrtowc_l(&pc, pattern, MB_LEN_MAX, &patmbs, loc);
+ if (pclen == (size_t)-1 || pclen == (size_t)-2)
+ return (FNM_NOMATCH);
+ pattern += pclen;
+- sclen = mbrtowc(&sc, string, MB_LEN_MAX, &strmbs);
++ sclen = mbrtowc_l(&sc, string, MB_LEN_MAX, &strmbs, loc);
+ if (sclen == (size_t)-1 || sclen == (size_t)-2) {
+ sc = (unsigned char)*string;
+ sclen = 1;
+@@ -150,10 +153,10 @@
+ /* General case, use recursion. */
+ while (sc != EOS) {
+ if (!fnmatch1(pattern, string,
+- flags & ~FNM_PERIOD, patmbs, strmbs))
++ flags & ~FNM_PERIOD, patmbs, strmbs, loc))
+ return (0);
+- sclen = mbrtowc(&sc, string, MB_LEN_MAX,
+- &strmbs);
++ sclen = mbrtowc_l(&sc, string, MB_LEN_MAX,
++ &strmbs, loc);
+ if (sclen == (size_t)-1 ||
+ sclen == (size_t)-2) {
+ sc = (unsigned char)*string;
+@@ -176,7 +179,7 @@
+ return (FNM_NOMATCH);
+
+ switch (rangematch(pattern, sc, flags, &newp,
+- &patmbs)) {
++ &patmbs, loc)) {
+ case RANGE_ERROR:
+ goto norm;
+ case RANGE_MATCH:
+@@ -189,8 +192,8 @@
+ break;
+ case '\\':
+ if (!(flags & FNM_NOESCAPE)) {
+- pclen = mbrtowc(&pc, pattern, MB_LEN_MAX,
+- &patmbs);
++ pclen = mbrtowc_l(&pc, pattern, MB_LEN_MAX,
++ &patmbs, loc);
+ if (pclen == (size_t)-1 || pclen == (size_t)-2)
+ return (FNM_NOMATCH);
+ if (pclen == 0)
+@@ -203,7 +206,7 @@
+ if (pc == sc)
+ ;
+ else if ((flags & FNM_CASEFOLD) &&
+- (towlower(pc) == towlower(sc)))
++ (towlower_l(pc, loc) == towlower_l(sc, loc)))
+ ;
+ else
+ return (FNM_NOMATCH);
+@@ -215,12 +218,13 @@
+ }
+
+ static int
+-rangematch(pattern, test, flags, newp, patmbs)
++rangematch(pattern, test, flags, newp, patmbs, loc)
+ const char *pattern;
+ wchar_t test;
+ int flags;
+ char **newp;
+ mbstate_t *patmbs;
++ locale_t loc;
+ {
+ int negate, ok;
+ wchar_t c, c2;
+@@ -238,7 +242,7 @@
+ ++pattern;
+
+ if (flags & FNM_CASEFOLD)
+- test = towlower(test);
++ test = towlower_l(test, loc);
+
+ /*
+ * A right bracket shall lose its special meaning and represent
+@@ -258,20 +262,20 @@
+ return (RANGE_NOMATCH);
+ } else if (*pattern == '\\' && !(flags & FNM_NOESCAPE))
+ pattern++;
+- pclen = mbrtowc(&c, pattern, MB_LEN_MAX, patmbs);
++ pclen = mbrtowc_l(&c, pattern, MB_LEN_MAX, patmbs, loc);
+ if (pclen == (size_t)-1 || pclen == (size_t)-2)
+ return (RANGE_NOMATCH);
+ pattern += pclen;
+
+ if (flags & FNM_CASEFOLD)
+- c = towlower(c);
++ c = towlower_l(c, loc);
+
+ if (*pattern == '-' && *(pattern + 1) != EOS &&
+ *(pattern + 1) != ']') {
+ if (*++pattern == '\\' && !(flags & FNM_NOESCAPE))
+ if (*pattern != EOS)
+ pattern++;
+- pclen = mbrtowc(&c2, pattern, MB_LEN_MAX, patmbs);
++ pclen = mbrtowc_l(&c2, pattern, MB_LEN_MAX, patmbs, loc);
+ if (pclen == (size_t)-1 || pclen == (size_t)-2)
+ return (RANGE_NOMATCH);
+ pattern += pclen;
+@@ -279,12 +283,12 @@
+ return (RANGE_ERROR);
+
+ if (flags & FNM_CASEFOLD)
+- c2 = towlower(c2);
++ c2 = towlower_l(c2, loc);
+
+- if (__collate_load_error ?
++ if (loc->__collate_load_error ?
+ c <= test && test <= c2 :
+- __collate_range_cmp(c, test) <= 0
+- && __collate_range_cmp(test, c2) <= 0
++ __collate_range_cmp(c, test, loc) <= 0
++ && __collate_range_cmp(test, c2, loc) <= 0
+ )
+ ok = 1;
+ } else if (c == test)
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/lib/libc/gen/fpclassify.3,v 1.3 2003/06/01 19:19:59 ru Exp $
+.\" $FreeBSD: src/lib/libc/gen/fpclassify.3,v 1.5 2004/07/09 06:37:44 das Exp $
.\"
-.Dd February 12, 2003
+.Dd July 8, 2004
.Dt FPCLASSIFY 3
.Os
.Sh NAME
.Nm fpclassify , isfinite , isinf , isnan , isnormal
.Nd "classify a floating-point number"
.Sh LIBRARY
-.Lb libc
+.Lb libm
.Sh SYNOPSIS
.In math.h
.Ft int
.Vt double
arguments; these have been superseded by the macros
described above.
-.Sh BUGS
-By default, the DEC Alpha architecture does not support IEEE rounding.
-See the compiler documentation for additional details.
---- fpclassify.3.orig Fri Oct 3 17:12:53 2003
-+++ fpclassify.3 Fri Nov 7 15:46:28 2003
+--- /Volumes/XDisk/tmp/Libc/gen/FreeBSD/fpclassify.3.orig 2004-07-08 23:37:44.000000000 -0700
++++ /Volumes/XDisk/tmp/Libc/gen/FreeBSD/fpclassify.3 2004-10-24 17:08:28.000000000 -0700
@@ -107,15 +107,6 @@
macros conform to
.St -isoC-99 .
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/lib/libc/gen/ftok.3,v 1.15 2002/10/19 13:33:12 tjr Exp $
+.\" $FreeBSD: src/lib/libc/gen/ftok.3,v 1.16 2004/07/02 23:52:10 ru Exp $
.Dd June 24, 1994
.Os
.Dt FTOK 3
The specified
.Fa path
must specify an existing file that is accessible to the calling process
-or the call will fail. Also, note that links to files will return the
+or the call will fail.
+Also, note that links to files will return the
same key, given the same
.Fa id .
.Sh RETURN VALUES
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/gen/ftok.c,v 1.6 2002/02/01 00:57:29 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/gen/ftok.c,v 1.7 2004/06/01 06:53:07 tjr Exp $");
#include <sys/types.h>
#include <sys/stat.h>
key_t
ftok(path, id)
const char *path;
- char id;
+ int id;
{
struct stat st;
.\" SUCH DAMAGE.
.\"
.\" @(#)getcap.3 8.4 (Berkeley) 5/13/94
-.\" $FreeBSD: src/lib/libc/gen/getcap.3,v 1.23 2002/12/30 21:18:02 schweikh Exp $
+.\" $FreeBSD: src/lib/libc/gen/getcap.3,v 1.25 2004/07/03 22:30:08 ru Exp $
.\"
.Dd May 13, 1994
.Dt GETCAP 3
the current entry is removed from the database.
A call to
.Fn cgetset
-must precede the database traversal. It must be called before the
+must precede the database traversal.
+It must be called before the
.Fn cgetent
-call. If a sequential access is being performed (see below), it must be called
+call.
+If a sequential access is being performed (see below), it must be called
before the first sequential access call
.Fn ( cgetfirst
or
.Fa type .
A
.Fa type
-is specified using any single character. If a colon (`:') is used, an
+is specified using any single character.
+If a colon (`:') is used, an
untyped capability will be searched for (see below for explanation of
-types). A pointer to the value of
+types).
+A pointer to the value of
.Fa cap
in
.Fa buf
is returned on success,
.Dv NULL
if the requested capability couldn't be
-found. The end of the capability value is signaled by a `:' or
+found.
+The end of the capability value is signaled by a `:' or
.Tn ASCII
.Dv NUL
(see below for capability database syntax).
.Fn cgetfirst
or
.Fn cgetnext
-call. If there is no such previous call, the first record in the database is
+call.
+If there is no such previous call, the first record in the database is
returned.
Each record is returned in a
.Xr malloc 3 Ns \&'d
expansion is done (see
.Ic tc=
comments below).
-Upon completion of the database 0 is returned, 1 is returned upon successful
+Upon completion of the database 0 is returned, 1 is returned upon successful
return of record with possibly more remaining (we haven't reached the end of
the database yet), 2 is returned if the record contains an unresolved
.Ic tc
The
.Fn cgetclose
function closes the sequential access and frees any memory and file descriptors
-being used. Note that it does not erase the buffer pushed by a call to
+being used.
+Note that it does not erase the buffer pushed by a call to
.Fn cgetset .
.Sh CAPABILITY DATABASE SYNTAX
Capability databases are normally
.Tn ASCII
and may be edited with standard
-text editors. Blank lines and lines beginning with a `#' are comments
-and are ignored. Lines ending with a `\|\e' indicate that the next line
+text editors.
+Blank lines and lines beginning with a `#' are comments
+and are ignored.
+Lines ending with a `\|\e' indicate that the next line
is a continuation of the current line; the `\|\e' and following newline
-are ignored. Long lines are usually continued onto several physical
+are ignored.
+Long lines are usually continued onto several physical
lines by ending each line except the last with a `\|\e'.
.Pp
Capability databases consist of a series of records, one per logical
-line. Each record contains a variable number of `:'-separated fields
-(capabilities). Empty fields consisting entirely of white space
+line.
+Each record contains a variable number of `:'-separated fields
+(capabilities).
+Empty fields consisting entirely of white space
characters (spaces and tabs) are ignored.
.Pp
The first capability of each record specifies its names, separated by `|'
-characters. These names are used to reference records in the database.
+characters.
+These names are used to reference records in the database.
By convention, the last name is usually a comment and is not intended as
-a lookup tag. For example, the
+a lookup tag.
+For example, the
.Em vt100
record from the
.Xr termcap 5
does not exist
.El
.Pp
-Names consist of one or more characters. Names may contain any character
+Names consist of one or more characters.
+Names may contain any character
except `:', but it's usually best to restrict them to the printable
-characters and avoid use of graphics like `#', `=', `%', `@', etc. Types
+characters and avoid use of graphics like `#', `=', `%', `@', etc.
+Types
are single characters used to separate capability names from their
-associated typed values. Types may be any character except a `:'.
-Typically, graphics like `#', `=', `%', etc. are used. Values may be any
+associated typed values.
+Types may be any character except a `:'.
+Typically, graphics like `#', `=', `%', etc.\& are used.
+Values may be any
number of characters and may contain any character except `:'.
.Sh CAPABILITY DATABASE SEMANTICS
-Capability records describe a set of (name, value) bindings. Names may
-have multiple values bound to them. Different values for a name are
+Capability records describe a set of (name, value) bindings.
+Names may
+have multiple values bound to them.
+Different values for a name are
distinguished by their
.Fa types .
The
name and the type of the value.
.Pp
The types `#' and `=' are conventionally used to denote numeric and
-string typed values, but no restriction on those types is enforced. The
+string typed values, but no restriction on those types is enforced.
+The
functions
.Fn cgetnum
and
.Ic tc
capabilities and more than one
.Ic tc
-capability may be used in a record. A
+capability may be used in a record.
+A
.Ic tc
expansion scope (i.e., where the argument is searched for) contains the
file in which the
is declared and all subsequent files in the file array.
.Pp
When a database is searched for a capability record, the first matching
-record in the search is returned. When a record is scanned for a
+record in the search is returned.
+When a record is scanned for a
capability, the first matching capability is returned; the capability
.Ic :nameT@:
will hide any following definition of a value of type
.Ed
.Pp
The capability foo has two values bound to it (bar of type `%' and blah of
-type `^') and any other value bindings are hidden. The capability abc
+type `^') and any other value bindings are hidden.
+The capability abc
also has two values bound but only a value of type `$' is prevented from
being defined in the capability record more.
.Pp
from being seen, glork#200 is inherited from old, and blah and anything
defined by the record extensions is added to those definitions in old.
Note that the position of the fript=bar and who-cares@ definitions before
-tc=old is important here. If they were after, the definitions in old
+tc=old is important here.
+If they were after, the definitions in old
would take precedence.
.Sh CGETNUM AND CGETSTR SYNTAX AND SEMANTICS
Two types are predefined by
it is interpreted as an octal number.
Otherwise the number is interpreted as a decimal number.
.Pp
-String capability values may contain any character. Non-printable
+String capability values may contain any character.
+Non-printable
.Dv ASCII
codes, new lines, and colons may be conveniently represented by the use
of escape sequences:
.El
.Pp
A `\|\e' may be followed by up to three octal digits directly specifies
-the numeric code for a character. The use of
+the numeric code for a character.
+The use of
.Tn ASCII
.Dv NUL Ns s ,
while easily
--- /dev/null
+--- getcap.c.orig 2003-05-20 15:21:01.000000000 -0700
++++ getcap.c 2005-02-27 15:52:46.000000000 -0800
+@@ -40,6 +40,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/gen/getcap.c,v 1.19 2003/01/02 10:19:43 thomas Exp $");
+
++#include "xlocale_private.h"
++
+ #include "namespace.h"
+ #include <sys/types.h>
+
+@@ -70,7 +72,7 @@
+ static int gottoprec; /* Flag indicating retrieval of toprecord */
+
+ static int cdbget(DB *, char **, const char *);
+-static int getent(char **, u_int *, char **, int, const char *, int, char *);
++static int getent(char **, u_int *, char **, int, const char *, int, char *, locale_t);
+ static int nfcmp(char *, char *);
+
+ /*
+@@ -166,7 +168,7 @@
+ {
+ u_int dummy;
+
+- return (getent(buf, &dummy, db_array, -1, name, 0, NULL));
++ return (getent(buf, &dummy, db_array, -1, name, 0, NULL, __current_locale()));
+ }
+
+ /*
+@@ -189,7 +191,7 @@
+ */
+ static int
+ getent(char **cap, u_int *len, char **db_array, int fd, const char *name,
+- int depth, char *nfield)
++ int depth, char *nfield, locale_t loc)
+ {
+ DB *capdbp;
+ char *r_end, *rp, **db_p;
+@@ -428,7 +430,7 @@
+ tcend = s;
+
+ iret = getent(&icap, &ilen, db_p, fd, tc, depth+1,
+- NULL);
++ NULL, loc);
+ newicap = icap; /* Put into a register. */
+ newilen = ilen;
+ if (iret != 0) {
+@@ -652,6 +654,7 @@
+ int done, hadreaderr, i, savederrno, status;
+ char *cp, *line, *rp, *np, buf[BSIZE], nbuf[BSIZE];
+ u_int dummy;
++ locale_t loc = __current_locale();
+
+ if (dbp == NULL)
+ dbp = db_array;
+@@ -693,7 +696,7 @@
+ slash = 0;
+ continue;
+ }
+- if (isspace((unsigned char)*line) ||
++ if (isspace_l((unsigned char)*line, loc) ||
+ *line == ':' || *line == '#' || slash) {
+ if (line[len - 2] == '\\')
+ slash = 1;
+@@ -765,7 +768,7 @@
+ * rather than the duplicate entry record. This is a
+ * matter of semantics that should be resolved.
+ */
+- status = getent(bp, &dummy, db_array, -1, buf, 0, NULL);
++ status = getent(bp, &dummy, db_array, -1, buf, 0, NULL, loc);
+ if (status == -2 || status == -3)
+ (void)cgetclose();
+
.\" SUCH DAMAGE.
.\"
.\" @(#)getcwd.3 8.2 (Berkeley) 12/11/93
-.\" $FreeBSD: src/lib/libc/gen/getcwd.3,v 1.15 2001/10/01 16:08:51 ru Exp $
+.\" $FreeBSD: src/lib/libc/gen/getcwd.3,v 1.16 2003/09/08 19:57:14 ru Exp $
.\"
.Dd November 24, 1997
.Dt GETCWD 3
.Dv MAXPATHLEN
(as defined in the include
file
-.Aq Pa sys/param.h ) .
+.In sys/param.h ) .
Obviously,
.Fa buf
should be at least
static char sccsid[] = "@(#)getcwd.c 8.5 (Berkeley) 2/7/95";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/gen/getcwd.c,v 1.24 2003/01/10 02:58:25 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/gen/getcwd.c,v 1.25 2003/10/29 10:45:01 tjr Exp $");
#include "namespace.h"
#include <sys/param.h>
return (NULL);
ept = pt + ptsize;
}
-#if !defined(__NETBSD_SYSCALLS)
if (__getcwd(pt, ept - pt) == 0) {
if (*pt != '/') {
bpt = pt;
}
return (pt);
}
-#endif
bpt = ept - 1;
*bpt = '\0';
---- getcwd.c.orig Thu Jan 9 18:58:25 2003
-+++ getcwd.c Sat May 3 14:04:22 2003
+--- getcwd.c.orig 2003-10-29 02:45:01.000000000 -0800
++++ getcwd.c 2004-10-24 17:19:39.000000000 -0700
@@ -54,8 +54,6 @@
(dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \
(dp->d_name[1] == '.' && dp->d_name[2] == '\0')))
char *
getcwd(pt, size)
char *pt;
-@@ -95,20 +93,6 @@
+@@ -95,18 +93,6 @@
return (NULL);
ept = pt + ptsize;
}
--#if !defined(__NETBSD_SYSCALLS)
- if (__getcwd(pt, ept - pt) == 0) {
- if (*pt != '/') {
- bpt = pt;
- }
- return (pt);
- }
--#endif
bpt = ept - 1;
*bpt = '\0';
.\" SUCH DAMAGE.
.\"
.\" @(#)gethostname.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/gen/gethostname.3,v 1.13 2002/12/19 09:40:21 ru Exp $
+.\" $FreeBSD: src/lib/libc/gen/gethostname.3,v 1.16 2004/07/03 22:30:08 ru Exp $
.\"
-.Dd June 4, 1993
+.Dd August 18, 2003
.Dt GETHOSTNAME 3
.Os
.Sh NAME
.Sh SYNOPSIS
.In unistd.h
.Ft int
-.Fn gethostname "char *name" "int namelen"
+.Fn gethostname "char *name" "size_t namelen"
.Ft int
.Fn sethostname "const char *name" "int namelen"
.Sh DESCRIPTION
argument
specifies the size of the
.Fa name
-array. The returned name is null-terminated unless insufficient
-space is provided.
+array.
+The returned name is null-terminated unless insufficient space is provided.
.Pp
The
.Fn sethostname
.Fa namelen .
This call is restricted to the super-user and
is normally used only when the system is bootstrapped.
+.Pp
+Host names are limited to
+.Brq Dv HOST_NAME_MAX
+characters, not including the trailing null, currently 255.
.Sh RETURN VALUES
.Rv -std
.Sh ERRORS
.Fa namelen
argument gave an
invalid address.
+.It Bq Er ENAMETOOLONG
+The current host name is longer than
+.Fa namelen .
+(For
+.Fn gethostname
+only.)
.It Bq Er EPERM
-The caller tried to set the hostname and was not the super-user.
+The caller tried to set the host name and was not the super-user.
.El
.Sh SEE ALSO
-.Xr gethostid 3 ,
+.Xr sysconf 3 ,
.Xr sysctl 3
-.Sh BUGS
-Host names are limited to
-.Dv MAXHOSTNAMELEN
-(from
-.Ao Pa sys/param.h Ac )
-characters, currently 256.
-This includes the trailing
-.Dv NUL .
+.Sh STANDARDS
+The
+.Fn gethostname
+function conforms to
+.St -p1003.1-2001 .
+Callers should be aware that
+.Brq Dv HOST_NAME_MAX
+may be variable or infinite, but is guaranteed to be no less than
+.Brq Dv _POSIX_HOST_NAME_MAX .
+On older systems, this limit was defined in the non-standard header
+.In sys/param.h
+as
+.Dv MAXHOSTNAMELEN ,
+and counted the terminating null.
+The
+.Fn sethostname
+function and the error returns for
+.Fn gethostname
+are not standardized.
.Sh HISTORY
The
.Fn gethostname
function appeared in
.Bx 4.2 .
+The
+.Fa namelen
+argument to
+.Fn gethostname
+was changed to
+.Vt size_t
+in
+.Fx 5.2
+for alignment with
+.St -p1003.1-2001 .
static char sccsid[] = "@(#)gethostname.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/gen/gethostname.c,v 1.3 2002/03/22 21:52:05 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/gen/gethostname.c,v 1.5 2003/08/19 23:01:46 wollman Exp $");
#include <sys/param.h>
#include <sys/sysctl.h>
+#include <errno.h>
+
int
gethostname(name, namelen)
char *name;
- int namelen;
+ size_t namelen;
{
int mib[2];
- size_t size;
+
+ /* Kluge to avoid ABI breakage. */
+ namelen = (int)namelen;
mib[0] = CTL_KERN;
mib[1] = KERN_HOSTNAME;
- size = namelen;
- if (sysctl(mib, 2, name, &size, NULL, 0) == -1)
+ if (sysctl(mib, 2, name, &namelen, NULL, 0) == -1) {
+ if (errno == ENOMEM)
+ errno = ENAMETOOLONG;
return (-1);
+ }
return (0);
}
static char sccsid[] = "@(#)getlogin.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/gen/getlogin.c,v 1.8 2002/03/29 22:43:41 markm Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/gen/getlogin.c,v 1.9 2003/10/29 10:45:01 tjr Exp $");
#include <sys/param.h>
#include <errno.h>
static char logname[MAXLOGNAME];
if (_logname_valid == 0) {
-#ifdef __NETBSD_SYSCALLS
- if (_getlogin(logname, sizeof(logname) - 1) < 0) {
-#else
if (_getlogin(logname, sizeof(logname)) < 0) {
-#endif
*status = errno;
return (NULL);
}
--- /dev/null
+--- /Volumes/XDisk/tmp/Libc/gen/FreeBSD/getlogin.c.orig 2003-10-29 02:45:01.000000000 -0800
++++ /Volumes/XDisk/tmp/Libc/gen/FreeBSD/getlogin.c 2004-10-24 17:08:28.000000000 -0700
+@@ -87,7 +87,7 @@
+ }
+
+ int
+-getlogin_r(char *logname, int namelen)
++getlogin_r(char *logname, size_t namelen)
+ {
+ char *result;
+ int len;
.\" SUCH DAMAGE.
.\"
.\" @(#)glob.3 8.3 (Berkeley) 4/16/94
-.\" $FreeBSD: src/lib/libc/gen/glob.3,v 1.23 2003/02/04 16:28:04 mikeh Exp $
+.\" $FreeBSD: src/lib/libc/gen/glob.3,v 1.30 2004/09/01 23:28:27 tjr Exp $
.\"
-.Dd April 16, 1994
+.Dd September 1, 2004
.Dt GLOB 3
.Os
.Sh NAME
matching used by the shell.
.Pp
The include file
-.Pa glob.h
+.In glob.h
defines the structure type
.Fa glob_t ,
which contains at least the following fields:
.Tn OR
of any of the following
values defined in
-.Pa glob.h :
+.In glob.h :
.Bl -tag -width GLOB_ALTDIRFUNC
.It Dv GLOB_APPEND
Append pathnames generated to the ones from a previous call (or calls)
terminates due to an error, it sets errno and returns one of the
following non-zero constants, which are defined in the include
file
-.Aq Pa glob.h :
+.In glob.h :
.Bl -tag -width GLOB_NOCHECK
.It Dv GLOB_NOSPACE
An attempt to allocate memory failed, or if
.Xr fnmatch 3 ,
.Xr regexp 3
.Sh STANDARDS
-The
+The current implementation of the
.Fn glob
-function is expected to be
-.St -p1003.2
-compatible with the exception
-that the flags
+function
+.Em does not
+conform to
+.St -p1003.2 .
+Collating symbol expressions, equivalence class expressions and
+character class expressions are not supported.
+.Pp
+The flags
.Dv GLOB_ALTDIRFUNC ,
.Dv GLOB_BRACE ,
.Dv GLOB_LIMIT ,
.Fa gl_matchc
and
.Fa gl_flags
-should not be used by applications striving for strict
+are extensions to the
.Tn POSIX
+standard and
+should not be used by applications striving for strict
conformance.
.Sh HISTORY
The
static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/gen/glob.c,v 1.20 2002/07/17 04:58:09 mikeh Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/gen/glob.c,v 1.22 2004/07/29 03:48:52 tjr Exp $");
/*
* glob(3) -- a superset of the one defined in POSIX 1003.2.
* Number of matches in the current invocation of glob.
*/
+/*
+ * Some notes on multibyte character support:
+ * 1. Patterns with illegal byte sequences match nothing - even if
+ * GLOB_NOCHECK is specified.
+ * 2. Illegal byte sequences in filenames are handled by treating them as
+ * single-byte characters with a value of the first byte of the sequence
+ * cast to wchar_t.
+ * 3. State-dependent encodings are not currently supported.
+ */
+
#include <sys/param.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#include <glob.h>
+#include <limits.h>
#include <pwd.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <wchar.h>
#include "collate.h"
#ifndef DEBUG
-#define M_QUOTE 0x8000
-#define M_PROTECT 0x4000
-#define M_MASK 0xffff
-#define M_ASCII 0x00ff
+#define M_QUOTE 0x8000000000ULL
+#define M_PROTECT 0x4000000000ULL
+#define M_MASK 0xffffffffffULL
+#define M_CHAR 0x00ffffffffULL
-typedef u_short Char;
+typedef uint_fast64_t Char;
#else
#define M_QUOTE 0x80
#define M_PROTECT 0x40
#define M_MASK 0xff
-#define M_ASCII 0x7f
+#define M_CHAR 0x7f
typedef char Char;
#endif
-#define CHAR(c) ((Char)((c)&M_ASCII))
+#define CHAR(c) ((Char)((c)&M_CHAR))
#define META(c) ((Char)((c)|M_QUOTE))
#define M_ALL META('*')
#define M_END META(']')
static int g_Ctoc(const Char *, char *, u_int);
static int g_lstat(Char *, struct stat *, glob_t *);
static DIR *g_opendir(Char *, glob_t *);
-static Char *g_strchr(Char *, int);
+static Char *g_strchr(Char *, wchar_t);
#ifdef notdef
static Char *g_strcat(Char *, const Char *);
#endif
glob_t *pglob;
{
const u_char *patnext;
- int c, limit;
- Char *bufnext, *bufend, patbuf[MAXPATHLEN];
+ int limit;
+ Char *bufnext, *bufend, patbuf[MAXPATHLEN], prot;
+ mbstate_t mbs;
+ wchar_t wc;
+ size_t clen;
patnext = (u_char *) pattern;
if (!(flags & GLOB_APPEND)) {
bufnext = patbuf;
bufend = bufnext + MAXPATHLEN - 1;
- if (flags & GLOB_NOESCAPE)
- while (bufnext < bufend && (c = *patnext++) != EOS)
- *bufnext++ = c;
- else {
+ if (flags & GLOB_NOESCAPE) {
+ memset(&mbs, 0, sizeof(mbs));
+ while (bufend - bufnext >= MB_CUR_MAX) {
+ clen = mbrtowc(&wc, patnext, MB_LEN_MAX, &mbs);
+ if (clen == (size_t)-1 || clen == (size_t)-2)
+ return (GLOB_NOMATCH);
+ else if (clen == 0)
+ break;
+ *bufnext++ = wc;
+ patnext += clen;
+ }
+ } else {
/* Protect the quoted characters. */
- while (bufnext < bufend && (c = *patnext++) != EOS)
- if (c == QUOTE) {
- if ((c = *patnext++) == EOS) {
- c = QUOTE;
- --patnext;
+ memset(&mbs, 0, sizeof(mbs));
+ while (bufend - bufnext >= MB_CUR_MAX) {
+ if (*patnext == QUOTE) {
+ if (*++patnext == EOS) {
+ *bufnext++ = QUOTE | M_PROTECT;
+ continue;
}
- *bufnext++ = c | M_PROTECT;
- }
- else
- *bufnext++ = c;
+ prot = M_PROTECT;
+ } else
+ prot = 0;
+ clen = mbrtowc(&wc, patnext, MB_LEN_MAX, &mbs);
+ if (clen == (size_t)-1 || clen == (size_t)-2)
+ return (GLOB_NOMATCH);
+ else if (clen == 0)
+ break;
+ *bufnext++ = wc | prot;
+ patnext += clen;
+ }
}
*bufnext = EOS;
* we're not running setuid or setgid) and then trying
* the password file
*/
- if (
-#ifndef __NETBSD_SYSCALLS
- issetugid() != 0 ||
-#endif
+ if (issetugid() != 0 ||
(h = getenv("HOME")) == NULL) {
if (((h = getlogin()) != NULL &&
(pwd = getpwnam(h)) != NULL) ||
while ((dp = (*readdirfunc)(dirp))) {
u_char *sc;
Char *dc;
+ wchar_t wc;
+ size_t clen;
+ mbstate_t mbs;
/* Initial DOT must be matched literally. */
if (dp->d_name[0] == DOT && *pattern != DOT)
continue;
+ memset(&mbs, 0, sizeof(mbs));
dc = pathend;
sc = (u_char *) dp->d_name;
- while (dc < pathend_last && (*dc++ = *sc++) != EOS)
- ;
+ while (dc < pathend_last) {
+ clen = mbrtowc(&wc, sc, MB_LEN_MAX, &mbs);
+ if (clen == (size_t)-1 || clen == (size_t)-2) {
+ wc = *sc;
+ clen = 1;
+ memset(&mbs, 0, sizeof(mbs));
+ }
+ if ((*dc++ = wc) == EOS)
+ break;
+ sc += clen;
+ }
if (!match(pathend, pattern, restpattern)) {
*pathend = EOS;
continue;
for (p = path; *p++;)
continue;
- len = (size_t)(p - path);
+ len = MB_CUR_MAX * (size_t)(p - path); /* XXX overallocation */
if ((copy = malloc(len)) != NULL) {
if (g_Ctoc(path, copy, len)) {
free(copy);
static Char *
g_strchr(str, ch)
Char *str;
- int ch;
+ wchar_t ch;
{
do {
if (*str == ch)
char *buf;
u_int len;
{
-
- while (len--) {
- if ((*buf++ = *str++) == '\0')
+ mbstate_t mbs;
+ size_t clen;
+
+ memset(&mbs, 0, sizeof(mbs));
+ while (len >= MB_CUR_MAX) {
+ clen = wcrtomb(buf, *str, &mbs);
+ if (clen == (size_t)-1)
+ return (1);
+ if (*str == L'\0')
return (0);
+ str++;
+ buf += clen;
+ len -= clen;
}
return (1);
}
--- /dev/null
+--- glob.c.orig 2004-11-25 11:38:01.000000000 -0800
++++ glob.c 2005-02-24 16:02:34.000000000 -0800
+@@ -40,6 +40,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/gen/glob.c,v 1.22 2004/07/29 03:48:52 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ /*
+ * glob(3) -- a superset of the one defined in POSIX 1003.2.
+ *
+@@ -144,24 +146,24 @@
+
+
+ static int compare(const void *, const void *);
+-static int g_Ctoc(const Char *, char *, u_int);
+-static int g_lstat(Char *, struct stat *, glob_t *);
+-static DIR *g_opendir(Char *, glob_t *);
++static int g_Ctoc(const Char *, char *, u_int, locale_t);
++static int g_lstat(Char *, struct stat *, glob_t *, locale_t);
++static DIR *g_opendir(Char *, glob_t *, locale_t);
+ static Char *g_strchr(Char *, wchar_t);
+ #ifdef notdef
+ static Char *g_strcat(Char *, const Char *);
+ #endif
+-static int g_stat(Char *, struct stat *, glob_t *);
+-static int glob0(const Char *, glob_t *, int *);
+-static int glob1(Char *, glob_t *, int *);
+-static int glob2(Char *, Char *, Char *, Char *, glob_t *, int *);
+-static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, int *);
+-static int globextend(const Char *, glob_t *, int *);
++static int g_stat(Char *, struct stat *, glob_t *, locale_t);
++static int glob0(const Char *, glob_t *, int *, locale_t);
++static int glob1(Char *, glob_t *, int *, locale_t);
++static int glob2(Char *, Char *, Char *, Char *, glob_t *, int *, locale_t);
++static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, int *, locale_t);
++static int globextend(const Char *, glob_t *, int *, locale_t);
+ static const Char *
+ globtilde(const Char *, Char *, size_t, glob_t *);
+-static int globexp1(const Char *, glob_t *, int *);
+-static int globexp2(const Char *, const Char *, glob_t *, int *, int *);
+-static int match(Char *, Char *, Char *);
++static int globexp1(const Char *, glob_t *, int *, locale_t);
++static int globexp2(const Char *, const Char *, glob_t *, int *, int *, locale_t);
++static int match(Char *, Char *, Char *, locale_t);
+ #ifdef DEBUG
+ static void qprintf(const char *, Char *);
+ #endif
+@@ -178,6 +180,8 @@
+ mbstate_t mbs;
+ wchar_t wc;
+ size_t clen;
++ locale_t loc = __current_locale();
++ int mb_cur_max = MB_CUR_MAX_L(loc);
+
+ patnext = (u_char *) pattern;
+ if (!(flags & GLOB_APPEND)) {
+@@ -200,8 +204,8 @@
+ bufend = bufnext + MAXPATHLEN - 1;
+ if (flags & GLOB_NOESCAPE) {
+ memset(&mbs, 0, sizeof(mbs));
+- while (bufend - bufnext >= MB_CUR_MAX) {
+- clen = mbrtowc(&wc, patnext, MB_LEN_MAX, &mbs);
++ while (bufend - bufnext >= mb_cur_max) {
++ clen = mbrtowc_l(&wc, (const char *)patnext, MB_LEN_MAX, &mbs, loc);
+ if (clen == (size_t)-1 || clen == (size_t)-2)
+ return (GLOB_NOMATCH);
+ else if (clen == 0)
+@@ -212,7 +216,7 @@
+ } else {
+ /* Protect the quoted characters. */
+ memset(&mbs, 0, sizeof(mbs));
+- while (bufend - bufnext >= MB_CUR_MAX) {
++ while (bufend - bufnext >= mb_cur_max) {
+ if (*patnext == QUOTE) {
+ if (*++patnext == EOS) {
+ *bufnext++ = QUOTE | M_PROTECT;
+@@ -221,7 +225,7 @@
+ prot = M_PROTECT;
+ } else
+ prot = 0;
+- clen = mbrtowc(&wc, patnext, MB_LEN_MAX, &mbs);
++ clen = mbrtowc_l(&wc, (const char *)patnext, MB_LEN_MAX, &mbs, loc);
+ if (clen == (size_t)-1 || clen == (size_t)-2)
+ return (GLOB_NOMATCH);
+ else if (clen == 0)
+@@ -233,9 +237,9 @@
+ *bufnext = EOS;
+
+ if (flags & GLOB_BRACE)
+- return globexp1(patbuf, pglob, &limit);
++ return globexp1(patbuf, pglob, &limit, loc);
+ else
+- return glob0(patbuf, pglob, &limit);
++ return glob0(patbuf, pglob, &limit, loc);
+ }
+
+ /*
+@@ -244,23 +248,24 @@
+ * characters
+ */
+ static int
+-globexp1(pattern, pglob, limit)
++globexp1(pattern, pglob, limit, loc)
+ const Char *pattern;
+ glob_t *pglob;
+ int *limit;
++ locale_t loc;
+ {
+ const Char* ptr = pattern;
+ int rv;
+
+ /* Protect a single {}, for find(1), like csh */
+ if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS)
+- return glob0(pattern, pglob, limit);
++ return glob0(pattern, pglob, limit, loc);
+
+ while ((ptr = (const Char *) g_strchr((Char *) ptr, LBRACE)) != NULL)
+- if (!globexp2(ptr, pattern, pglob, &rv, limit))
++ if (!globexp2(ptr, pattern, pglob, &rv, limit, loc))
+ return rv;
+
+- return glob0(pattern, pglob, limit);
++ return glob0(pattern, pglob, limit, loc);
+ }
+
+
+@@ -270,10 +275,11 @@
+ * If it fails then it tries to glob the rest of the pattern and returns.
+ */
+ static int
+-globexp2(ptr, pattern, pglob, rv, limit)
++globexp2(ptr, pattern, pglob, rv, limit, loc)
+ const Char *ptr, *pattern;
+ glob_t *pglob;
+ int *rv, *limit;
++ locale_t loc;
+ {
+ int i;
+ Char *lm, *ls;
+@@ -310,7 +316,7 @@
+
+ /* Non matching braces; just glob the pattern */
+ if (i != 0 || *pe == EOS) {
+- *rv = glob0(patbuf, pglob, limit);
++ *rv = glob0(patbuf, pglob, limit, loc);
+ return 0;
+ }
+
+@@ -357,7 +363,7 @@
+ #ifdef DEBUG
+ qprintf("globexp2:", patbuf);
+ #endif
+- *rv = globexp1(patbuf, pglob, limit);
++ *rv = globexp1(patbuf, pglob, limit, loc);
+
+ /* move after the comma, to the next string */
+ pl = pm + 1;
+@@ -447,10 +453,11 @@
+ * if things went well, nonzero if errors occurred.
+ */
+ static int
+-glob0(pattern, pglob, limit)
++glob0(pattern, pglob, limit, loc)
+ const Char *pattern;
+ glob_t *pglob;
+ int *limit;
++ locale_t loc;
+ {
+ const Char *qpatnext;
+ int c, err, oldpathc;
+@@ -512,7 +519,7 @@
+ qprintf("glob0:", patbuf);
+ #endif
+
+- if ((err = glob1(patbuf, pglob, limit)) != 0)
++ if ((err = glob1(patbuf, pglob, limit, loc)) != 0)
+ return(err);
+
+ /*
+@@ -525,7 +532,7 @@
+ if (((pglob->gl_flags & GLOB_NOCHECK) ||
+ ((pglob->gl_flags & GLOB_NOMAGIC) &&
+ !(pglob->gl_flags & GLOB_MAGCHAR))))
+- return(globextend(pattern, pglob, limit));
++ return(globextend(pattern, pglob, limit, loc));
+ else
+ return(GLOB_NOMATCH);
+ }
+@@ -543,10 +550,11 @@
+ }
+
+ static int
+-glob1(pattern, pglob, limit)
++glob1(pattern, pglob, limit, loc)
+ Char *pattern;
+ glob_t *pglob;
+ int *limit;
++ locale_t loc;
+ {
+ Char pathbuf[MAXPATHLEN];
+
+@@ -554,7 +562,7 @@
+ if (*pattern == EOS)
+ return(0);
+ return(glob2(pathbuf, pathbuf, pathbuf + MAXPATHLEN - 1,
+- pattern, pglob, limit));
++ pattern, pglob, limit, loc));
+ }
+
+ /*
+@@ -563,10 +571,11 @@
+ * meta characters.
+ */
+ static int
+-glob2(pathbuf, pathend, pathend_last, pattern, pglob, limit)
++glob2(pathbuf, pathend, pathend_last, pattern, pglob, limit, loc)
+ Char *pathbuf, *pathend, *pathend_last, *pattern;
+ glob_t *pglob;
+ int *limit;
++ locale_t loc;
+ {
+ struct stat sb;
+ Char *p, *q;
+@@ -579,13 +588,13 @@
+ for (anymeta = 0;;) {
+ if (*pattern == EOS) { /* End of pattern? */
+ *pathend = EOS;
+- if (g_lstat(pathbuf, &sb, pglob))
++ if (g_lstat(pathbuf, &sb, pglob, loc))
+ return(0);
+
+ if (((pglob->gl_flags & GLOB_MARK) &&
+ pathend[-1] != SEP) && (S_ISDIR(sb.st_mode)
+ || (S_ISLNK(sb.st_mode) &&
+- (g_stat(pathbuf, &sb, pglob) == 0) &&
++ (g_stat(pathbuf, &sb, pglob, loc) == 0) &&
+ S_ISDIR(sb.st_mode)))) {
+ if (pathend + 1 > pathend_last)
+ return (GLOB_ABORTED);
+@@ -593,7 +602,7 @@
+ *pathend = EOS;
+ }
+ ++pglob->gl_matchc;
+- return(globextend(pathbuf, pglob, limit));
++ return(globextend(pathbuf, pglob, limit, loc));
+ }
+
+ /* Find end of next segment, copy tentatively to pathend. */
+@@ -617,16 +626,17 @@
+ }
+ } else /* Need expansion, recurse. */
+ return(glob3(pathbuf, pathend, pathend_last, pattern, p,
+- pglob, limit));
++ pglob, limit, loc));
+ }
+ /* NOTREACHED */
+ }
+
+ static int
+-glob3(pathbuf, pathend, pathend_last, pattern, restpattern, pglob, limit)
++glob3(pathbuf, pathend, pathend_last, pattern, restpattern, pglob, limit, loc)
+ Char *pathbuf, *pathend, *pathend_last, *pattern, *restpattern;
+ glob_t *pglob;
+ int *limit;
++ locale_t loc;
+ {
+ struct dirent *dp;
+ DIR *dirp;
+@@ -646,10 +656,10 @@
+ *pathend = EOS;
+ errno = 0;
+
+- if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
++ if ((dirp = g_opendir(pathbuf, pglob, loc)) == NULL) {
+ /* TODO: don't call for ENOENT or ENOTDIR? */
+ if (pglob->gl_errfunc) {
+- if (g_Ctoc(pathbuf, buf, sizeof(buf)))
++ if (g_Ctoc(pathbuf, buf, sizeof(buf), loc))
+ return (GLOB_ABORTED);
+ if (pglob->gl_errfunc(buf, errno) ||
+ pglob->gl_flags & GLOB_ERR)
+@@ -679,7 +689,7 @@
+ dc = pathend;
+ sc = (u_char *) dp->d_name;
+ while (dc < pathend_last) {
+- clen = mbrtowc(&wc, sc, MB_LEN_MAX, &mbs);
++ clen = mbrtowc_l(&wc, (const char *)sc, MB_LEN_MAX, &mbs, loc);
+ if (clen == (size_t)-1 || clen == (size_t)-2) {
+ wc = *sc;
+ clen = 1;
+@@ -689,12 +699,12 @@
+ break;
+ sc += clen;
+ }
+- if (!match(pathend, pattern, restpattern)) {
++ if (!match(pathend, pattern, restpattern, loc)) {
+ *pathend = EOS;
+ continue;
+ }
+ err = glob2(pathbuf, --dc, pathend_last, restpattern,
+- pglob, limit);
++ pglob, limit, loc);
+ if (err)
+ break;
+ }
+@@ -722,10 +732,11 @@
+ * gl_pathv points to (gl_offs + gl_pathc + 1) items.
+ */
+ static int
+-globextend(path, pglob, limit)
++globextend(path, pglob, limit, loc)
+ const Char *path;
+ glob_t *pglob;
+ int *limit;
++ locale_t loc;
+ {
+ char **pathv;
+ int i;
+@@ -760,9 +771,9 @@
+
+ for (p = path; *p++;)
+ continue;
+- len = MB_CUR_MAX * (size_t)(p - path); /* XXX overallocation */
++ len = MB_CUR_MAX_L(loc) * (size_t)(p - path); /* XXX overallocation */
+ if ((copy = malloc(len)) != NULL) {
+- if (g_Ctoc(path, copy, len)) {
++ if (g_Ctoc(path, copy, len, loc)) {
+ free(copy);
+ return (GLOB_NOSPACE);
+ }
+@@ -777,8 +788,9 @@
+ * pattern causes a recursion level.
+ */
+ static int
+-match(name, pat, patend)
++match(name, pat, patend, loc)
+ Char *name, *pat, *patend;
++ locale_t loc;
+ {
+ int ok, negate_range;
+ Char c, k;
+@@ -790,7 +802,7 @@
+ if (pat == patend)
+ return(1);
+ do
+- if (match(name, pat, patend))
++ if (match(name, pat, patend, loc))
+ return(1);
+ while (*name++ != EOS);
+ return(0);
+@@ -806,10 +818,10 @@
+ ++pat;
+ while (((c = *pat++) & M_MASK) != M_END)
+ if ((*pat & M_MASK) == M_RNG) {
+- if (__collate_load_error ?
++ if (loc->__collate_load_error ?
+ CHAR(c) <= CHAR(k) && CHAR(k) <= CHAR(pat[1]) :
+- __collate_range_cmp(CHAR(c), CHAR(k)) <= 0
+- && __collate_range_cmp(CHAR(k), CHAR(pat[1])) <= 0
++ __collate_range_cmp(CHAR(c), CHAR(k), loc) <= 0
++ && __collate_range_cmp(CHAR(k), CHAR(pat[1]), loc) <= 0
+ )
+ ok = 1;
+ pat += 2;
+@@ -846,16 +858,17 @@
+ }
+
+ static DIR *
+-g_opendir(str, pglob)
++g_opendir(str, pglob, loc)
+ Char *str;
+ glob_t *pglob;
++ locale_t loc;
+ {
+ char buf[MAXPATHLEN];
+
+ if (!*str)
+ strcpy(buf, ".");
+ else {
+- if (g_Ctoc(str, buf, sizeof(buf)))
++ if (g_Ctoc(str, buf, sizeof(buf), loc))
+ return (NULL);
+ }
+
+@@ -866,14 +879,15 @@
+ }
+
+ static int
+-g_lstat(fn, sb, pglob)
++g_lstat(fn, sb, pglob, loc)
+ Char *fn;
+ struct stat *sb;
+ glob_t *pglob;
++ locale_t loc;
+ {
+ char buf[MAXPATHLEN];
+
+- if (g_Ctoc(fn, buf, sizeof(buf))) {
++ if (g_Ctoc(fn, buf, sizeof(buf), loc)) {
+ errno = ENAMETOOLONG;
+ return (-1);
+ }
+@@ -883,14 +897,15 @@
+ }
+
+ static int
+-g_stat(fn, sb, pglob)
++g_stat(fn, sb, pglob, loc)
+ Char *fn;
+ struct stat *sb;
+ glob_t *pglob;
++ locale_t loc;
+ {
+ char buf[MAXPATHLEN];
+
+- if (g_Ctoc(fn, buf, sizeof(buf))) {
++ if (g_Ctoc(fn, buf, sizeof(buf), loc)) {
+ errno = ENAMETOOLONG;
+ return (-1);
+ }
+@@ -912,17 +927,19 @@
+ }
+
+ static int
+-g_Ctoc(str, buf, len)
++g_Ctoc(str, buf, len, loc)
+ const Char *str;
+ char *buf;
+ u_int len;
++ locale_t loc;
+ {
+ mbstate_t mbs;
+ size_t clen;
++ int mb_cur_max = MB_CUR_MAX_L(loc);
+
+ memset(&mbs, 0, sizeof(mbs));
+- while (len >= MB_CUR_MAX) {
+- clen = wcrtomb(buf, *str, &mbs);
++ while (len >= mb_cur_max) {
++ clen = wcrtomb_l(buf, *str, &mbs, loc);
+ if (clen == (size_t)-1)
+ return (1);
+ if (*str == L'\0')
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/lib/libc/gen/lockf.3,v 1.11 2002/12/18 10:13:54 ru Exp $
+.\" $FreeBSD: src/lib/libc/gen/lockf.3,v 1.13 2004/07/02 23:52:10 ru Exp $
.\"
.Dd December 19, 1997
.Dt LOCKF 3
The section to be locked or unlocked starts at the current
offset in the file and extends forward for a positive size or backward
for a negative size (the preceding bytes up to but not including the
-current offset). However, it is not permitted to lock a section that
+current offset).
+However, it is not permitted to lock a section that
starts or extends before the beginning of the file.
If
.Fa size
Locked sections will be unlocked starting
at the current file offset through
.Fa size
-bytes or to the end of file if size is 0. When all of a locked section
+bytes or to the end of file if size is 0.
+When all of a locked section
is not released (that is, when the beginning or end of the area to be
unlocked falls within a locked section), the remaining portions of
that section are still locked by the process.
off_t, when the process has an existing lock in which size is 0 and
which includes the last byte of the requested section, will be treated
as a request to unlock from the start of the requested section with a
-size equal to 0. Otherwise an
+size equal to 0.
+Otherwise an
.Dv F_ULOCK
request will attempt to unlock only the requested section.
.Pp
A potential for deadlock occurs if a process controlling a locked
region is put to sleep by attempting to lock the locked region of
-another process. This implementation detects that sleeping until a
+another process.
+This implementation detects that sleeping until a
locked region is unlocked would cause a deadlock and fails with an
.Er EDEADLK
error.
.Pp
The
.Fn lockf ,
-.Xr fcntl 2
+.Xr fcntl 2 ,
and
.Xr flock 2
-locks may be safely used concurrently.
+locks are compatible.
+Processes using different locking interfaces can cooperate
+over the same file safely.
+However, only one of such interfaces should be used within
+the same process.
+If a file is locked by a process through
+.Xr flock 2 ,
+any record within the file will be seen as locked
+from the viewpoint of another process using
+.Xr fcntl 2
+or
+.Fn lockf ,
+and vice versa.
.Pp
Blocking on a section is interrupted by any signal.
.Sh RETURN VALUES
static char sccsid[] = "@(#)opendir.c 8.8 (Berkeley) 5/1/95";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/gen/opendir.c,v 1.19 2003/01/04 00:18:50 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/gen/opendir.c,v 1.22 2004/08/14 17:46:10 stefanf Exp $");
#include "namespace.h"
#include <sys/param.h>
(dirp = malloc(sizeof(DIR) + sizeof(struct _telldir))) == NULL)
goto fail;
- dirp->dd_td = (void *)dirp + sizeof(DIR);
+ dirp->dd_td = (struct _telldir *)((char *)dirp + sizeof(DIR));
LIST_INIT(&dirp->dd_td->td_locq);
dirp->dd_td->td_loccnt = 0;
if (_fstatfs(fd, &sfb) < 0)
goto fail;
- unionstack = !strcmp(sfb.f_fstypename, "union")
+ unionstack = !strcmp(sfb.f_fstypename, "unionfs")
|| (sfb.f_flags & MNT_UNION);
} else {
unionstack = 0;
dirp->dd_size = ddptr - dirp->dd_buf;
} else {
dirp->dd_len = incr;
+ dirp->dd_size = 0;
dirp->dd_buf = malloc(dirp->dd_len);
if (dirp->dd_buf == NULL)
goto fail;
---- opendir.c.orig Fri Jan 3 16:18:50 2003
-+++ opendir.c Sat May 3 15:00:52 2003
+--- /Volumes/XDisk/tmp/Libc/gen/FreeBSD/opendir.c.orig 2004-08-14 10:46:10.000000000 -0700
++++ /Volumes/XDisk/tmp/Libc/gen/FreeBSD/opendir.c 2004-10-24 17:08:28.000000000 -0700
@@ -48,6 +48,7 @@
#include <stdlib.h>
#include <string.h>
#include "un-namespace.h"
#include "telldir.h"
-@@ -268,7 +269,7 @@
+@@ -269,7 +270,7 @@
dirp->dd_loc = 0;
dirp->dd_fd = fd;
dirp->dd_flags = flags;
.\" SUCH DAMAGE.
.\"
.\" @(#)popen.3 8.2 (Berkeley) 5/3/95
-.\" $FreeBSD: src/lib/libc/gen/popen.3,v 1.15 2003/01/03 05:21:59 tjr Exp $
+.\" $FreeBSD: src/lib/libc/gen/popen.3,v 1.16 2003/06/08 10:01:51 charnier Exp $
.\"
.Dd May 3, 1995
.Dt POPEN 3
function waits for the associated process to terminate
and returns the exit status of the command
as returned by
-.Fn wait4 .
+.Xr wait4 2 .
.Sh RETURN VALUES
The
.Fn popen
already
.Dq pclosed ,
or if
-.Xr wait4
+.Xr wait4 2
returns an error.
.Sh ERRORS
The
static char sccsid[] = "@(#)raise.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/gen/raise.c,v 1.3 2002/03/22 21:52:05 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/gen/raise.c,v 1.4 2003/07/19 05:22:56 davidxu Exp $");
#include <signal.h>
#include <unistd.h>
+__weak_reference(__raise, raise);
+__weak_reference(__raise, _raise);
+
int
-raise(s)
+__raise(s)
int s;
{
return(kill(getpid(), s));
.\" to anyone/anything when using this software.
.\"
.\" @(#)rand48.3 V1.0 MB 8 Oct 1993
-.\" $FreeBSD: src/lib/libc/gen/rand48.3,v 1.15 2002/12/19 09:40:21 ru Exp $
+.\" $FreeBSD: src/lib/libc/gen/rand48.3,v 1.16 2004/07/02 23:52:10 ru Exp $
.\"
.Dd October 8, 1993
.Dt RAND48 3
.Fn nrand48
functions
return values of type long in the range
-[0, 2**31-1]. The high-order (31) bits of
+[0, 2**31-1].
+The high-order (31) bits of
r(n+1) are loaded into the lower bits of the returned value, with
the topmost (sign) bit set to zero.
.Pp
.Fn jrand48
functions
return values of type long in the range
-[-2**31, 2**31-1]. The high-order (32) bits of
+[-2**31, 2**31-1].
+The high-order (32) bits of
r(n+1) are loaded into the returned value.
.Pp
The
and
.Fn mrand48
functions
-use an internal buffer to store r(n). For these functions
+use an internal buffer to store r(n).
+For these functions
the initial value of r(0) = 0x1234abcd330e = 20017429951246.
.Pp
On the other hand,
--- /dev/null
+--- readpassphrase.c.orig 2003-05-20 15:21:02.000000000 -0700
++++ readpassphrase.c 2005-02-24 17:00:36.000000000 -0800
+@@ -33,6 +33,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/gen/readpassphrase.c,v 1.6 2002/03/09 03:16:41 green Exp $");
+
++#include "xlocale_private.h"
++
+ #include "namespace.h"
+ #include <ctype.h>
+ #include <errno.h>
+@@ -59,6 +61,7 @@
+ struct termios term, oterm;
+ struct sigaction sa, saveint, savehup, savequit, saveterm;
+ struct sigaction savetstp, savettin, savettou;
++ locale_t loc = __current_locale();
+
+ /* I suppose we could alloc on demand in this case (XXX). */
+ if (bufsiz == 0) {
+@@ -115,11 +118,11 @@
+ if (p < end) {
+ if ((flags & RPP_SEVENBIT))
+ ch &= 0x7f;
+- if (isalpha(ch)) {
++ if (isalpha_l(ch, loc)) {
+ if ((flags & RPP_FORCELOWER))
+- ch = tolower(ch);
++ ch = tolower_l(ch, loc);
+ if ((flags & RPP_FORCEUPPER))
+- ch = toupper(ch);
++ ch = toupper_l(ch, loc);
+ }
+ *p++ = ch;
+ }
.\" SUCH DAMAGE.
.\"
.\" @(#)signal.3 8.3 (Berkeley) 4/19/94
-.\" $FreeBSD: src/lib/libc/gen/signal.3,v 1.32 2002/12/19 09:40:21 ru Exp $
+.\" $FreeBSD: src/lib/libc/gen/signal.3,v 1.38 2004/07/03 22:30:08 ru Exp $
.\"
-.Dd April 19, 1994
+.Dd June 7, 2004
.Dt SIGNAL 3
.Os
.Sh NAME
.Lb libc
.Sh SYNOPSIS
.In signal.h
-.\" The following is Quite Ugly, but syntactically correct. Don't try to
+.\" The following is Quite Ugly, but syntactically correct.
+.\" Don't try to
.\" fix it.
.Ft void \*(lp*
.Fn signal "int sig" "void \*(lp*func\*(rp\*(lpint\*(rp\*(rp\*(rp\*(lpint"
.Pp
Signals allow the manipulation of a process from outside its
domain as well as allowing the process to manipulate itself or
-copies of itself (children). There are two general types of signals:
+copies of itself (children).
+There are two general types of signals:
those that cause termination of a process and those that do not.
Signals which cause termination of a program might result from
an irrecoverable error or might be the result of a user at a terminal
function allows for a signal to be caught, to be ignored, or to generate
an interrupt.
These signals are defined in the file
-.Aq Pa signal.h :
-.Bl -column SIGVTALARMXX "create core imagexxx"
-.It Sy "Name Default Action Description"
-.It Dv SIGHUP Ta "terminate process" Ta "terminal line hangup"
-.It Dv SIGINT Ta "terminate process" Ta "interrupt program"
-.It Dv SIGQUIT Ta "create core image" Ta "quit program"
-.It Dv SIGILL Ta "create core image" Ta "illegal instruction"
-.It Dv SIGTRAP Ta "create core image" Ta "trace trap"
-.It Dv SIGABRT Ta "create core image" Ta "abort program"
+.In signal.h :
+.Bl -column No ".Dv SIGVTALRM" "create core image"
+.It Sy "No Name Default Action Description"
+.It 1 Ta Dv SIGHUP Ta "terminate process" Ta "terminal line hangup"
+.It 2 Ta Dv SIGINT Ta "terminate process" Ta "interrupt program"
+.It 3 Ta Dv SIGQUIT Ta "create core image" Ta "quit program"
+.It 4 Ta Dv SIGILL Ta "create core image" Ta "illegal instruction"
+.It 5 Ta Dv SIGTRAP Ta "create core image" Ta "trace trap"
+.It 6 Ta Dv SIGABRT Ta "create core image" Ta "abort program"
(formerly
.Dv SIGIOT )
-.It Dv SIGEMT Ta "create core image" Ta "emulate instruction executed"
-.It Dv SIGFPE Ta "create core image" Ta "floating-point exception"
-.It Dv SIGKILL Ta "terminate process" Ta "kill program"
-.It Dv SIGBUS Ta "create core image" Ta "bus error"
-.It Dv SIGSEGV Ta "create core image" Ta "segmentation violation"
-.It Dv SIGSYS Ta "create core image" Ta "non-existent system call invoked"
-.It Dv SIGPIPE Ta "terminate process" Ta "write on a pipe with no reader"
-.It Dv SIGALRM Ta "terminate process" Ta "real-time timer expired"
-.It Dv SIGTERM Ta "terminate process" Ta "software termination signal"
-.It Dv SIGURG Ta "discard signal" Ta "urgent condition present on socket"
-.It Dv SIGSTOP Ta "stop process" Ta "stop (cannot be caught or ignored)"
-.It Dv SIGTSTP Ta "stop process" Ta "stop signal generated from keyboard"
-.It Dv SIGCONT Ta "discard signal" Ta "continue after stop"
-.It Dv SIGCHLD Ta "discard signal" Ta "child status has changed"
-.It Dv SIGTTIN Ta "stop process" Ta "background read attempted from control terminal"
-.It Dv SIGTTOU Ta "stop process" Ta "background write attempted to control terminal"
-.It Dv SIGIO Ta "discard signal" Ta Tn "I/O"
+.It 7 Ta Dv SIGEMT Ta "create core image" Ta "emulate instruction executed"
+.It 8 Ta Dv SIGFPE Ta "create core image" Ta "floating-point exception"
+.It 9 Ta Dv SIGKILL Ta "terminate process" Ta "kill program"
+.It 10 Ta Dv SIGBUS Ta "create core image" Ta "bus error"
+.It 11 Ta Dv SIGSEGV Ta "create core image" Ta "segmentation violation"
+.It 12 Ta Dv SIGSYS Ta "create core image" Ta "non-existent system call invoked"
+.It 13 Ta Dv SIGPIPE Ta "terminate process" Ta "write on a pipe with no reader"
+.It 14 Ta Dv SIGALRM Ta "terminate process" Ta "real-time timer expired"
+.It 15 Ta Dv SIGTERM Ta "terminate process" Ta "software termination signal"
+.It 16 Ta Dv SIGURG Ta "discard signal" Ta "urgent condition present on socket"
+.It 17 Ta Dv SIGSTOP Ta "stop process" Ta "stop (cannot be caught or ignored)"
+.It 18 Ta Dv SIGTSTP Ta "stop process" Ta "stop signal generated from keyboard"
+.It 19 Ta Dv SIGCONT Ta "discard signal" Ta "continue after stop"
+.It 20 Ta Dv SIGCHLD Ta "discard signal" Ta "child status has changed"
+.It 21 Ta Dv SIGTTIN Ta "stop process" Ta "background read attempted from"
+control terminal
+.It 22 Ta Dv SIGTTOU Ta "stop process" Ta "background write attempted to"
+control terminal
+.It 23 Ta Dv SIGIO Ta "discard signal" Ta Tn "I/O"
is possible on a descriptor (see
.Xr fcntl 2 )
-.It Dv SIGXCPU Ta "terminate process" Ta "cpu time limit exceeded (see"
+.It 24 Ta Dv SIGXCPU Ta "terminate process" Ta "cpu time limit exceeded (see"
.Xr setrlimit 2 )
-.It Dv SIGXFSZ Ta "terminate process" Ta "file size limit exceeded (see"
+.It 25 Ta Dv SIGXFSZ Ta "terminate process" Ta "file size limit exceeded (see"
.Xr setrlimit 2 )
-.It Dv SIGVTALRM Ta "terminate process" Ta "virtual time alarm (see"
+.It 26 Ta Dv SIGVTALRM Ta "terminate process" Ta "virtual time alarm (see"
.Xr setitimer 2 )
-.It Dv SIGPROF Ta "terminate process" Ta "profiling timer alarm (see"
+.It 27 Ta Dv SIGPROF Ta "terminate process" Ta "profiling timer alarm (see"
.Xr setitimer 2 )
-.It Dv SIGWINCH Ta "discard signal" Ta "Window size change"
-.It Dv SIGINFO Ta "discard signal" Ta "status request from keyboard"
-.It Dv SIGUSR1 Ta "terminate process" Ta "User defined signal 1"
-.It Dv SIGUSR2 Ta "terminate process" Ta "User defined signal 2"
+.It 28 Ta Dv SIGWINCH Ta "discard signal" Ta "Window size change"
+.It 29 Ta Dv SIGINFO Ta "discard signal" Ta "status request from keyboard"
+.It 30 Ta Dv SIGUSR1 Ta "terminate process" Ta "User defined signal 1"
+.It 31 Ta Dv SIGUSR2 Ta "terminate process" Ta "User defined signal 2"
+.It 32 Ta Dv SIGTHR Ta "terminate process" Ta "thread interrupt"
.El
.Pp
The
function;
ignored signals remain ignored.
.Pp
+If a process explicitly specifies
+.Dv SIG_IGN
+as the action for the signal
+.Dv SIGCHLD ,
+the system will not create zombie processes when children
+of the calling process exit.
+As a consequence, the system will discard the exit status
+from the child processes.
+If the calling process subsequently issues a call to
+.Xr wait 2
+or equivalent, it will block until all of the calling process's
+children terminate, and then return a value of \-1 with
+.Va errno
+set to
+.Er ECHILD .
+.Pp
See
.Xr sigaction 2
for a list of functions
that are considered safe for use in signal handlers.
.Sh RETURN VALUES
The previous action is returned on a successful call.
-Otherwise, SIG_ERR is returned and the global variable
+Otherwise, SIG_ERR is returned and the global variable
.Va errno
is set to indicate the error.
.Sh ERRORS
.Xr sigaltstack 2 ,
.Xr sigprocmask 2 ,
.Xr sigsuspend 2 ,
+.Xr wait 2 ,
.Xr fpsetmask 3 ,
.Xr setjmp 3 ,
.Xr siginterrupt 3 ,
.Fn signal
facility appeared in
.Bx 4.0 .
+The option to avoid the creation of child zombies through ignoring
+.Dv SIGCHLD
+appeared in
+.Fx 5.0 .
---- signal.3.orig Tue May 20 15:21:03 2003
-+++ signal.3 Sun Nov 30 22:08:18 2003
-@@ -47,9 +47,7 @@
+--- /Volumes/XDisk/tmp/Libc/gen/FreeBSD/signal.3.orig 2004-07-03 15:30:08.000000000 -0700
++++ /Volumes/XDisk/tmp/Libc/gen/FreeBSD/signal.3 2004-10-24 17:08:28.000000000 -0700
+@@ -48,9 +48,7 @@
.Ft void \*(lp*
.Fn signal "int sig" "void \*(lp*func\*(rp\*(lpint\*(rp\*(rp\*(rp\*(lpint"
.Pp
.\" SUCH DAMAGE.
.\"
.\" @(#)sleep.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/gen/sleep.3,v 1.15 2001/10/01 16:08:51 ru Exp $
+.\" $FreeBSD: src/lib/libc/gen/sleep.3,v 1.16 2004/07/02 23:52:10 ru Exp $
.\"
.Dd February 13, 1998
.Dt SLEEP 3
If the
.Fn sleep
function returns because the requested time has elapsed, the value
-returned will be zero. If the
+returned will be zero.
+If the
.Fn sleep
function returns due to the delivery of a signal, the value returned
will be the unslept amount (the requested time minus the time actually
-Index: sleep.3
-===================================================================
-RCS file: /cvs/root/Libc/gen/FreeBSD/sleep.3,v
-retrieving revision 1.2
-diff -u -r1.2 sleep.3
---- sleep.3 2003/05/20 22:21:03 1.2
-+++ sleep.3 2003/10/20 23:09:28
+--- /Volumes/XDisk/tmp/Libc/gen/FreeBSD/sleep.3.orig 2004-07-02 16:52:10.000000000 -0700
++++ /Volumes/XDisk/tmp/Libc/gen/FreeBSD/sleep.3 2004-10-24 17:08:28.000000000 -0700
@@ -37,7 +37,7 @@
.Os
.Sh NAME
.\" SUCH DAMAGE.
.\"
.\" @(#)sysconf.3 8.3 (Berkeley) 4/19/94
-.\" $FreeBSD: src/lib/libc/gen/sysconf.3,v 1.18 2003/09/08 19:57:14 ru Exp $
+.\" $FreeBSD: src/lib/libc/gen/sysconf.3,v 1.20 2003/12/23 18:42:55 trhodes Exp $
.\"
.Dd June 18, 2001
.Dt SYSCONF 3
---- sysconf.c.orig Sun Nov 17 00:54:29 2002
-+++ sysconf.c Wed Apr 14 17:09:36 2004
+--- sysconf.c 2004-04-15 16:50:28.000000000 -0700
++++ /Volumes/dee/Len/Build/Libc-3845788.roots/Libc-3845788.sym/sysconf-fbsd.c 2004-11-30 18:08:26.000000000 -0800
@@ -45,6 +45,8 @@
#include <sys/sysctl.h>
#include <sys/resource.h>
#define _PATH_ZONEINFO TZDIR /* from tzfile.h */
-@@ -76,7 +78,7 @@
+@@ -75,8 +77,9 @@
+ int name;
{
struct rlimit rl;
++ quad_t qdvalue; /* for kern.sysv.shmmin */
size_t len;
- int mib[2], sverrno, value;
+ int mib[3], sverrno, value;
long defaultresult;
const char *path;
-@@ -254,76 +256,94 @@
+@@ -254,76 +257,94 @@
return (_POSIX_TIMERS);
#endif
case _SC_AIO_LISTIO_MAX:
case _SC_ADVISORY_INFO:
#if _POSIX_ADVISORY_INFO == 0
#error "_POSIX_ADVISORY_INFO"
-@@ -348,18 +368,10 @@
+@@ -348,18 +369,10 @@
#else
return (_POSIX_CPUTIME);
#endif
case _SC_HOST_NAME_MAX:
return (MAXHOSTNAMELEN - 1); /* does not include \0 */
case _SC_LOGIN_NAME_MAX:
-@@ -370,10 +382,8 @@
+@@ -370,10 +383,8 @@
#else
return (_POSIX_MONOTONIC_CLOCK);
#endif
case _SC_READER_WRITER_LOCKS:
return (_POSIX_READER_WRITER_LOCKS);
case _SC_REGEXP:
-@@ -413,7 +423,11 @@
+@@ -410,10 +421,16 @@
+ return (_POSIX_THREAD_PROCESS_SHARED);
+ case _SC_THREAD_SAFE_FUNCTIONS:
+ return (_POSIX_THREAD_SAFE_FUNCTIONS);
++ case _SC_THREAD_SPORADIC_SERVER:
++ return (_POSIX_THREAD_SPORADIC_SERVER);
case _SC_THREAD_STACK_MIN:
return (PTHREAD_STACK_MIN);
case _SC_THREAD_THREADS_MAX:
case _SC_TIMEOUTS:
return (_POSIX_TIMEOUTS);
case _SC_THREADS:
-@@ -493,9 +507,13 @@
+@@ -425,16 +442,14 @@
+ #else
+ return (_POSIX_TRACE);
+ #endif
+-#if _POSIX_TRACE > -1
+ case _SC_TRACE_EVENT_FILTER:
+ return (_POSIX_TRACE_EVENT_FILTER);
+ case _SC_TRACE_INHERIT:
+ return (_POSIX_TRACE_INHERIT);
+ case _SC_TRACE_LOG:
+ return (_POSIX_TRACE_LOG);
+-#endif
+ case _SC_TTY_NAME_MAX:
+- path = _PATH_DEV;
++ path = "/"; // should be _PATH_DEV (PR-3624562)
+ goto do_NAME_MAX;
+ case _SC_TYPED_MEMORY_OBJECTS:
+ #if _POSIX_TYPED_MEMORY_OBJECTS == 0
+@@ -493,9 +508,13 @@
case _SC_ATEXIT_MAX:
return (ATEXIT_SIZE);
case _SC_IOV_MAX:
mib[1] = KERN_IOV_MAX;
break;
+#else
-+ return (-1);
++ return (IOV_MAX);
+#endif
case _SC_XOPEN_CRYPT:
return (_XOPEN_CRYPT);
case _SC_XOPEN_ENH_I18N:
-@@ -568,11 +586,25 @@
+@@ -531,7 +550,8 @@
+ #endif
+ case _SC_XOPEN_SHM:
+ sverrno = errno;
+- if (sysctlbyname("kern.ipc.shmmin", &value, &len, NULL,
++ len = sizeof(qdvalue);
++ if (sysctlbyname("kern.sysv.shmmin", &qdvalue, &len, NULL,
+ 0) == -1) {
+ errno = sverrno;
+ return (-1);
+@@ -568,11 +588,25 @@
return (_POSIX_IPV6);
#endif
.\" SUCH DAMAGE.
.\"
.\" @(#)sysctl.3 8.4 (Berkeley) 5/9/95
-.\" $FreeBSD: src/lib/libc/gen/sysctl.3,v 1.57 2002/12/19 09:40:21 ru Exp $
+.\" $FreeBSD: src/lib/libc/gen/sysctl.3,v 1.63 2004/07/02 23:52:10 ru Exp $
.\"
.Dd January 23, 2001
.Dt SYSCTL 3
The
.Fn sysctlbyname
function accepts an ASCII representation of the name and internally
-looks up the integer name vector. Apart from that, it behaves the same
+looks up the integer name vector.
+Apart from that, it behaves the same
as the standard
.Fn sysctl
function.
.Ed
.Pp
The top level names are defined with a CTL_ prefix in
-.Aq Pa sys/sysctl.h ,
+.In sys/sysctl.h ,
and are as follows.
The next and subsequent levels down are found in the include files
listed here, and described in separate sections below.
.Pp
.Bl -column CTLXMACHDEPXXX "Next level namesXXXXXX" -offset indent
.It Sy "Name Next level names Description"
-.It "CTL\_DEBUG sys/sysctl.h Debugging"
-.It "CTL\_VFS sys/mount.h File system"
-.It "CTL\_HW sys/sysctl.h Generic CPU, I/O"
-.It "CTL\_KERN sys/sysctl.h High kernel limits"
-.It "CTL\_MACHDEP sys/sysctl.h Machine dependent"
-.It "CTL\_NET sys/socket.h Networking"
-.It "CTL\_USER sys/sysctl.h User-level"
-.It "CTL\_VM vm/vm_param.h Virtual memory"
+.It "CTL_DEBUG sys/sysctl.h Debugging"
+.It "CTL_VFS sys/mount.h File system"
+.It "CTL_HW sys/sysctl.h Generic CPU, I/O"
+.It "CTL_KERN sys/sysctl.h High kernel limits"
+.It "CTL_MACHDEP sys/sysctl.h Machine dependent"
+.It "CTL_NET sys/socket.h Networking"
+.It "CTL_USER sys/sysctl.h User-level"
+.It "CTL_VM vm/vm_param.h Virtual memory"
.El
.Pp
For example, the following retrieves the maximum number of processes allowed
privilege may change the value.
.Bl -column "Second level nameXXXXXX" integerXXX -offset indent
.It Sy "Second level name Type Changeable"
-.It "HW\_MACHINE string no"
-.It "HW\_MODEL string no"
-.It "HW\_NCPU integer no"
-.It "HW\_BYTEORDER integer no"
-.It "HW\_PHYSMEM integer no"
-.It "HW\_USERMEM integer no"
-.It "HW\_PAGESIZE integer no"
-.It "HW\_FLOATINGPOINT integer no"
-.It "HW\_MACHINE\_ARCH string no"
-.\".It "HW\_DISKNAMES integer no"
-.\".It "HW\_DISKSTATS integer no"
+.It "HW_MACHINE string no"
+.It "HW_MODEL string no"
+.It "HW_NCPU integer no"
+.It "HW_BYTEORDER integer no"
+.It "HW_PHYSMEM integer no"
+.It "HW_USERMEM integer no"
+.It "HW_PAGESIZE integer no"
+.It "HW_FLOATINGPOINT integer no"
+.It "HW_MACHINE_ARCH string no"
+.\".It "HW_DISKNAMES integer no"
+.\".It "HW_DISKSTATS integer no"
.El
.Pp
.Bl -tag -width 6n
information.
.Bl -column "KERNXMAXFILESPERPROCXXX" "struct clockrateXXX" -offset indent
.It Sy "Second level name Type Changeable"
-.It "KERN\_ARGMAX integer no"
-.It "KERN\_BOOTFILE string yes"
-.It "KERN\_BOOTTIME struct timeval no"
-.It "KERN\_CLOCKRATE struct clockinfo no"
-.It "KERN\_FILE struct file no"
-.It "KERN\_HOSTID integer yes"
-.It "KERN\_HOSTNAME string yes"
-.It "KERN\_JOB\_CONTROL integer no"
-.It "KERN\_MAXFILES integer yes"
-.It "KERN\_MAXFILESPERPROC integer yes"
-.It "KERN\_MAXPROC integer no"
-.It "KERN\_MAXPROCPERUID integer yes"
-.It "KERN\_MAXVNODES integer yes"
-.It "KERN\_NGROUPS integer no"
-.It "KERN\_NISDOMAINNAME string yes"
-.It "KERN\_OSRELDATE integer no"
-.It "KERN\_OSRELEASE string no"
-.It "KERN\_OSREV integer no"
-.It "KERN\_OSTYPE string no"
-.It "KERN\_POSIX1 integer no"
-.It "KERN\_PROC struct proc no"
-.It "KERN\_PROF node not applicable"
-.It "KERN\_QUANTUM integer yes"
-.It "KERN\_SAVED\_IDS integer no"
-.It "KERN\_SECURELVL integer raise only"
-.It "KERN\_UPDATEINTERVAL integer no"
-.It "KERN\_VERSION string no"
-.It "KERN\_VNODE struct vnode no"
+.It "KERN_ARGMAX integer no"
+.It "KERN_BOOTFILE string yes"
+.It "KERN_BOOTTIME struct timeval no"
+.It "KERN_CLOCKRATE struct clockinfo no"
+.It "KERN_FILE struct file no"
+.It "KERN_HOSTID integer yes"
+.It "KERN_HOSTNAME string yes"
+.It "KERN_JOB_CONTROL integer no"
+.It "KERN_MAXFILES integer yes"
+.It "KERN_MAXFILESPERPROC integer yes"
+.It "KERN_MAXPROC integer no"
+.It "KERN_MAXPROCPERUID integer yes"
+.It "KERN_MAXVNODES integer yes"
+.It "KERN_NGROUPS integer no"
+.It "KERN_NISDOMAINNAME string yes"
+.It "KERN_OSRELDATE integer no"
+.It "KERN_OSRELEASE string no"
+.It "KERN_OSREV integer no"
+.It "KERN_OSTYPE string no"
+.It "KERN_POSIX1 integer no"
+.It "KERN_PROC struct proc no"
+.It "KERN_PROF node not applicable"
+.It "KERN_QUANTUM integer yes"
+.It "KERN_SAVED_IDS integer no"
+.It "KERN_SECURELVL integer raise only"
+.It "KERN_UPDATEINTERVAL integer no"
+.It "KERN_VERSION string no"
+.It "KERN_VNODE struct vnode no"
.El
.Pp
.Bl -tag -width 6n
.It Li KERN_NISDOMAINNAME
The name of the current YP/NIS domain.
.It Li KERN_OSRELDATE
-The system release date in YYYYMM format
-(January 1996 is encoded as 199601).
+The kernel release version in the format
+.Ar M Ns Ar mm Ns Ar R Ns Ar xx ,
+where
+.Ar M
+is the major version,
+.Ar mm
+is the two digit minor version,
+.Ar R
+is 0 if release branch, otherwise 1,
+and
+.Ar xx
+is updated when the available APIs change.
+.Pp
+The userland release version is available from
+.In osreldate.h ;
+parse this file if you need to get the release version of
+the currently installed userland.
.It Li KERN_OSRELEASE
The system release string.
.It Li KERN_OSREV
The third and fourth level names are as follows:
.Bl -column "Third level nameXXXXXX" "Fourth level is:XXXXXX" -offset indent
.It "Third level name Fourth level is:"
-.It "KERN\_PROC\_ALL None"
-.It "KERN\_PROC\_PID A process ID"
-.It "KERN\_PROC\_PGRP A process group"
-.It "KERN\_PROC\_TTY A tty device"
-.It "KERN\_PROC\_UID A user ID"
-.It "KERN\_PROC\_RUID A real user ID"
+.It "KERN_PROC_ALL None"
+.It "KERN_PROC_PID A process ID"
+.It "KERN_PROC_PGRP A process group"
+.It "KERN_PROC_TTY A tty device"
+.It "KERN_PROC_UID A user ID"
+.It "KERN_PROC_RUID A real user ID"
.El
.Pp
If the third level name is KERN_PROC_ARGS then the command line argument
-array is returned in a flattened form, i.e. zero-terminated arguments
+array is returned in a flattened form, i.e., zero-terminated arguments
follow each other.
The total size of array is returned.
It is also possible for a process to set its own process title this way.
.Bl -column "Third level nameXXXXXX" "Fourth level is:XXXXXX" -offset indent
.It Sy "Third level name Fourth level is:"
-.It "KERN\_PROC\_ARGS A process ID"
+.It "KERN_PROC_ARGS A process ID"
.El
.It Li KERN_PROF
Return profiling information about the kernel.
privilege may change the value.
.Bl -column "GPROFXGMONPARAMXXX" "struct gmonparamXXX" -offset indent
.It Sy "Third level name Type Changeable"
-.It "GPROF\_STATE integer yes"
-.It "GPROF\_COUNT u_short[\|] yes"
-.It "GPROF\_FROMS u_short[\|] yes"
-.It "GPROF\_TOS struct tostruct yes"
-.It "GPROF\_GMONPARAM struct gmonparam no"
+.It "GPROF_STATE integer yes"
+.It "GPROF_COUNT u_short[\|] yes"
+.It "GPROF_FROMS u_short[\|] yes"
+.It "GPROF_TOS struct tostruct yes"
+.It "GPROF_GMONPARAM struct gmonparam no"
.El
.Pp
The variables are as follows:
privilege may change the value.
.Bl -column "Second level nameXXXXXX" "routing messagesXXX" -offset indent
.It Sy "Second level name Type Changeable"
-.It "PF\_ROUTE routing messages no"
-.It "PF\_INET IPv4 values yes"
-.It "PF\_INET6 IPv6 values yes"
+.It "PF_ROUTE routing messages no"
+.It "PF_INET IPv4 values yes"
+.It "PF_INET6 IPv6 values yes"
.El
.Pp
.Bl -tag -width 6n
The fifth and sixth level names are as follows:
.Bl -column "Fifth level nameXXXXXX" "Sixth level is:XXX" -offset indent
.It Sy "Fifth level name Sixth level is:"
-.It "NET\_RT\_FLAGS rtflags"
-.It "NET\_RT\_DUMP None"
-.It "NET\_RT\_IFLIST 0 or if_index"
+.It "NET_RT_FLAGS rtflags"
+.It "NET_RT_DUMP None"
+.It "NET_RT_IFLIST 0 or if_index"
+.It "NET_RT_IFMALIST 0 or if_index"
.El
+.Pp
+The
+.Dv NET_RT_IFMALIST
+name returns information about multicast group memberships on all interfaces
+if 0 is specified, or for the interface specified by
+.Va if_index .
.It Li PF_INET
Get or set various global information about the IPv4
(Internet Protocol version 4).
privilege may change the value.
.Bl -column "USER_COLL_WEIGHTS_MAXXXX" "integerXXX" -offset indent
.It Sy "Second level name Type Changeable"
-.It "USER\_BC\_BASE\_MAX integer no"
-.It "USER\_BC\_DIM\_MAX integer no"
-.It "USER\_BC\_SCALE\_MAX integer no"
-.It "USER\_BC\_STRING\_MAX integer no"
-.It "USER\_COLL\_WEIGHTS\_MAX integer no"
-.It "USER\_CS\_PATH string no"
-.It "USER\_EXPR\_NEST\_MAX integer no"
-.It "USER\_LINE\_MAX integer no"
-.It "USER\_POSIX2\_CHAR\_TERM integer no"
-.It "USER\_POSIX2\_C\_BIND integer no"
-.It "USER\_POSIX2\_C\_DEV integer no"
-.It "USER\_POSIX2\_FORT\_DEV integer no"
-.It "USER\_POSIX2\_FORT\_RUN integer no"
-.It "USER\_POSIX2\_LOCALEDEF integer no"
-.It "USER\_POSIX2\_SW\_DEV integer no"
-.It "USER\_POSIX2\_UPE integer no"
-.It "USER\_POSIX2\_VERSION integer no"
-.It "USER\_RE\_DUP\_MAX integer no"
-.It "USER\_STREAM\_MAX integer no"
-.It "USER\_TZNAME\_MAX integer no"
+.It "USER_BC_BASE_MAX integer no"
+.It "USER_BC_DIM_MAX integer no"
+.It "USER_BC_SCALE_MAX integer no"
+.It "USER_BC_STRING_MAX integer no"
+.It "USER_COLL_WEIGHTS_MAX integer no"
+.It "USER_CS_PATH string no"
+.It "USER_EXPR_NEST_MAX integer no"
+.It "USER_LINE_MAX integer no"
+.It "USER_POSIX2_CHAR_TERM integer no"
+.It "USER_POSIX2_C_BIND integer no"
+.It "USER_POSIX2_C_DEV integer no"
+.It "USER_POSIX2_FORT_DEV integer no"
+.It "USER_POSIX2_FORT_RUN integer no"
+.It "USER_POSIX2_LOCALEDEF integer no"
+.It "USER_POSIX2_SW_DEV integer no"
+.It "USER_POSIX2_UPE integer no"
+.It "USER_POSIX2_VERSION integer no"
+.It "USER_RE_DUP_MAX integer no"
+.It "USER_STREAM_MAX integer no"
+.It "USER_TZNAME_MAX integer no"
.El
.Bl -tag -width 6n
.Pp
privilege may change the value.
.Bl -column "Second level nameXXXXXX" "struct loadavgXXX" -offset indent
.It Sy "Second level name Type Changeable"
-.It "VM\_LOADAVG struct loadavg no"
-.It "VM\_METER struct vmtotal no"
-.It "VM\_PAGEOUT\_ALGORITHM integer yes"
-.It "VM\_SWAPPING\_ENABLED integer maybe"
-.It "VM\_V\_CACHE\_MAX integer yes"
-.It "VM\_V\_CACHE\_MIN integer yes"
-.It "VM\_V\_FREE\_MIN integer yes"
-.It "VM\_V\_FREE\_RESERVED integer yes"
-.It "VM\_V\_FREE\_TARGET integer yes"
-.It "VM\_V\_INACTIVE\_TARGET integer yes"
-.It "VM\_V\_PAGEOUT\_FREE\_MIN integer yes"
+.It "VM_LOADAVG struct loadavg no"
+.It "VM_METER struct vmtotal no"
+.It "VM_PAGEOUT_ALGORITHM integer yes"
+.It "VM_SWAPPING_ENABLED integer maybe"
+.It "VM_V_CACHE_MAX integer yes"
+.It "VM_V_CACHE_MIN integer yes"
+.It "VM_V_FREE_MIN integer yes"
+.It "VM_V_FREE_RESERVED integer yes"
+.It "VM_V_FREE_TARGET integer yes"
+.It "VM_V_INACTIVE_TARGET integer yes"
+.It "VM_V_PAGEOUT_FREE_MIN integer yes"
.El
.Pp
.Bl -tag -width 6n
0 if the statistics-based page management algorithm is in use
or 1 if the near-LRU algorithm is in use.
.It Li VM_SWAPPING_ENABLED
-1 if process swapping is enabled or 0 if disabled. This variable is
+1 if process swapping is enabled or 0 if disabled.
+This variable is
permanently set to 0 if the kernel was built with swapping disabled.
.It Li VM_V_CACHE_MAX
Maximum desired size of the cache queue.
.It Li VM_V_CACHE_MIN
-Minimum desired size of the cache queue. If the cache queue size
+Minimum desired size of the cache queue.
+If the cache queue size
falls very far below this value, the pageout daemon is awakened.
.It Li VM_V_FREE_MIN
Minimum amount of memory (cache memory plus free memory)
pageout daemon tries to maintain.
.It Li VM_V_INACTIVE_TARGET
The desired number of inactive pages that the pageout daemon should
-achieve when it runs. Inactive pages can be quickly inserted into
+achieve when it runs.
+Inactive pages can be quickly inserted into
process address space when needed.
.It Li VM_V_PAGEOUT_FREE_MIN
If the amount of free and cache memory falls below this value, the
The length pointed to by
.Fa oldlenp
is too short to hold the requested value.
+.It Bq Er ENOMEM
+The smaller of either the length pointed to by
+.Fa oldlenp
+or the estimated size of the returned data exceeds the
+system limit on locked memory.
+.It Bq Er ENOMEM
+Locking the buffer
+.Fa oldp ,
+or a portion of the buffer if the estimated size of the data
+to be returned is smaller,
+would cause the process to exceed its per-process locked memory limit.
.It Bq Er ENOTDIR
The
.Fa name
.El
.Sh FILES
.Bl -tag -width <netinet/icmpXvar.h> -compact
-.It Aq Pa sys/sysctl.h
+.It In sys/sysctl.h
definitions for top level identifiers, second level kernel and hardware
identifiers, and user level identifiers
-.It Aq Pa sys/socket.h
+.It In sys/socket.h
definitions for second level network identifiers
-.It Aq Pa sys/gmon.h
+.It In sys/gmon.h
definitions for third level profiling identifiers
-.It Aq Pa vm/vm_param.h
+.It In vm/vm_param.h
definitions for second level virtual memory identifiers
-.It Aq Pa netinet/in.h
+.It In netinet/in.h
definitions for third level IPv4/IPv6 identifiers and
fourth level IPv4/v6 identifiers
-.It Aq Pa netinet/icmp_var.h
+.It In netinet/icmp_var.h
definitions for fourth level ICMP identifiers
-.It Aq Pa netinet/icmp6.h
+.It In netinet/icmp6.h
definitions for fourth level ICMPv6 identifiers
-.It Aq Pa netinet/udp_var.h
+.It In netinet/udp_var.h
definitions for fourth level UDP identifiers
.El
.Sh SEE ALSO
-Index: sysctl.3
-===================================================================
-RCS file: /cvs/root/Libc/gen/FreeBSD/sysctl.3,v
-retrieving revision 1.2
-diff -u -r1.2 sysctl.3
---- sysctl.3 2003/05/20 22:21:03 1.2
-+++ sysctl.3 2003/10/21 18:31:52
-@@ -181,13 +181,21 @@
+--- sysctl.3.orig 2004-07-02 16:52:10.000000000 -0700
++++ sysctl.3 2004-10-24 17:35:54.000000000 -0700
+@@ -182,13 +182,21 @@
}
.Ed
.Pp
-+Note: Implementation of
++Note: Implementation of
+.Fn printkproc
+-- to print whatever data deemed necessary from the large
+.Vt kinfo_proc
-+structure (
++structure (
+.In sysctl.h
+) -- is left as an exercise for the reader.
+.Pp
The top level names are defined with a CTL_ prefix in
- .Aq Pa sys/sysctl.h ,
+ .In sys/sysctl.h ,
and are as follows.
The next and subsequent levels down are found in the include files
listed here, and described in separate sections below.
-.Bl -column CTLXMACHDEPXXX "Next level namesXXXXXX" -offset indent
+.Bl -column CTLXMACHDEP "Next level names" -offset indent
.It Sy "Name Next level names Description"
- .It "CTL\_DEBUG sys/sysctl.h Debugging"
- .It "CTL\_VFS sys/mount.h File system"
-@@ -196,7 +204,8 @@
- .It "CTL\_MACHDEP sys/sysctl.h Machine dependent"
- .It "CTL\_NET sys/socket.h Networking"
- .It "CTL\_USER sys/sysctl.h User-level"
--.It "CTL\_VM vm/vm_param.h Virtual memory"
-+.It "CTL\_VM sys/resource.h Virtual memory (struct loadavg)"
-+.It "CTL\_VM sys/vmmeter.h Virtual memory (struct vmtotal)"
+ .It "CTL_DEBUG sys/sysctl.h Debugging"
+ .It "CTL_VFS sys/mount.h File system"
+@@ -197,7 +205,8 @@
+ .It "CTL_MACHDEP sys/sysctl.h Machine dependent"
+ .It "CTL_NET sys/socket.h Networking"
+ .It "CTL_USER sys/sysctl.h User-level"
+-.It "CTL_VM vm/vm_param.h Virtual memory"
++.It "CTL_VM sys/resources.h Virtual memory (struct loadavg)"
++.It "CTL_VM sys/vmmeter.h Virtual memory (struct vmtotal)"
.El
.Pp
For example, the following retrieves the maximum number of processes allowed
--- /dev/null
+--- telldir.c.orig 2003-05-20 15:21:03.000000000 -0700
++++ telldir.c 2004-11-19 17:18:44.000000000 -0800
+@@ -54,7 +54,9 @@
+ * cookie may be used only once before it is freed. This option
+ * is used to avoid having memory usage grow without bound.
+ */
++#if !__DARWIN_UNIX03
+ #define SINGLEUSE
++#endif /* !__DARWIN_UNIX03 */
+
+ /*
+ * return a pointer into a directory
+@@ -65,14 +67,32 @@
+ {
+ struct ddloc *lp;
+
++#if __DARWIN_UNIX03
++ if (__isthreaded)
++ _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock);
++ LIST_FOREACH(lp, &dirp->dd_td->td_locq, loc_lqe) {
++ if ((lp->loc_seek == dirp->dd_seek) &&
++ (lp->loc_loc == dirp->dd_loc))
++ goto found;
++ }
++ if ((lp = (struct ddloc *)malloc(sizeof(struct ddloc))) == NULL) {
++ if (__isthreaded)
++ _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock);
++ return (-1);
++ }
++#else /* !__DARWIN_UNIX03 */
+ if ((lp = (struct ddloc *)malloc(sizeof(struct ddloc))) == NULL)
+ return (-1);
+ if (__isthreaded)
+ _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock);
++#endif /* __DARWIN_UNIX03 */
+ lp->loc_index = dirp->dd_td->td_loccnt++;
+ lp->loc_seek = dirp->dd_seek;
+ lp->loc_loc = dirp->dd_loc;
+ LIST_INSERT_HEAD(&dirp->dd_td->td_locq, lp, loc_lqe);
++#if __DARWIN_UNIX03
++found:
++#endif /* __DARWIN_UNIX03 */
+ if (__isthreaded)
+ _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock);
+ return (lp->loc_index);
+@@ -106,13 +126,14 @@
+ if (dp == NULL)
+ break;
+ }
+-found:
++found:;
+ #ifdef SINGLEUSE
+ LIST_REMOVE(lp, loc_lqe);
+ free((caddr_t)lp);
+ #endif
+ }
+
++#ifndef BUILDING_VARIANT
+ /*
+ * Reclaim memory for telldir cookies which weren't used.
+ */
+@@ -131,3 +152,4 @@
+ }
+ LIST_INIT(&dirp->dd_td->td_locq);
+ }
++#endif /* !BUILDING_VARIANT */
--- /dev/null
+--- telldir.h.orig 2003-05-20 15:21:03.000000000 -0700
++++ telldir.h 2004-11-19 17:43:13.000000000 -0800
+@@ -61,6 +61,7 @@
+
+ struct dirent *_readdir_unlocked(DIR *);
+ void _reclaim_telldir(DIR *);
+-void _seekdir(DIR *, long);
++void _seekdir(DIR *, long) __DARWIN_ALIAS(_seekdir);
++long telldir(DIR *) __DARWIN_ALIAS(telldir);
+
+ #endif
.\" SUCH DAMAGE.
.\"
.\" @(#)time.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/gen/time.3,v 1.11 2001/10/01 16:08:51 ru Exp $
+.\" $FreeBSD: src/lib/libc/gen/time.3,v 1.13 2004/07/02 19:07:30 ru Exp $
.\"
-.Dd June 4, 1993
+.Dd July 18, 2003
.Dt TIME 3
.Os
.Sh NAME
function
returns the value of time in seconds since 0 hours, 0 minutes,
0 seconds, January 1, 1970, Coordinated Universal Time.
-.Pp
-A copy of the time value may be saved to the area indicated by the
-pointer
-.Fa tloc .
-If
-.Fa tloc
-is a NULL pointer, no value is stored.
-.Pp
-Upon successful completion,
+If an error occurs,
.Fn time
-returns the value of time.
-Otherwise a value of
-.Pq Po Vt time_t Pc \-1
-is returned and the global variable
-.Va errno
-is set to indicate the error.
+returns the value
+.Po Vt time_t Pc Ns \-1 .
+.Pp
+The return value is also stored in
+.No \&* Ns Va tloc ,
+provided that
+.Va tloc
+is non-null.
.Sh ERRORS
-The following error codes may be set in
-.Va errno :
-.Bl -tag -width Er
-.It Bq Er EFAULT
-An argument address referenced invalid memory.
-.El
+The
+.Fn time
+function may fail for any of the reasons described in
+.Xr gettimeofday 2 .
.Sh SEE ALSO
.Xr gettimeofday 2 ,
.Xr ctime 3
+.Sh STANDARDS
+The
+.Nm
+function conforms to
+.St -p1003.1-2001 .
+.Sh BUGS
+Neither
+.St -isoC-99
+nor
+.St -p1003.1-2001
+requires
+.Fn time
+to set
+.Va errno
+on failure; thus, it is impossible for an application to distinguish
+the valid time value \-1 (representing the last UTC second of 1969)
+from the error return value.
+.Pp
+Systems conforming to earlier versions of the C and
+.Tn POSIX
+standards (including older versions of
+.Fx )
+did not set
+.No \&* Ns Va tloc
+in the error case.
.Sh HISTORY
A
.Fn time
-Index: time.3
-===================================================================
-RCS file: /cvs/root/Libc/gen/FreeBSD/time.3,v
-retrieving revision 1.2
-diff -u -r1.2 time.3
---- time.3 2003/05/20 22:21:03 1.2
-+++ time.3 2003/07/08 23:12:00
+--- time.3.orig 2004-07-02 12:07:30.000000000 -0700
++++ time.3 2004-10-24 17:39:18.000000000 -0700
@@ -53,7 +53,8 @@
.Fn time
function
-0 seconds, January 1, 1970, Coordinated Universal Time.
+0 seconds, January 1, 1970, Coordinated Universal Time,
+without including leap seconds.
- .Pp
- A copy of the time value may be saved to the area indicated by the
- pointer
+ If an error occurs,
+ .Fn time
+ returns the value
static char sccsid[] = "@(#)time.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/gen/time.c,v 1.2 2002/03/22 21:52:05 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/gen/time.c,v 1.4 2003/07/19 02:53:46 wollman Exp $");
#include <sys/types.h>
#include <sys/time.h>
time_t *t;
{
struct timeval tt;
+ time_t retval;
if (gettimeofday(&tt, (struct timezone *)0) < 0)
- return(-1);
- if (t)
- *t = tt.tv_sec;
- return(tt.tv_sec);
+ retval = -1;
+ else
+ retval = tt.tv_sec;
+ if (t != NULL)
+ *t = retval;
+ return (retval);
}
static char sccsid[] = "@(#)ttyname.c 8.2 (Berkeley) 1/27/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/gen/ttyname.c,v 1.12 2002/02/01 01:32:19 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/gen/ttyname.c,v 1.16 2004/01/06 18:26:14 nectar Exp $");
#include "namespace.h"
#include <sys/types.h>
#include <pthread.h>
#include "un-namespace.h"
-#include <db.h>
#include "libc_private.h"
-static char buf[sizeof(_PATH_DEV) + MAXNAMLEN] = _PATH_DEV;
-static char *oldttyname(int, struct stat *);
+static char buf[sizeof(_PATH_DEV) + MAXNAMLEN];
static char *ttyname_threaded(int fd);
static char *ttyname_unthreaded(int fd);
char *
ttyname_r(int fd, char *buf, size_t len)
{
- struct dirent *dirp;
- DIR *dp;
- struct stat dsb;
struct stat sb;
char *rval;
- int minlen;
rval = NULL;
if (len <= sizeof(_PATH_DEV))
return (rval);
- if ((dp = opendir(_PATH_DEV)) != NULL) {
- memcpy(buf, _PATH_DEV, sizeof(_PATH_DEV));
- for (rval = NULL; (dirp = readdir(dp)) != NULL;) {
- if (dirp->d_fileno != sb.st_ino)
- continue;
- minlen = (len - (sizeof(_PATH_DEV) - 1)) < (dirp->d_namlen + 1) ?
- (len - (sizeof(_PATH_DEV) - 1)) : (dirp->d_namlen + 1);
- memcpy(buf + sizeof(_PATH_DEV) - 1, dirp->d_name, minlen);
- if (stat(buf, &dsb) || sb.st_dev != dsb.st_dev ||
- sb.st_ino != dsb.st_ino)
- continue;
- rval = buf;
- break;
- }
- (void) closedir(dp);
- }
- return (rval);
+ strcpy(buf, _PATH_DEV);
+ devname_r(sb.st_rdev, S_IFCHR,
+ buf + strlen(buf), sizeof(buf) - strlen(buf));
+ return (buf);
}
static char *
{
struct stat sb;
struct termios ttyb;
- DB *db;
- DBT data, key;
- struct {
- mode_t type;
- dev_t dev;
- } bkey;
/* Must be a terminal. */
if (tcgetattr(fd, &ttyb) < 0)
if (_fstat(fd, &sb) || !S_ISCHR(sb.st_mode))
return (NULL);
- if ( (db = dbopen(_PATH_DEVDB, O_RDONLY, 0, DB_HASH, NULL)) ) {
- memset(&bkey, 0, sizeof(bkey));
- bkey.type = S_IFCHR;
- bkey.dev = sb.st_rdev;
- key.data = &bkey;
- key.size = sizeof(bkey);
- if (!(db->get)(db, &key, &data, 0)) {
- bcopy(data.data,
- buf + sizeof(_PATH_DEV) - 1, data.size);
- (void)(db->close)(db);
- return (buf);
- }
- (void)(db->close)(db);
- }
- return (oldttyname(fd, &sb));
-}
-
-static char *
-oldttyname(int fd, struct stat *sb)
-{
- struct dirent *dirp;
- struct stat dsb;
- DIR *dp;
-
- if ((dp = opendir(_PATH_DEV)) == NULL)
- return (NULL);
-
- while ( (dirp = readdir(dp)) ) {
- if (dirp->d_fileno != sb->st_ino)
- continue;
- bcopy(dirp->d_name, buf + sizeof(_PATH_DEV) - 1,
- dirp->d_namlen + 1);
- if (stat(buf, &dsb) || sb->st_dev != dsb.st_dev ||
- sb->st_ino != dsb.st_ino)
- continue;
- (void)closedir(dp);
- return (buf);
- }
- (void)closedir(dp);
- return (NULL);
+ strcpy(buf, _PATH_DEV);
+ devname_r(sb.st_rdev, S_IFCHR,
+ buf + strlen(buf), sizeof(buf) - strlen(buf));
+ return (buf);
}
--- /dev/null
+Index: ttyname.c
+===================================================================
+RCS file: /cvs/root/Libc/gen/FreeBSD/ttyname.c,v
+retrieving revision 1.3
+diff -u -d -b -w -p -u -r1.3 ttyname.c
+--- ttyname.c 2004/11/25 19:38:02 1.3
++++ ttyname.c 2004/12/12 03:51:44
+@@ -48,10 +48,14 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/tty
+ #include <string.h>
+ #include <paths.h>
+ #include <pthread.h>
++#if __DARWIN_UNIX03
++#include <errno.h>
++#endif /* __DARWIN_UNIX03 */
+ #include "un-namespace.h"
+
+ #include "libc_private.h"
+
++#ifndef BUILDING_VARIANT
+ static char buf[sizeof(_PATH_DEV) + MAXNAMLEN];
+ static char *ttyname_threaded(int fd);
+ static char *ttyname_unthreaded(int fd);
+@@ -71,31 +75,54 @@ ttyname(int fd)
+ ret = ttyname_threaded(fd);
+ return (ret);
+ }
++#endif /* !BUILDING_VARIANT */
+
++#if __DARWIN_UNIX03
++int
++#else /* !__DARWIN_UNIX03 */
+ char *
+-ttyname_r(int fd, char *buf, size_t len)
++#endif /* __DARWIN_UNIX03 */
++ttyname_r(int fd, char *thrbuf, size_t len)
+ {
+ struct stat sb;
+- char *rval;
+
+- rval = NULL;
+-
++#if __DARWIN_UNIX03
++ if (_fstat(fd, &sb) < 0)
++ return (EBADF);
+ /* Must be a terminal. */
+ if (!isatty(fd))
+- return (rval);
++ return (ENOTTY);
+ /* Must be a character device. */
++ if (!S_ISCHR(sb.st_mode))
++ return (ENOTTY);
++ /* Must have enough room */
++ if (len <= sizeof(_PATH_DEV))
++ return (ERANGE);
++#else /* !__DARWIN_UNIX03 */
++ /* Must be a terminal. */
++ if (!isatty(fd))
++ return (NULL);
++ /* Must be a character device. */
+ if (_fstat(fd, &sb) || !S_ISCHR(sb.st_mode))
+- return (rval);
++ return (NULL);
+ /* Must have enough room */
+ if (len <= sizeof(_PATH_DEV))
+- return (rval);
++ return (NULL);
++#endif /* __DARWIN_UNIX03 */
+
+- strcpy(buf, _PATH_DEV);
+- devname_r(sb.st_rdev, S_IFCHR,
+- buf + strlen(buf), sizeof(buf) - strlen(buf));
+- return (buf);
++ strcpy(thrbuf, _PATH_DEV);
++ if (devname_r(sb.st_rdev, S_IFCHR,
++ thrbuf + strlen(thrbuf), len - strlen(thrbuf)) == NULL)
++#if __DARWIN_UNIX03
++ return (ERANGE);
++ return (0);
++#else /* !__DARWIN_UNIX03 */
++ return (NULL);
++ return (thrbuf);
++#endif /* __DARWIN_UNIX03 */
+ }
+
++#ifndef BUILDING_VARIANT
+ static char *
+ ttyname_threaded(int fd)
+ {
+@@ -124,7 +151,11 @@ ttyname_threaded(int fd)
+ return (NULL);
+ }
+ }
++#if __DARWIN_UNIX03
++ return (ttyname_r(fd, buf, sizeof(_PATH_DEV) + MAXNAMLEN) == 0 ? buf : NULL);
++#else /* !__DARWIN_UNIX03 */
+ return (ttyname_r(fd, buf, sizeof(_PATH_DEV) + MAXNAMLEN));
++#endif /* __DARWIN_UNIX03 */
+ }
+
+ static char *
+@@ -141,7 +172,9 @@ ttyname_unthreaded(int fd)
+ return (NULL);
+
+ strcpy(buf, _PATH_DEV);
+- devname_r(sb.st_rdev, S_IFCHR,
+- buf + strlen(buf), sizeof(buf) - strlen(buf));
++ if (devname_r(sb.st_rdev, S_IFCHR,
++ buf + strlen(buf), sizeof(buf) - strlen(buf)) == NULL)
++ return (NULL);
+ return (buf);
+ }
++#endif /* !BUILDING_VARIANT */
.\" SUCH DAMAGE.
.\"
.\" From: @(#)ualarm.3 8.2 (Berkeley) 4/19/94
-.\" $FreeBSD: src/lib/libc/gen/ualarm.3,v 1.15 2001/10/01 16:08:51 ru Exp $
+.\" $FreeBSD: src/lib/libc/gen/ualarm.3,v 1.19 2004/07/02 23:52:10 ru Exp $
.\"
.Dd April 19, 1994
.Dt UALARM 3
.Lb libc
.Sh SYNOPSIS
.In unistd.h
-.Ft u_int
-.Fn ualarm "u_int microseconds" "u_int interval"
+.Ft useconds_t
+.Fn ualarm "useconds_t microseconds" "useconds_t interval"
.Sh DESCRIPTION
.Bf -symbolic
This is a simplified interface to
.Fn ualarm
function
waits a count of
-.Ar microseconds
+.Fa microseconds
before asserting the terminating signal
.Dv SIGALRM .
System activity or time used in processing the call may cause a slight
signal will be sent
to the process every
.Fa interval
-microseconds after the timer expires (e.g. after
-.Fa value
-microseconds have passed).
+microseconds after the timer expires (e.g.\& after
+.Fa microseconds
+number of microseconds have passed).
.Pp
Due to
.Xr setitimer 2
restriction the maximum number of
-.Ar microseconds
+.Fa microseconds
and
-.Ar interval
+.Fa interval
is limited to 100000000000000
-(in case this value fit in the unsigned integer).
+(in case this value fits in the unsigned integer).
.Sh RETURN VALUES
When the signal has successfully been caught,
.Fn ualarm
static char sccsid[] = "@(#)ualarm.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/gen/ualarm.c,v 1.3 2002/02/01 01:08:48 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/gen/ualarm.c,v 1.4 2002/12/29 00:59:09 mike Exp $");
#include <sys/time.h>
#include <unistd.h>
* If ``reload'' is non-zero, keep generating SIGALRM
* every ``reload'' microseconds after the first signal.
*/
-unsigned
+useconds_t
ualarm(usecs, reload)
- unsigned usecs;
- unsigned reload;
+ useconds_t usecs;
+ useconds_t reload;
{
struct itimerval new, old;
.\" SUCH DAMAGE.
.\"
.\" @(#)unvis.3 8.2 (Berkeley) 12/11/93
-.\" $FreeBSD: src/lib/libc/gen/unvis.3,v 1.15 2002/12/18 13:33:02 ru Exp $
+.\" $FreeBSD: src/lib/libc/gen/unvis.3,v 1.17 2004/07/03 22:30:08 ru Exp $
.\"
.Dd December 11, 1993
.Dt UNVIS 3
by the
.Xr vis 3
function, back into
-the original form. Unvis is called with successive characters in
+the original form.
+Unvis is called with successive characters in
.Fa c
until a valid
sequence is recognized, at which time the decoded character is
and returns the number of characters placed into
.Fa dst ,
or \-1 if an
-invalid escape sequence was detected. The size of
+invalid escape sequence was detected.
+The size of
.Fa dst
should be
equal to the size of
.Fn unvis
function
implements a state machine that can be used to decode an arbitrary
-stream of bytes. All state associated with the bytes being decoded
+stream of bytes.
+All state associated with the bytes being decoded
is stored outside the
.Fn unvis
function (that is, a pointer to the state is passed in), so
-calls decoding different streams can be freely intermixed. To
+calls decoding different streams can be freely intermixed.
+To
start decoding a stream of bytes, first initialize an integer
-to zero. Call
+to zero.
+Call
.Fn unvis
with each successive byte, along with a pointer
to this integer, and a pointer to a destination character.
The
.Fn unvis
function
-has several return codes that must be handled properly. They are:
+has several return codes that must be handled properly.
+They are:
.Bl -tag -width UNVIS_VALIDPUSH
.It Li \&0 (zero)
Another character is necessary; nothing has been recognized yet.
-.It Dv UNVIS_VALID
+.It Dv UNVIS_VALID
A valid character has been recognized and is available at the location
pointed to by cp.
-.It Dv UNVIS_VALIDPUSH
+.It Dv UNVIS_VALIDPUSH
A valid character has been recognized and is available at the location
pointed to by cp; however, the character currently passed in should
be passed in again.
-.It Dv UNVIS_NOCHAR
-A valid sequence was detected, but no character was produced. This
+.It Dv UNVIS_NOCHAR
+A valid sequence was detected, but no character was produced.
+This
return code is necessary to indicate a logical break between characters.
-.It Dv UNVIS_SYNBAD
+.It Dv UNVIS_SYNBAD
An invalid escape sequence was detected, or the decoder is in an
-unknown state. The decoder is placed into the starting state.
+unknown state.
+The decoder is placed into the starting state.
.El
.Pp
When all bytes in the stream have been processed, call
static char sccsid[] = "@(#)unvis.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/gen/unvis.c,v 1.8 2003/02/16 17:29:09 nectar Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/gen/unvis.c,v 1.9 2004/08/02 08:46:23 stefanf Exp $");
#include <sys/types.h>
#include <ctype.h>
* unvis - decode characters previously encoded by vis
*/
int
-unvis(cp, c, astate, flag)
- char *cp;
- int c, *astate, flag;
+unvis(char *cp, int c, int *astate, int flag)
{
if (flag & UNVIS_END) {
*/
int
-strunvis(dst, src)
- char *dst;
- const char *src;
+strunvis(char *dst, const char *src)
{
char c;
char *start = dst;
}
int
-strunvisx(dst, src, flag)
- char *dst;
- const char *src;
+strunvisx(char *dst, const char *src, int flag)
{
char c;
char *start = dst;
--- /dev/null
+--- unvis.c.orig 2004-11-25 11:38:02.000000000 -0800
++++ unvis.c 2005-02-27 01:14:02.000000000 -0800
+@@ -37,6 +37,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/gen/unvis.c,v 1.9 2004/08/02 08:46:23 stefanf Exp $");
+
++#include "xlocale_private.h"
++
+ #include <sys/types.h>
+ #include <ctype.h>
+ #include <vis.h>
+@@ -64,6 +66,7 @@
+ int
+ unvis(char *cp, int c, int *astate, int flag)
+ {
++ locale_t loc = __current_locale();
+
+ if (flag & UNVIS_END) {
+ if (*astate == S_OCTAL2 || *astate == S_OCTAL3) {
+@@ -90,8 +93,8 @@
+
+ case S_START:
+ if (*astate & S_HTTP) {
+- if (ishex(tolower(c))) {
+- *cp = isdigit(c) ? (c - '0') : (tolower(c) - 'a');
++ if (ishex(tolower_l(c, loc))) {
++ *cp = isdigit_l(c, loc) ? (c - '0') : (tolower_l(c, loc) - 'a');
+ *astate = S_HEX2;
+ return (0);
+ }
+@@ -216,8 +219,8 @@
+ return (UNVIS_VALIDPUSH);
+
+ case S_HEX2: /* second mandatory hex digit */
+- if (ishex(tolower(c))) {
+- *cp = (isdigit(c) ? (*cp << 4) + (c - '0') : (*cp << 4) + (tolower(c) - 'a' + 10));
++ if (ishex(tolower_l(c, loc))) {
++ *cp = (isdigit_l(c, loc) ? (*cp << 4) + (c - '0') : (*cp << 4) + (tolower_l(c, loc) - 'a' + 10));
+ }
+ *astate = S_GROUND;
+ return (UNVIS_VALID);
.\" SUCH DAMAGE.
.\"
.\" @(#)usleep.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/gen/usleep.3,v 1.17 2001/10/01 16:08:51 ru Exp $
+.\" $FreeBSD: src/lib/libc/gen/usleep.3,v 1.18 2002/12/29 00:59:09 mike Exp $
.\"
.Dd February 13, 1998
.Dt USLEEP 3
.Sh SYNOPSIS
.In unistd.h
.Ft int
-.Fn usleep "unsigned int microseconds"
+.Fn usleep "useconds_t microseconds"
.Sh DESCRIPTION
The
.Fn usleep
---- usleep.3.orig Tue Oct 28 18:01:58 2003
-+++ usleep.3 Tue Oct 28 18:07:33 2003
+--- /Volumes/XDisk/tmp/Libc/gen/FreeBSD/usleep.3.orig 2002-12-28 16:59:09.000000000 -0800
++++ /Volumes/XDisk/tmp/Libc/gen/FreeBSD/usleep.3 2004-10-24 17:08:28.000000000 -0700
@@ -37,7 +37,7 @@
.Os
.Sh NAME
static char sccsid[] = "@(#)usleep.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/gen/usleep.c,v 1.27 2002/02/01 00:57:29 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/gen/usleep.c,v 1.28 2002/12/29 00:59:09 mike Exp $");
#include "namespace.h"
#include <time.h>
int
usleep(useconds)
- unsigned int useconds;
+ useconds_t useconds;
{
struct timespec time_to_sleep;
.\" SUCH DAMAGE.
.\"
.\" From: @(#)vis.3 8.1 (Berkeley) 6/9/93
-.\" $FreeBSD: src/lib/libc/gen/vis.3,v 1.20 2002/12/19 09:40:21 ru Exp $
+.\" $FreeBSD: src/lib/libc/gen/vis.3,v 1.26 2004/07/17 12:27:25 tjr Exp $
.\"
-.Dd July 25, 1996
+.Dd March 21, 2004
.Dt VIS 3
.Os
.Sh NAME
.Fa c .
If
.Fa c
-needs no encoding, it is copied in unaltered. The string is
+needs no encoding, it is copied in unaltered.
+The string is
null terminated, and a pointer to the end of the string is
-returned. The maximum length of any encoding is four
+returned.
+The maximum length of any encoding is four
characters (not including the trailing
.Dv NUL ) ;
thus, when
The following flags
alter this:
.Bl -tag -width VIS_WHITEX
+.It Dv VIS_GLOB
+Also encode magic characters
+.Ql ( * ,
+.Ql \&? ,
+.Ql \&[
+and
+.Ql # )
+recognized by
+.Xr glob 3 .
.It Dv VIS_SP
Also encode space.
.It Dv VIS_TAB
\&|
.Dv VIS_NL .
.It Dv VIS_SAFE
-Only encode "unsafe" characters. Unsafe means control
+Only encode "unsafe" characters.
+Unsafe means control
characters which may cause common terminals to perform
-unexpected functions. Currently this form allows space,
+unexpected functions.
+Currently this form allows space,
tab, newline, backspace, bell, and return - in addition
to all graphic characters - unencoded.
.El
Use an
.Ql M
to represent meta characters (characters with the 8th
-bit set), and use carat
+bit set), and use caret
.Ql ^
to represent control characters see
.Pf ( Xr iscntrl 3 ) .
.Ar d
represents a hexadecimal digit.
.It Dv VIS_OCTAL
-Use a three digit octal sequence. The form is
+Use a three digit octal sequence.
+The form is
.Ql \eddd
where
.Ar d
.Sh HISTORY
These functions first appeared in
.Bx 4.4 .
+.Sh BUGS
+The
+.Nm
+family of functions do not recognize multibyte characters, and thus
+may consider them to be non-printable when they are in fact printable
+(and vice versa.)
static char sccsid[] = "@(#)vis.c 8.1 (Berkeley) 7/19/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/gen/vis.c,v 1.11 2002/08/19 17:14:58 jmallett Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/gen/vis.c,v 1.13 2003/10/30 12:41:50 phk Exp $");
#include <sys/types.h>
#include <limits.h>
}
}
- if (isgraph(c) ||
+ if ((flag & VIS_GLOB) &&
+ (c == '*' || c == '?' || c == '[' || c == '#'))
+ ;
+ else if (isgraph(c) ||
((flag & VIS_SP) == 0 && c == ' ') ||
((flag & VIS_TAB) == 0 && c == '\t') ||
((flag & VIS_NL) == 0 && c == '\n') ||
goto done;
}
}
- if (((c & 0177) == ' ') || (flag & VIS_OCTAL)) {
+ if (((c & 0177) == ' ') || isgraph(c) || (flag & VIS_OCTAL)) {
*dst++ = '\\';
*dst++ = ((u_char)c >> 6 & 07) + '0';
*dst++ = ((u_char)c >> 3 & 07) + '0';
--- /dev/null
+--- vis.c.orig 2004-11-25 11:38:02.000000000 -0800
++++ vis.c 2005-02-24 16:58:00.000000000 -0800
+@@ -37,6 +37,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/gen/vis.c,v 1.13 2003/10/30 12:41:50 phk Exp $");
+
++#include "xlocale_private.h"
++
+ #include <sys/types.h>
+ #include <limits.h>
+ #include <ctype.h>
+@@ -54,18 +56,20 @@
+ int c, nextc;
+ int flag;
+ {
++ locale_t loc = __current_locale();
++
+ c = (unsigned char)c;
+
+ if (flag & VIS_HTTPSTYLE) {
+ /* Described in RFC 1808 */
+- if (!(isalnum(c) /* alpha-numeric */
++ if (!(isalnum_l(c, loc) /* alpha-numeric */
+ /* safe */
+ || c == '$' || c == '-' || c == '_' || c == '.' || c == '+'
+ /* extra */
+ || c == '!' || c == '*' || c == '\'' || c == '('
+ || c == ')' || c == ',')) {
+ *dst++ = '%';
+- snprintf(dst, 4, (c < 16 ? "0%X" : "%X"), c);
++ snprintf_l(dst, 4, loc, (c < 16 ? "0%X" : "%X"), c);
+ dst += 2;
+ goto done;
+ }
+@@ -74,7 +78,7 @@
+ if ((flag & VIS_GLOB) &&
+ (c == '*' || c == '?' || c == '[' || c == '#'))
+ ;
+- else if (isgraph(c) ||
++ else if (isgraph_l(c, loc) ||
+ ((flag & VIS_SP) == 0 && c == ' ') ||
+ ((flag & VIS_TAB) == 0 && c == '\t') ||
+ ((flag & VIS_NL) == 0 && c == '\n') ||
+@@ -130,7 +134,7 @@
+ goto done;
+ }
+ }
+- if (((c & 0177) == ' ') || isgraph(c) || (flag & VIS_OCTAL)) {
++ if (((c & 0177) == ' ') || isgraph_l(c, loc) || (flag & VIS_OCTAL)) {
+ *dst++ = '\\';
+ *dst++ = ((u_char)c >> 6 & 07) + '0';
+ *dst++ = ((u_char)c >> 3 & 07) + '0';
+@@ -143,7 +147,7 @@
+ c &= 0177;
+ *dst++ = 'M';
+ }
+- if (iscntrl(c)) {
++ if (iscntrl_l(c, loc)) {
+ *dst++ = '^';
+ if (c == 0177)
+ *dst++ = '?';
.PATH: ${.CURDIR}/gen
CFLAGS += -I${.CURDIR}/pthreads
-CFLAGS-crypt.c += -D__APPLE_PR_3509199_COMPAT__
-MISRCS += NSSystemDirectories.c OSSystemInfo.c arc4random.c assert.c cache.c \
- confstr.c crypt.c devname.c disklabel.c errlst.c fts.c ftw.c \
- getloadavg.c getttyent.c getusershell.c getvfsbyname.c \
+MISRCS += NSSystemDirectories.c OSSystemInfo.c arc4random.c asl.c \
+ cache.c confstr.c crypt.c devname.c disklabel.c errlst.c \
+ filesec.c fts.c \
+ get_compat.c getloadavg.c getttyent.c getusershell.c getvfsbyname.c \
isinf.c isnan.c \
malloc.c nanosleep.c nftw.c nlist.c scalable_malloc.c setlogin.c \
- sigsetops.c stack_logging.c strtofflags.c syslog.c \
+ sigsetops.c simple_dprintf.c stack_logging.c strtofflags.c syslog.c \
uname.c wordexp.c zone.c
+CFLAGS-asl.c = -I${.CURDIR}/gen
+LOCALHDRS += ${.CURDIR}/gen/asl_private.h
+
+# also build 64-bit long double versions (ppc only)
+LDBLSRCS += asl.c err.c syslog.c
+
.include "Makefile.fbsd_begin"
-FBSDMISRCS = _rand48.c alarm.c basename.c clock.c closedir.c ctermid.c \
+FBSDMISRCS = _rand48.c alarm.c assert.c \
+ basename.c clock.c closedir.c ctermid.c \
daemon.c dirname.c drand48.c erand48.c err.c errno_.c exec.c \
fmtcheck.c fmtmsg.c fnmatch.c ftok.c \
getbsize.c getcap.c getcwd.c gethostname.c getpeereid.c \
sethostname.c setmode.c setprogname.c siginterrupt.c siglist.c \
signal.c sleep.c srand48.c stringlist.c sysconf.c sysctl.c \
sysctlbyname.c sysctlnametomib.c \
- telldir.c termios.c time.c times.c timezone.c \
+ telldir.c termios.c time.c times.c \
ttyname.c ttyslot.c ualarm.c ulimit.c unvis.c usleep.c utime.c vis.c \
wait.c wait3.c waitpid.c
+.if (${MACHINE_ARCH} != ppc64)
+FBSDMISRCS += timezone.c
+.endif
FBSDHDRS = rand48.h telldir.h
.include "Makefile.fbsd_end"
+.include "Makefile.nbsd_begin"
+NBSDMISRCS = utmpx.c
+.include "Makefile.nbsd_end"
+CFLAGS-utmpx-nbsd.c += -DUTMP_COMPAT
+
+# private header files
+INSTHDRS += ${.CURDIR}/gen/get_compat.h
+PRIV_INSTHDRS += ${.CURDIR}/gen/stack_logging.h
+
+UNIX03SRCS += closedir.c crypt.c nanosleep.c nftw.c opendir.c rewinddir.c \
+ seekdir.c telldir.c ttyname.c
+
.if ${LIB} == "c"
-MAN3 += arc4random.3 confstr.3 crypt.3 devname.3 directory.3 fts.3 ftw.3 \
+MAN3 += arc4random.3 asl.3 confstr.3 crypt.3 devname.3 directory.3 fts.3 ftw.3 \
getdomainname.3 getfsent.3 getgrent.3 getgrouplist.3 getloadavg.3 \
- getnetgrent.3 getobjformat.3 getpeereid.3 getpwent.3 getttyent.3 \
+ getnetgrent.3 getobjformat.3 getpwent.3 getttyent.3 \
getusershell.3 getvfsbyname.3 initgroups.3 \
malloc.3 nlist.3 pwcache.3 setjmp.3 sigsetops.3 \
strtofflags.3 syslog.3 tcgetpgrp.3 tcsendbreak.3 \
tcsetattr.3 tcsetpgrp.3 tzset.3 uname.3 valloc.3 wordexp.3 intro.3
+MAN5 += compat.5
+
.include "Makefile.fbsd_begin"
FBSDMAN3= alarm.3 basename.3 clock.3 ctermid.3 daemon.3 dirname.3 err.3 exec.3 \
fmtcheck.3 fmtmsg.3 fnmatch.3 fpclassify.3 ftok.3 \
ulimit.3 unvis.3 usleep.3 utime.3 vis.3
.include "Makefile.fbsd_end"
+.include "Makefile.nbsd_begin"
+NBSDMAN3= endutxent.3
+.include "Makefile.nbsd_end"
+
MLINKS+=arc4random.3 arc4random_addrandom.3 arc4random.3 arc4random_stir.3
+MLINKS+=asl.3 asl_open.3 asl.3 asl_close.3 asl.3 asl_new.3 asl.3 asl_free.3 \
+ asl.3 asl_set.3 asl.3 asl_set_query.3 asl.3 asl_get.3 asl.3 asl_unset.3 \
+ asl.3 asl_log.3 asl.3 asl_vlog.3 asl.3 asl_send.3 asl.3 asl_key.3 \
+ asl.3 asl_add_log_file.3 asl.3 asl_remove_log_file.3 \
+ asl.3 asl_set_cutoff_level.3 asl.3 asl_search.3 asl.3 aslresponse_next.3 \
+ asl.3 aslresponse_free.3
MLINKS+=ctermid.3 ctermid_r.3
MLINKS+=crypt.3 encrypt.3 crypt.3 setkey.3 crypt.3 des_setkey.3 \
crypt.3 des_cipher.3
MLINKS+=directory.3 closedir.3 directory.3 dirfd.3 directory.3 opendir.3 \
directory.3 readdir.3 directory.3 readdir_r.3 directory.3 rewinddir.3 \
directory.3 seekdir.3 directory.3 telldir.3
+MLINKS+=endutxent.3 getutxent.3 endutxent.3 getutxid.3 \
+ endutxent.3 getutxline.3 endutxent.3 pututxline.3 \
+ endutxent.3 setutxent.3
MLINKS+=err.3 err_set_exit.3 err.3 err_set_file.3 err.3 errc.3 err.3 errx.3 \
err.3 verr.3 err.3 verrc.3 err.3 verrx.3 err.3 vwarn.3 err.3 vwarnc.3 \
err.3 vwarnx.3 err.3 warnc.3 err.3 warn.3 err.3 warnx.3
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#import <NSSystemDirectories.h>
// Names of directories; index into this with NSSearchPathDirectory - 1
-#define numDirs 10
+#define numDirs 14
static const struct {
unsigned char invalidDomainMask; // Domains in which this dir does not appear
unsigned char alternateDomainMask; // Domains in which this dir uses the alternate domain path
const char *dirPath;
} dirInfo[numDirs] = {
{0, 0, "Applications"},
- {0, 0, "Applications/GrabBag"},
+ {0, 0, "Applications/Demos"},
{0, 0, "Developer/Applications"},
{0, 0, "Applications/Utilities"},
- {0, 0x8, "Library"}, // Uses alternate form in System domain
+ {0, 0x8, "Library"}, // Uses alternate form in System domain
{0, 0, "Developer"},
- {0x9, 0, "Users"}, // Not valid in the System and User domains
- {0, 0x8, "Library/Documentation"}, // Uses alternate form in System domain
- {0xe, 0, "Documents"}, // Only valid in user domain
- {0x7, 0, "Library/CoreServices"} // Only valid in System domain
+ {0x9, 0, "Users"}, // Not valid in the System and User domains
+ {0, 0x8, "Library/Documentation"}, // Uses alternate form in System domain
+ {0xe, 0, "Documents"}, // Only valid in user domain
+ {0x7, 0, "Library/CoreServices"}, // Only valid in System domain
+ {0xe, 0, "Documents/Autosaved"}, // Only valid in user domain; not public API yet
+ {0xe, 0, "Desktop"}, // Only valid in user domain
+ {0, 0, "Library/Caches"},
+ {0, 0, "Library/Application Support"}
+};
+
+// Unpublicized values for NSSearchPathDirectory
+enum {
+ NSAutosavedDocumentsDirectory = 11
};
// Ordered list of where to find applications in each domain (the numbers are NSSearchPathDirectory)
--- /dev/null
+.\" $NetBSD: endutxent.3,v 1.4 2004/05/04 02:38:35 atatat Exp $
+.\"
+.\" Copyright (c) 2002 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Thomas Klausner.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+.\"
+.Dd September 26, 2002
+.Dt ENDUTXENT 3
+.Os
+.Sh NAME
+.Nm endutxent ,
+.Nm getutxent ,
+.Nm getutxid ,
+.Nm getutxline ,
+.Nm pututxline ,
+.Nm setutxent
+.Nd user accounting database functions
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In utmpx.h
+.Ft void
+.Fn endutxent void
+.Ft struct utmpx *
+.Fn getutxent void
+.Ft struct utmpx *
+.Fn getutxid "const struct utmpx *"
+.Ft struct utmpx *
+.Fn getutxline "const struct utmpx *"
+.Ft struct utmpx *
+.Fn pututxline "const struct utmpx *"
+.Ft void
+.Fn setutxent void
+.Sh DESCRIPTION
+These functions provide access to the
+.Xr utmpx 5
+user accounting database.
+.Pp
+.Fn getutxent
+reads the next entry from the database;
+if the database was not yet open, it also opens it.
+.Fn setutxent
+resets the database, so that the next
+.Fn getutxent
+call will get the first entry.
+.Fn endutxent
+closes the database.
+.Pp
+.Fn getutxid
+returns the next entry of the type specified in its argument's
+.Va ut_type
+field, or
+.Dv NULL
+if none is found.
+.Fn getutxline
+returns the next
+.Dv LOGIN_PROCESS
+or
+.Dv USER_PROCESS
+entry which has the same name as specified in the
+.Va ut_line
+field, or
+.Dv NULL
+if no match is found.
+.Pp
+.Fn pututxline
+adds the argument
+.Xr utmpx 5
+entry line to the accounting database, replacing a previous entry for
+the same user if it exists.
+.Ss The utmpx structure
+The
+.Nm utmpx
+structure has the following definition:
+.Pp
+.Bd -literal
+struct utmpx {
+ char ut_name[_UTX_USERSIZE]; /* login name */
+ char ut_id[_UTX_IDSIZE]; /* inittab id */
+ char ut_line[_UTX_LINESIZE]; /* tty name */
+ char ut_host[_UTX_HOSTSIZE]; /* host name */
+ uint16_t ut_session; /* session id used for windowing */
+ uint16_t ut_type; /* type of this entry */
+ pid_t ut_pid; /* process id creating the entry */
+ struct {
+ uint16_t e_termination; /* process termination signal */
+ uint16_t e_exit; /* process exit status */
+ } ut_exit;
+ struct sockaddr_storage ut_ss; /* address where entry was made from */
+ struct timeval ut_tv; /* time entry was created */
+ uint32_t ut_pad[10]; /* reserved for future use */
+};
+.Ed
+.Pp
+Valid entries for
+.Fa ut_type
+are:
+.Bl -tag -width LOGIN_PROCESSXX -compact -offset indent
+.It Dv BOOT_TIME
+Time of a system boot.
+.It Dv DEAD_PROCESS
+A session leader exited.
+.It Dv EMPTY
+No valid user accounting information.
+.It Dv INIT_PROCESS
+A process spawned by
+.Xr init 8 .
+.It Dv LOGIN_PROCESS
+The session leader of a logged-in user.
+.It Dv NEW_TIME
+Time after system clock change.
+.It Dv OLD_TIME
+Time before system clock change.
+.It Dv RUN_LVL
+Run level.
+Provided for compatibility, not used on
+.Nx .
+.It Dv USER_PROCESS
+A user process.
+.El
+.Sh RETURN VALUES
+.Fn getutxent
+returns the next entry, or
+.Dv NULL
+on failure (end of database or problems reading from the database).
+.Fn getutxid
+and
+.Fn getutxline
+return the matching structure on success, or
+.Dv NULL
+if no match was found.
+.Fn pututxline
+returns the structure that was successfully written, or
+.Dv NULL .
+.Sh SEE ALSO
+.Xr logwtmpx 3 ,
+.Xr utmpx 5
+.Sh STANDARDS
+The
+.Fn endutxent ,
+.Fn getutxent ,
+.Fn getutxid ,
+.Fn getutxline ,
+.Fn pututxline ,
+.Fn setutxent
+all conform to
+.St -p1003.1-2001
+(XSI extension), and previously to
+.St -xpg4.2 .
+The fields
+.Fa ut_user ,
+.Fa ut_id ,
+.Fa ut_line ,
+.Fa ut_pid ,
+.Fa ut_type ,
+and
+.Fa ut_tv
+conform to
+.St -p1003.1-2001
+(XSI extension), and previously to
+.St -xpg4.2 .
+.\" .Fa ut_host ,
+.\" .Fa ut_session ,
+.\" .Fa ut_exit ,
+.\" and
+.\" .Fa ut_ss
+.\" are from
+.\" SVR3/4?
+.\" .Dv RUN_LVL
+.\" is for compatibility with
+.\" what exactly?
+.\" .Sh HISTORY
+.\" The
+.\" .Nm utmpx ,
+.\" .Nm wtmpx ,
+.\" and
+.\" .Nm lastlogx
+.\" files first appeared in
+.\" SVR3? 4?
--- /dev/null
+--- endutxent.3.orig 2004-07-13 09:02:01.000000000 -0700
++++ endutxent.3 2004-08-05 15:41:50.000000000 -0700
+@@ -34,7 +34,7 @@
+ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ .\" POSSIBILITY OF SUCH DAMAGE.
+ .\"
+-.Dd September 26, 2002
++.Dd July 13, 2004
+ .Dt ENDUTXENT 3
+ .Os
+ .Sh NAME
+@@ -105,20 +105,14 @@
+ .Pp
+ .Bd -literal
+ struct utmpx {
+- char ut_name[_UTX_USERSIZE]; /* login name */
+- char ut_id[_UTX_IDSIZE]; /* inittab id */
+- char ut_line[_UTX_LINESIZE]; /* tty name */
+- char ut_host[_UTX_HOSTSIZE]; /* host name */
+- uint16_t ut_session; /* session id used for windowing */
+- uint16_t ut_type; /* type of this entry */
+- pid_t ut_pid; /* process id creating the entry */
+- struct {
+- uint16_t e_termination; /* process termination signal */
+- uint16_t e_exit; /* process exit status */
+- } ut_exit;
+- struct sockaddr_storage ut_ss; /* address where entry was made from */
+- struct timeval ut_tv; /* time entry was created */
+- uint32_t ut_pad[10]; /* reserved for future use */
++ char ut_user[_UTX_USERSIZE]; /* login name */
++ char ut_id[_UTX_IDSIZE]; /* id */
++ char ut_line[_UTX_LINESIZE]; /* tty name */
++ pid_t ut_pid; /* process id creating the entry */
++ short ut_type; /* type of this entry */
++ struct timeval ut_tv; /* time entry was created */
++ char ut_host[_UTX_HOSTSIZE]; /* host name */
++ __uint32_t ut_pad[16]; /* reserved for future use */
+ };
+ .Ed
+ .Pp
+@@ -143,8 +137,7 @@
+ Time before system clock change.
+ .It Dv RUN_LVL
+ Run level.
+-Provided for compatibility, not used on
+-.Nx .
++Provided for compatibility, not used.
+ .It Dv USER_PROCESS
+ A user process.
+ .El
+@@ -163,7 +156,6 @@
+ returns the structure that was successfully written, or
+ .Dv NULL .
+ .Sh SEE ALSO
+-.Xr logwtmpx 3 ,
+ .Xr utmpx 5
+ .Sh STANDARDS
+ The
--- /dev/null
+.\" $NetBSD: utmpx.5,v 1.2 2003/04/16 13:35:24 wiz Exp $
+.\"
+.\" Copyright (c) 2002 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Thomas Klausner.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+.\"
+.Dd September 26, 2002
+.Dt UTMPX 5
+.Os
+.Sh NAME
+.Nm utmpx ,
+.Nm wtmpx ,
+.Nm lastlogx
+.Nd user accounting database
+.Sh SYNOPSIS
+.In utmpx.h
+.Sh DESCRIPTION
+The
+.Aq Pa utmpx.h
+header defines the structures and functions for logging user.
+Currently logged in users are tracked in
+.Pa /var/run/utmpx ,
+a list of all logins and logouts, as well as all shutdowns, reboots
+and date changes, is kept in
+.Pa /var/log/wtmpx ,
+and the last login of each user is noted in
+.Pa /var/log/lastlogx .
+The files are not automatically created if they do not exist; they
+must be created manually.
+.Pp
+The interface to the
+.Nm utmpx
+file is described in
+.Xr endutxent 3 .
+.Pp
+The
+.Nm wtmpx
+file can grow rapidly on busy systems, and is normally rotated with
+.Xr newsyslog 8 .
+.Pp
+In the event of a date change, a shutdown, or a reboot, the following
+items are logged in the
+.Nm wtmpx
+file:
+.Bl -tag -width shutdownxx -compact -offset indent
+.It Li date
+The system time has been manually or automatically updated by
+.Xr date 1 .
+The command name
+.Em date
+is recorded in the field
+.Fa ut_name .
+In the field
+.Fa ut_line ,
+the character
+.Ql \\*(Ba
+indicates the time prior to the change, and the character
+.Ql \&{
+indicates the new time.
+.It Li reboot
+.It Li shutdown
+A system reboot or shutdown has been initiated.
+The character
+.Ql \&~
+is placed in the field
+.Fa ut_line ,
+and
+.Li reboot
+or
+.Li shutdown
+in the field
+.Fa ut_name
+(see
+.Xr shutdown 8
+and
+.Xr reboot 8 ) ,
+using
+.Xr logwtmpx 3 .
+.Pp
+.El
+.Sh FILES
+.Bl -tag -width /var/log/lastlogx -compact
+.It Pa /var/run/utmpx
+The
+.Nm utmpx
+file.
+.It Pa /var/log/wtmpx
+The
+.Nm wtmpx
+file.
+.It Pa /var/log/lastlogx
+The
+.Nm lastlogx
+file.
+.El
+.Sh SEE ALSO
+.Xr last 1 ,
+.Xr login 1 ,
+.Xr rwho 1 ,
+.Xr w 1 ,
+.Xr who 1 ,
+.Xr endutxent 3 ,
+.Xr logwtmpx 3 ,
+.Xr ac 8 ,
+.Xr init 8 ,
+.Xr newsyslog 8 ,
+.Xr reboot 8
--- /dev/null
+--- utmpx.5.orig 2004-07-13 09:15:18.000000000 -0700
++++ utmpx.5 2004-08-05 15:33:40.000000000 -0700
+@@ -38,23 +38,16 @@
+ .Dt UTMPX 5
+ .Os
+ .Sh NAME
+-.Nm utmpx ,
+-.Nm wtmpx ,
+-.Nm lastlogx
++.Nm utmpx
+ .Nd user accounting database
+ .Sh SYNOPSIS
+ .In utmpx.h
+ .Sh DESCRIPTION
+ The
+ .Aq Pa utmpx.h
+-header defines the structures and functions for logging user.
++header defines the structure and functions for logging user.
+ Currently logged in users are tracked in
+-.Pa /var/run/utmpx ,
+-a list of all logins and logouts, as well as all shutdowns, reboots
+-and date changes, is kept in
+-.Pa /var/log/wtmpx ,
+-and the last login of each user is noted in
+-.Pa /var/log/lastlogx .
++.Pa /var/run/utmpx .
+ The files are not automatically created if they do not exist; they
+ must be created manually.
+ .Pp
+@@ -62,76 +55,18 @@
+ .Nm utmpx
+ file is described in
+ .Xr endutxent 3 .
+-.Pp
+-The
+-.Nm wtmpx
+-file can grow rapidly on busy systems, and is normally rotated with
+-.Xr newsyslog 8 .
+-.Pp
+-In the event of a date change, a shutdown, or a reboot, the following
+-items are logged in the
+-.Nm wtmpx
+-file:
+-.Bl -tag -width shutdownxx -compact -offset indent
+-.It Li date
+-The system time has been manually or automatically updated by
+-.Xr date 1 .
+-The command name
+-.Em date
+-is recorded in the field
+-.Fa ut_name .
+-In the field
+-.Fa ut_line ,
+-the character
+-.Ql \\*(Ba
+-indicates the time prior to the change, and the character
+-.Ql \&{
+-indicates the new time.
+-.It Li reboot
+-.It Li shutdown
+-A system reboot or shutdown has been initiated.
+-The character
+-.Ql \&~
+-is placed in the field
+-.Fa ut_line ,
+-and
+-.Li reboot
+-or
+-.Li shutdown
+-in the field
+-.Fa ut_name
+-(see
+-.Xr shutdown 8
+-and
+-.Xr reboot 8 ) ,
+-using
+-.Xr logwtmpx 3 .
+-.Pp
+-.El
++For compatibility, changes to
++.Nm utmpx
++are reflected in
++.Xr utmp 3 ,
++but not the other way around.
+ .Sh FILES
+-.Bl -tag -width /var/log/lastlogx -compact
++.Bl -tag -width /var/log/utmpx -compact
+ .It Pa /var/run/utmpx
+ The
+ .Nm utmpx
+ file.
+-.It Pa /var/log/wtmpx
+-The
+-.Nm wtmpx
+-file.
+-.It Pa /var/log/lastlogx
+-The
+-.Nm lastlogx
+-file.
+ .El
+ .Sh SEE ALSO
+-.Xr last 1 ,
+-.Xr login 1 ,
+-.Xr rwho 1 ,
+-.Xr w 1 ,
+-.Xr who 1 ,
+ .Xr endutxent 3 ,
+-.Xr logwtmpx 3 ,
+-.Xr ac 8 ,
+-.Xr init 8 ,
+-.Xr newsyslog 8 ,
+-.Xr reboot 8
++.Xr utmp 5
--- /dev/null
+/* $NetBSD: utmpx.c,v 1.21 2003/09/06 16:42:10 wiz Exp $ */
+
+/*-
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/cdefs.h>
+
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: utmpx.c,v 1.21 2003/09/06 16:42:10 wiz Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+
+#include <assert.h>
+#include <db.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <utmp.h>
+/* don't define earlier, has side effects in fcntl.h */
+#define __LIBC12_SOURCE__
+#include <utmpx.h>
+#include <vis.h>
+
+__warn_references(getlastlogx,
+ "warning: reference to compatibility getlastlogx(); include <utmpx.h> for correct reference")
+__warn_references(lastlogxname,
+ "warning: reference to deprecated lastlogxname()")
+
+static FILE *fp;
+static int readonly = 0;
+static struct utmpx ut;
+static char utfile[MAXPATHLEN] = _PATH_UTMPX;
+static char llfile[MAXPATHLEN] = _PATH_LASTLOGX;
+
+static struct utmpx *utmp_update(const struct utmpx *);
+
+static const char vers[] = "utmpx-1.00";
+
+void
+setutxent()
+{
+
+ (void)memset(&ut, 0, sizeof(ut));
+ if (fp == NULL)
+ return;
+ (void)fseeko(fp, (off_t)sizeof(ut), SEEK_SET);
+}
+
+
+void
+endutxent()
+{
+
+ (void)memset(&ut, 0, sizeof(ut));
+ if (fp != NULL) {
+ (void)fclose(fp);
+ fp = NULL;
+ readonly = 0;
+ }
+}
+
+
+struct utmpx *
+getutxent()
+{
+
+ if (fp == NULL) {
+ struct stat st;
+
+ if ((fp = fopen(utfile, "r+")) == NULL)
+ if ((fp = fopen(utfile, "w+")) == NULL) {
+ if ((fp = fopen(utfile, "r")) == NULL)
+ goto fail;
+ else
+ readonly = 1;
+ }
+
+
+ /* get file size in order to check if new file */
+ if (fstat(fileno(fp), &st) == -1)
+ goto failclose;
+
+ if (st.st_size == 0) {
+ /* new file, add signature record */
+ (void)memset(&ut, 0, sizeof(ut));
+ ut.ut_type = SIGNATURE;
+ (void)memcpy(ut.ut_user, vers, sizeof(vers));
+ if (fwrite(&ut, sizeof(ut), 1, fp) != 1)
+ goto failclose;
+ } else {
+ /* old file, read signature record */
+ if (fread(&ut, sizeof(ut), 1, fp) != 1)
+ goto failclose;
+ if (memcmp(ut.ut_user, vers, sizeof(vers)) != 0 ||
+ ut.ut_type != SIGNATURE)
+ goto failclose;
+ }
+ }
+
+ if (fread(&ut, sizeof(ut), 1, fp) != 1)
+ goto fail;
+
+ return &ut;
+failclose:
+ (void)fclose(fp);
+fail:
+ (void)memset(&ut, 0, sizeof(ut));
+ return NULL;
+}
+
+
+struct utmpx *
+getutxid(const struct utmpx *utx)
+{
+
+ _DIAGASSERT(utx != NULL);
+
+ if (utx->ut_type == EMPTY)
+ return NULL;
+
+ do {
+ if (ut.ut_type == EMPTY)
+ continue;
+ switch (utx->ut_type) {
+ case EMPTY:
+ return NULL;
+ case RUN_LVL:
+ case BOOT_TIME:
+ case OLD_TIME:
+ case NEW_TIME:
+ if (ut.ut_type == utx->ut_type)
+ return &ut;
+ break;
+ case INIT_PROCESS:
+ case LOGIN_PROCESS:
+ case USER_PROCESS:
+ case DEAD_PROCESS:
+ switch (ut.ut_type) {
+ case INIT_PROCESS:
+ case LOGIN_PROCESS:
+ case USER_PROCESS:
+ case DEAD_PROCESS:
+ if (memcmp(ut.ut_id, utx->ut_id,
+ sizeof(ut.ut_id)) == 0)
+ return &ut;
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ return NULL;
+ }
+ } while (getutxent() != NULL);
+ return NULL;
+}
+
+
+struct utmpx *
+getutxline(const struct utmpx *utx)
+{
+
+ _DIAGASSERT(utx != NULL);
+
+ do {
+ switch (ut.ut_type) {
+ case EMPTY:
+ break;
+ case LOGIN_PROCESS:
+ case USER_PROCESS:
+ if (strncmp(ut.ut_line, utx->ut_line,
+ sizeof(ut.ut_line)) == 0)
+ return &ut;
+ break;
+ default:
+ break;
+ }
+ } while (getutxent() != NULL);
+ return NULL;
+}
+
+
+struct utmpx *
+pututxline(const struct utmpx *utx)
+{
+ struct utmpx temp, *u = NULL;
+ int gotlock = 0;
+
+ _DIAGASSERT(utx != NULL);
+
+ if (utx == NULL)
+ return NULL;
+
+ if (strcmp(_PATH_UTMPX, utfile) == 0)
+ if ((fp != NULL && readonly) || (fp == NULL && geteuid() != 0))
+ return utmp_update(utx);
+
+
+ (void)memcpy(&temp, utx, sizeof(temp));
+
+ if (fp == NULL) {
+ (void)getutxent();
+ if (fp == NULL || readonly)
+ return NULL;
+ }
+
+ if (getutxid(&temp) == NULL) {
+ setutxent();
+ if (getutxid(&temp) == NULL) {
+ if (lockf(fileno(fp), F_LOCK, (off_t)0) == -1)
+ return NULL;
+ gotlock++;
+ if (fseeko(fp, (off_t)0, SEEK_END) == -1)
+ goto fail;
+ }
+ }
+
+ if (!gotlock) {
+ /* we are not appending */
+ if (fseeko(fp, -(off_t)sizeof(ut), SEEK_CUR) == -1)
+ return NULL;
+ }
+
+ if (fwrite(&temp, sizeof (temp), 1, fp) != 1)
+ goto fail;
+
+ if (fflush(fp) == -1)
+ goto fail;
+
+ u = memcpy(&ut, &temp, sizeof(ut));
+fail:
+ if (gotlock) {
+ if (lockf(fileno(fp), F_ULOCK, (off_t)0) == -1)
+ return NULL;
+ }
+ return u;
+}
+
+
+static struct utmpx *
+utmp_update(const struct utmpx *utx)
+{
+ char buf[sizeof(*utx) * 4 + 1];
+ pid_t pid;
+ int status;
+
+ _DIAGASSERT(utx != NULL);
+
+ (void)strvisx(buf, (const char *)(const void *)utx, sizeof(*utx),
+ VIS_WHITE);
+ switch (pid = fork()) {
+ case 0:
+ (void)execl(_PATH_UTMP_UPDATE,
+ strrchr(_PATH_UTMP_UPDATE, '/') + 1, buf, NULL);
+ exit(1);
+ /*NOTREACHED*/
+ case -1:
+ return NULL;
+ default:
+ if (waitpid(pid, &status, 0) == -1)
+ return NULL;
+ if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
+ return memcpy(&ut, utx, sizeof(ut));
+ return NULL;
+ }
+
+}
+
+/*
+ * The following are extensions and not part of the X/Open spec.
+ */
+int
+updwtmpx(const char *file, const struct utmpx *utx)
+{
+ int fd;
+ int saved_errno;
+
+ _DIAGASSERT(file != NULL);
+ _DIAGASSERT(utx != NULL);
+
+ fd = open(file, O_WRONLY|O_APPEND|O_SHLOCK);
+
+ if (fd == -1) {
+ if ((fd = open(file, O_CREAT|O_WRONLY|O_EXLOCK, 0644)) == -1)
+ return -1;
+ (void)memset(&ut, 0, sizeof(ut));
+ ut.ut_type = SIGNATURE;
+ (void)memcpy(ut.ut_user, vers, sizeof(vers));
+ if (write(fd, &ut, sizeof(ut)) == -1)
+ goto failed;
+ }
+ if (write(fd, utx, sizeof(*utx)) == -1)
+ goto failed;
+ if (close(fd) == -1)
+ return -1;
+ return 0;
+
+ failed:
+ saved_errno = errno;
+ (void) close(fd);
+ errno = saved_errno;
+ return -1;
+}
+
+
+int
+utmpxname(const char *fname)
+{
+ size_t len;
+
+ _DIAGASSERT(fname != NULL);
+
+ len = strlen(fname);
+
+ if (len >= sizeof(utfile))
+ return 0;
+
+ /* must end in x! */
+ if (fname[len - 1] != 'x')
+ return 0;
+
+ (void)strlcpy(utfile, fname, sizeof(utfile));
+ endutxent();
+ return 1;
+}
+
+
+void
+getutmp(const struct utmpx *ux, struct utmp *u)
+{
+
+ _DIAGASSERT(ux != NULL);
+ _DIAGASSERT(u != NULL);
+
+ (void)memcpy(u->ut_name, ux->ut_name, sizeof(u->ut_name));
+ (void)memcpy(u->ut_line, ux->ut_line, sizeof(u->ut_line));
+ (void)memcpy(u->ut_host, ux->ut_host, sizeof(u->ut_host));
+ u->ut_time = ux->ut_tv.tv_sec;
+}
+
+void
+getutmpx(const struct utmp *u, struct utmpx *ux)
+{
+
+ _DIAGASSERT(ux != NULL);
+ _DIAGASSERT(u != NULL);
+
+ (void)memcpy(ux->ut_name, u->ut_name, sizeof(u->ut_name));
+ (void)memcpy(ux->ut_line, u->ut_line, sizeof(u->ut_line));
+ (void)memcpy(ux->ut_host, u->ut_host, sizeof(u->ut_host));
+ ux->ut_tv.tv_sec = u->ut_time;
+ ux->ut_tv.tv_usec = 0;
+ (void)memset(&ux->ut_ss, 0, sizeof(ux->ut_ss));
+ ux->ut_pid = 0;
+ ux->ut_type = USER_PROCESS;
+ ux->ut_session = 0;
+ ux->ut_exit.e_termination = 0;
+ ux->ut_exit.e_exit = 0;
+}
+
+int
+lastlogxname(const char *fname)
+{
+ size_t len;
+
+ _DIAGASSERT(fname != NULL);
+
+ len = strlen(fname);
+
+ if (len >= sizeof(llfile))
+ return 0;
+
+ /* must end in x! */
+ if (fname[len - 1] != 'x')
+ return 0;
+
+ (void)strlcpy(llfile, fname, sizeof(llfile));
+ return 1;
+}
+
+struct lastlogx *
+getlastlogx(uid_t uid, struct lastlogx *ll)
+{
+
+ return __getlastlogx13(_PATH_LASTLOGX, uid, ll);
+}
+
+struct lastlogx *
+__getlastlogx13(const char *fname, uid_t uid, struct lastlogx *ll)
+{
+ DBT key, data;
+ DB *db;
+
+ _DIAGASSERT(fname != NULL);
+ _DIAGASSERT(ll != NULL);
+
+ db = dbopen(fname, O_RDONLY|O_SHLOCK, 0, DB_HASH, NULL);
+
+ if (db == NULL)
+ return NULL;
+
+ key.data = &uid;
+ key.size = sizeof(uid);
+
+ if ((db->get)(db, &key, &data, 0) != 0)
+ goto error;
+
+ if (data.size != sizeof(*ll)) {
+ errno = EFTYPE;
+ goto error;
+ }
+
+ if (ll == NULL)
+ if ((ll = malloc(sizeof(*ll))) == NULL)
+ goto done;
+
+ (void)memcpy(ll, data.data, sizeof(*ll));
+ goto done;
+error:
+ ll = NULL;
+done:
+ (db->close)(db);
+ return ll;
+}
+
+int
+updlastlogx(const char *fname, uid_t uid, struct lastlogx *ll)
+{
+ DBT key, data;
+ int error = 0;
+ DB *db;
+
+ _DIAGASSERT(fname != NULL);
+ _DIAGASSERT(ll != NULL);
+
+ db = dbopen(fname, O_RDWR|O_CREAT|O_EXLOCK, 0, DB_HASH, NULL);
+
+ if (db == NULL)
+ return -1;
+
+ key.data = &uid;
+ key.size = sizeof(uid);
+ data.data = ll;
+ data.size = sizeof(*ll);
+ if ((db->put)(db, &key, &data, 0) != 0)
+ error = -1;
+
+ (db->close)(db);
+ return error;
+}
--- /dev/null
+--- utmpx.c.orig 2004-07-13 13:02:37.000000000 -0700
++++ utmpx.c 2004-08-05 15:25:10.000000000 -0700
+@@ -50,7 +50,6 @@
+ #include <sys/wait.h>
+
+ #include <assert.h>
+-#include <db.h>
+ #include <errno.h>
+ #include <fcntl.h>
+ #include <stdio.h>
+@@ -63,6 +62,13 @@
+ #include <utmpx.h>
+ #include <vis.h>
+
++#ifdef UTMP_COMPAT
++#include <utmp.h>
++#include <ttyent.h>
++
++static void _utmp_compat(const struct utmpx *);
++#endif /* UTMP_COMPAT */
++
+ __warn_references(getlastlogx,
+ "warning: reference to compatibility getlastlogx(); include <utmpx.h> for correct reference")
+ __warn_references(lastlogxname,
+@@ -72,7 +78,6 @@
+ static int readonly = 0;
+ static struct utmpx ut;
+ static char utfile[MAXPATHLEN] = _PATH_UTMPX;
+-static char llfile[MAXPATHLEN] = _PATH_LASTLOGX;
+
+ static struct utmpx *utmp_update(const struct utmpx *);
+
+@@ -270,6 +275,9 @@
+ goto fail;
+
+ u = memcpy(&ut, &temp, sizeof(ut));
++#ifdef UTMP_COMPAT
++ _utmp_compat(u);
++#endif /* UTMP_COMPAT */
+ fail:
+ if (gotlock) {
+ if (lockf(fileno(fp), F_ULOCK, (off_t)0) == -1)
+@@ -308,185 +316,50 @@
+
+ }
+
+-/*
+- * The following are extensions and not part of the X/Open spec.
+- */
+-int
+-updwtmpx(const char *file, const struct utmpx *utx)
+-{
+- int fd;
+- int saved_errno;
+-
+- _DIAGASSERT(file != NULL);
+- _DIAGASSERT(utx != NULL);
+-
+- fd = open(file, O_WRONLY|O_APPEND|O_SHLOCK);
+-
+- if (fd == -1) {
+- if ((fd = open(file, O_CREAT|O_WRONLY|O_EXLOCK, 0644)) == -1)
+- return -1;
+- (void)memset(&ut, 0, sizeof(ut));
+- ut.ut_type = SIGNATURE;
+- (void)memcpy(ut.ut_user, vers, sizeof(vers));
+- if (write(fd, &ut, sizeof(ut)) == -1)
+- goto failed;
++#ifdef UTMP_COMPAT
++static void
++_utmp_compat(const struct utmpx *ux)
++{
++ struct utmp u;
++ int fd, slot;
++ struct ttyent *ttyp;
++
++ switch (ux->ut_type) {
++ case INIT_PROCESS:
++ case LOGIN_PROCESS:
++ case USER_PROCESS:
++ break;
++ case DEAD_PROCESS:
++ logout(ux->ut_line);
++ return;
++ default:
++ return;
+ }
+- if (write(fd, utx, sizeof(*utx)) == -1)
+- goto failed;
+- if (close(fd) == -1)
+- return -1;
+- return 0;
+-
+- failed:
+- saved_errno = errno;
+- (void) close(fd);
+- errno = saved_errno;
+- return -1;
+-}
+-
+-
+-int
+-utmpxname(const char *fname)
+-{
+- size_t len;
+-
+- _DIAGASSERT(fname != NULL);
+-
+- len = strlen(fname);
+-
+- if (len >= sizeof(utfile))
+- return 0;
+-
+- /* must end in x! */
+- if (fname[len - 1] != 'x')
+- return 0;
+-
+- (void)strlcpy(utfile, fname, sizeof(utfile));
+- endutxent();
+- return 1;
+-}
+-
+-
+-void
+-getutmp(const struct utmpx *ux, struct utmp *u)
+-{
+-
+- _DIAGASSERT(ux != NULL);
+- _DIAGASSERT(u != NULL);
+-
+- (void)memcpy(u->ut_name, ux->ut_name, sizeof(u->ut_name));
+- (void)memcpy(u->ut_line, ux->ut_line, sizeof(u->ut_line));
+- (void)memcpy(u->ut_host, ux->ut_host, sizeof(u->ut_host));
+- u->ut_time = ux->ut_tv.tv_sec;
+-}
+-
+-void
+-getutmpx(const struct utmp *u, struct utmpx *ux)
+-{
+-
+- _DIAGASSERT(ux != NULL);
+- _DIAGASSERT(u != NULL);
+-
+- (void)memcpy(ux->ut_name, u->ut_name, sizeof(u->ut_name));
+- (void)memcpy(ux->ut_line, u->ut_line, sizeof(u->ut_line));
+- (void)memcpy(ux->ut_host, u->ut_host, sizeof(u->ut_host));
+- ux->ut_tv.tv_sec = u->ut_time;
+- ux->ut_tv.tv_usec = 0;
+- (void)memset(&ux->ut_ss, 0, sizeof(ux->ut_ss));
+- ux->ut_pid = 0;
+- ux->ut_type = USER_PROCESS;
+- ux->ut_session = 0;
+- ux->ut_exit.e_termination = 0;
+- ux->ut_exit.e_exit = 0;
+-}
+-
+-int
+-lastlogxname(const char *fname)
+-{
+- size_t len;
+-
+- _DIAGASSERT(fname != NULL);
+-
+- len = strlen(fname);
+-
+- if (len >= sizeof(llfile))
+- return 0;
+-
+- /* must end in x! */
+- if (fname[len - 1] != 'x')
+- return 0;
+-
+- (void)strlcpy(llfile, fname, sizeof(llfile));
+- return 1;
+-}
+-
+-struct lastlogx *
+-getlastlogx(uid_t uid, struct lastlogx *ll)
+-{
+-
+- return __getlastlogx13(_PATH_LASTLOGX, uid, ll);
+-}
+-
+-struct lastlogx *
+-__getlastlogx13(const char *fname, uid_t uid, struct lastlogx *ll)
+-{
+- DBT key, data;
+- DB *db;
+-
+- _DIAGASSERT(fname != NULL);
+- _DIAGASSERT(ll != NULL);
+-
+- db = dbopen(fname, O_RDONLY|O_SHLOCK, 0, DB_HASH, NULL);
+-
+- if (db == NULL)
+- return NULL;
+-
+- key.data = &uid;
+- key.size = sizeof(uid);
+-
+- if ((db->get)(db, &key, &data, 0) != 0)
+- goto error;
+-
+- if (data.size != sizeof(*ll)) {
+- errno = EFTYPE;
+- goto error;
++ /* do equivalent of ttyslot(), but using ux->ut_slot */
++ setttyent();
++ slot = 1;
++ for(;;) {
++ if ((ttyp = getttyent()) == NULL) {
++ endttyent();
++ return;
++ }
++ if (!strcmp(ttyp->ty_name, ux->ut_line)) {
++ endttyent();
++ break;
++ }
++ slot++;
+ }
+
+- if (ll == NULL)
+- if ((ll = malloc(sizeof(*ll))) == NULL)
+- goto done;
+-
+- (void)memcpy(ll, data.data, sizeof(*ll));
+- goto done;
+-error:
+- ll = NULL;
+-done:
+- (db->close)(db);
+- return ll;
+-}
+-
+-int
+-updlastlogx(const char *fname, uid_t uid, struct lastlogx *ll)
+-{
+- DBT key, data;
+- int error = 0;
+- DB *db;
+-
+- _DIAGASSERT(fname != NULL);
+- _DIAGASSERT(ll != NULL);
+-
+- db = dbopen(fname, O_RDWR|O_CREAT|O_EXLOCK, 0, DB_HASH, NULL);
+-
+- if (db == NULL)
+- return -1;
+-
+- key.data = &uid;
+- key.size = sizeof(uid);
+- data.data = ll;
+- data.size = sizeof(*ll);
+- if ((db->put)(db, &key, &data, 0) != 0)
+- error = -1;
+-
+- (db->close)(db);
+- return error;
++ /* now write utmp */
++ (void)memset(&u, 0, sizeof(u));
++ strncpy(u.ut_line, ux->ut_line, UT_LINESIZE);
++ strncpy(u.ut_name, ux->ut_user, UT_NAMESIZE);
++ strncpy(u.ut_host, ux->ut_host, UT_HOSTSIZE);
++ u.ut_time = ux->ut_tv.tv_sec;
++ if ((fd = open(_PATH_UTMP, O_WRONLY|O_CREAT, 0644)) >= 0) {
++ (void)lseek(fd, (off_t)(slot * sizeof(struct utmp)), L_SET);
++ (void)write(fd, &u, sizeof(struct utmp));
++ (void)close(fd);
++ }
+ }
++#endif /* UTMP_COMPAT */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
static int rs_initialized;
static struct arc4_stream *rs = NULL;
+static inline void arc4_init(struct arc4_stream *) __attribute__((always_inline));
static inline void
arc4_init(as)
struct arc4_stream *as;
as->j = 0;
}
+static inline void arc4_addrandom(struct arc4_stream *, u_char *, int) __attribute__((always_inline));
static inline void
arc4_addrandom(as, dat, datlen)
struct arc4_stream *as;
arc4_addrandom(as, (void *) &rdat, sizeof(rdat));
}
+static inline u_int8_t arc4_getbyte(struct arc4_stream *) __attribute__((always_inline));
static inline u_int8_t
arc4_getbyte(as)
struct arc4_stream *as;
return (as->s[(si + sj) & 0xff]);
}
+static inline u_int32_t arc4_getword(struct arc4_stream *) __attribute__((always_inline));
static inline u_int32_t
arc4_getword(as)
struct arc4_stream *as;
--- /dev/null
+.\" Copyright (c) 2005 Apple Computer
+.\" 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.
+.\" 4. Neither the name of Apple Computer nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER 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 REGENTS 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.
+.\"
+.\"
+.Dd January 5, 2005
+.Dt asl 3
+.Os "Mac OS X"
+.Sh NAME
+.Nm asl_open ,
+.Nm asl_close ,
+.Nm asl_new ,
+.Nm asl_free ,
+.Nm asl_set ,
+.Nm asl_set_query ,
+.Nm asl_get ,
+.Nm asl_unset ,
+.Nm asl_log ,
+.Nm asl_vlog ,
+.Nm asl_send ,
+.Nm asl_key ,
+.Nm asl_add_log_file ,
+.Nm asl_remove_log_file ,
+.Nm asl_set_cutoff_level ,
+.Nm asl_search ,
+.Nm aslresponse_next ,
+.Nm aslresponse_free
+.Nd system log message sending and searching functions
+.Sh SYNOPSIS
+.Fd #include <asl.h>
+.Ft aslclient
+.Fn asl_open "const char *ident, const char *facility, uint32_t opts"
+.Ft void
+.Fn asl_close "aslclient asl"
+.Ft aslmsg
+.Fn asl_new "uint32_t type"
+.Ft void
+.Fn asl_free "aslmsg msg"
+.Ft int
+.Fn asl_set "aslmsg msg, const char *key, const char *value"
+.Ft int
+.Fn asl_set_query "aslmsg msg, const char *key, const char *value, uint32_t op"
+.Ft const char *
+.Fn asl_key "aslmsg msg, uint32_t n"
+.Ft const char *
+.Fn asl_get "aslmsg msg, const char *key"
+.Ft int
+.Fn asl_unset "aslmsg msg, const char *key"
+.Ft int
+.Fn asl_log "aslclient asl, aslmsg msg, int level, const char *format, ..."
+.Ft int
+.Fn asl_vlog "aslclient asl, aslmsg msg, int level, const char *format, va_list ap"
+.Ft int
+.Fn asl_send "aslclient asl, aslmsg msg"
+.Ft int
+.Fn asl_add_log_file "aslclient asl, int fd"
+.Ft int
+.Fn asl_remove_log_file "aslclient asl, int fd"
+.Ft int
+.Fn asl_set_filter "aslclient asl, int f"
+.Ft aslresponse
+.Fn asl_search "aslclient asl, aslmsg msg"
+.Ft aslmsg
+.Fn aslresponse_next "aslresponse r"
+.Ft void
+.Fn aslresponse_free "aslresponse a"
+.Sh DESCRIPTION
+These routines provide an interface to the Apple system log facility.
+They are intended to be a replacement for the
+.Xr syslog 3
+API, which will continue to be supported for backwards compatibility.
+The new API allows client applications to create flexible, structured messages and send them to the
+.Nm syslogd
+server, where they may undergo additional processing.
+Messages received by the server are saved in a data store (subject to input filtering constraints).
+This API permits clients to create queries and search the message data store for matching messages.
+.Ss MESSAGES
+At the core of this API is the aslmsg structure.
+Although the structure is opaque and may not be directly manipulated, it contains a list of key/value pairs.
+All keys and values are NULL-terminated C language character strings.
+UTF-8 encoding may be used for non-ASCII characters.
+.Pp
+Message structures are generally used to send log messages, and are created thusly:
+.Pp
+ aslmsg m = asl_new(ASL_TYPE_MSG);
+.Pp
+Another message type, ASL_TYPE_QUERY, is used to create queries when searching the data store.
+Query type messages and searching are described in detail in the
+.Sx SEARCHING
+section below.
+For the remainder of this section, the messages described will be of the ASL_TYPE_MSG variety.
+.Pp
+Each aslmsg contains a default set of keys and values associated with them.
+These keys are listed in the asl.h header file.
+They are:
+.Pp
+ #define ASL_KEY_TIME "Time"
+ #define ASL_KEY_HOST "Host"
+ #define ASL_KEY_SENDER "Sender"
+ #define ASL_KEY_PID "PID"
+ #define ASL_KEY_UID "UID"
+ #define ASL_KEY_GID "GID"
+ #define ASL_KEY_LEVEL "Level"
+ #define ASL_KEY_MSG "Message"
+.Pp
+Many of these correspond to equivalent parts of messages described in the
+.Xr syslog 3
+API.
+Values associated with these message keys are assigned appropriate defaults.
+The value for ASL_KEY_HOST is the local host name,
+the value associated with ASL_KEY_SENDER is the process name,
+the ASL_KEY_PID is the client's process ID number, and so on.
+.Pp
+Note the addition of the UID and GID keys.
+The values for UID and GID are set in library code by the message sender.
+The server will attempt to confirm the values, but no claim is made that these
+values cannot be maliciously overridden in an attempt to deceive a log message
+reader as to the identity of the sender of a message.
+The contents of log messages must be regarded as insecure.
+.Pp
+Also note the absence of a Facility key.
+The
+.Xr asl 3
+API does not require a process to choose a facility name.
+The
+.Nm syslogd
+server will use a default value of
+.Dq user
+if a facility is not set.
+However, a client may set a facility name using:
+.Pp
+ asl_set(m, "Facility", "UsefulService");
+.Pp
+An application may choose any facility name at will.
+.Pp
+Default values are set in the message for each of the keys listed above except for
+ASL_KEY_MSG, which may be explicitly set at any time using the
+.Nm asl_set
+routine, or implicitly set at the time the message is sent using the
+.Nm asl_log
+or
+.Nm asl_vlog
+routines.
+These two routines also have an integer level parameter for specifying the log priority.
+The ASL_KEY_LEVEL value is set accordingly.
+Finally, the value associated with ASL_KEY_TIME is set in the sending routine.
+.Pp
+Although it may appear that there is significant overhead required to send a log message using this API,
+the opposite is actually true.
+A simple
+.Dq Hello World
+program requires only:
+.Pp
+ #include <asl.h>
+ ...
+ asl_log(NULL, NULL, ASL_LEVEL_INFO, "Hello World!");
+.Pp
+Both
+.Nm asl_log
+and
+.Nm asl_vlog
+will provide the appropriate default values when passed a NULL aslmsg argument.
+.Pp
+.Pp
+In this example, the aslclient argument is NULL.
+This is sufficient for a single-threaded application,
+or for an application which only sends log messages from a single thread.
+When logging from multiple threads, each thread must open a separate client handle using
+.Nm asl_open .
+The client handle may then be closed when it is no longer required using
+.Nm asl_close .
+.Pp
+When an application requires additional keys and values to be associated with each log message,
+a single message structure may be allocated and set up as
+.Dq template
+message of sorts:
+.Pp
+ aslmsg m = asl_new(ASL_TYPE_MSG);
+ asl_set(m, "Facility", "Spy vs. Spy");
+ asl_set(m, "Clearance", "Top Secret");
+ ...
+ asl_log(NULL, m, ASL_LEVEL_NOTICE, "Message One");
+ ...
+ asl_log(NULL, m, ASL_LEVEL_ERR, "Message Two");
+.Pp
+The message structure will carry the values set for the
+.Dq Facility
+and
+.Dq Clearance
+keys so that they are used in each call to
+.Nm asl_log ,
+while the log level and the message text are taken from the calling parameters.
+.Pp
+Key/value pairs may be removed from a message structure with
+.Nm asl_unset .
+A message may be freed using
+.Nm asl_free .
+.Pp
+The
+.Nm asl_send
+routine is used by
+.Nm asl_log
+and
+.Nm asl_vlog
+to transmit a message to the server.
+This routine sets the value associated with ASL_KEY_TIME and send the message.
+It may be called directly if all of a message's key/value pairs have been created using
+.Nm asl_set .
+.Ss CLIENT HANDLES
+When logging is done from a single thread,
+a NULL value may be used in any of the routines that require an aslclient argument.
+In this case the library will open an internal client handle on behalf of the application.
+.Pp
+If multiple threads must do logging,
+or if client options are desired,
+then the application should call
+.Nm asl_open
+to create a client handle for each thread.
+As a convenience,
+the
+.Nm asl_open
+routine may be given an ident argument,
+which becomes the default value for the ASL_KEY_SENDER key,
+and a facility argument,
+which becomes the default facility name for the application.
+.Pp
+Several options are available when creating a client handle.
+They are:
+.Pp
+.Bl -tag -width "ASL_OPT_NO_REMOTE" -compact
+.It ASL_OPT_STDERR
+adds stderr as an output file descriptor
+.It ASL_OPT_NO_DELAY
+connects to the server immediately
+.It ASL_OPT_NO_REMOTE
+disables remote-control filter adjustment
+.El
+.Pp
+See the FILTERING section below, and the
+.Xr syslog 1
+for additional details on filter controls.
+.Pp
+A client handle is closed and it's resources released using
+.Nm asl_close .
+Note that if additional file descriptors were added to the handle either using the
+ASL_OPT_STDERR option or afterwards with the
+.Nm asl_add_log_file
+routine, those file descriptors are not closed by
+.Nm asl_close .
+.Ss LOGGING TO ADDITIONAL FILES
+If a client handle is opened with the ASL_OPT_STDERR option to
+.Nm asl_open ,
+a copy of each log message will be sent to stderr.
+Additional output streams may be include using
+.Nm asl_add_log_file .
+File descriptors may be removed from the list of outputs associated with a client handle with
+.Nm asl_remove_log_file .
+This routine simply removes the file descriptor from the output list.
+The file is not closed as a result.
+.Pp
+The ASL_OPT_STDERR option may not be unset after a client handle has been opened.
+.Pp
+In the present release of Mac OS X, a
+.Dq raw
+format is used to format messages sent to file descriptors added to a client handle.
+Each message is preceded by a 10-character field containing a message length.
+The message length is padded with leading white space.
+The length gives the string length of the remainder of the output string.
+Following the length is a space character, and then the message.
+The message is encoded as a set of key/value pairs enclosed in square brackets,
+which are themselves separated by a space character.
+The key is separated from the value by space character.
+Embedded closing square brackets are escaped by a backslash.
+Embedded space characters in keys are escaped by a backslash;
+Embedded newlines are summarily turned into semicolons.
+The output is terminated by a trailing newline and a NUL character.
+.Ss SEARCHING
+The
+.Nm syslogd
+server archives received messages in a data store that may be searched using the
+.Nm asl_search ,
+.Nm aslresponse_next ,
+and
+.Nm aslresponse_free
+routines.
+A query message is created using:
+.Pp
+ aslmsg q = asl_new(ASL_TYPE_QUERY);
+.Pp
+Search settings are made in the query using
+.Nm asl_set_query .
+A search is performed on the data store with
+.Nm asl_search .
+It returns an
+.Ft aslresponse
+structure.
+The caller may then call
+.Nm aslresponse_next
+to iterate through matching messages.
+The
+.Ft aslresponse
+structure may be freed with
+.Nm aslresponse_free .
+.Pp
+Like other messages, ASL_TYPE_QUERY messages contain keys and values.
+They also associate an operation with each key and value.
+The operation is used to decide if a message matches the query.
+The simplest operation is ASL_QUERY_OP_EQUAL, which tests for equality.
+For example, the following code snippet searches for messages with a Sender value equal to
+.Dq MyApp .
+.Pp
+ aslmsg m;
+ aslresponse r;
+ q = asl_new(ASL_TYPE_QUERY);
+ asl_set_query(q, ASL_KEY_SENDER, "MyApp", ASL_QUERY_OP_EQUAL);
+ r = asl_search(NULL, q);
+.Pp
+More complex searches may be performed using other query operations.
+.Pp
+.Bl -tag -width "ASL_QUERY_OP_GREATER_EQUAL" -compact
+.It ASL_QUERY_OP_EQUAL
+value equality
+.It ASL_QUERY_OP_GREATER
+value greater than
+.It ASL_QUERY_OP_GREATER_EQUAL
+value greater than or equal to
+.It ASL_QUERY_OP_LESS
+value less than
+.It ASL_QUERY_OP_LESS_EQUAL
+value less than or equal to
+.It ASL_QUERY_OP_NOT_EQUAL
+value not equal
+.It ASL_QUERY_OP_REGEX
+regular expression search
+.It ASL_QUERY_OP_TRUE
+always true - use to test for the existence of a key
+.El
+.Pp
+Regular expression search uses
+.Xr regex 3
+library.
+Patterns are compiled using the REG_EXTENDED and REG_NOSUB options.
+.Pp
+Modifiers that change the behavior of these operations may also be specified
+by ORing the modifier value with the operation.
+The modifiers are:
+.Pp
+.Bl -tag -width "ASL_QUERY_OP_SUBSTRING" -compact
+.It ASL_QUERY_OP_CASEFOLD
+string comparisons are case-folded
+.It ASL_QUERY_OP_PREFIX
+match a leading substring
+.It ASL_QUERY_OP_SUFFIX
+match a trailing substring
+.It ASL_QUERY_OP_SUBSTRING
+match any substring
+.It ASL_QUERY_OP_NUMERIC
+values are converted to integer using
+.Nm atoi
+.El
+.Pp
+The only modifier that is checked for ASL_QUERY_OP_REGEX search is ASL_QUERY_OP_CASEFOLD.
+This causes the regular expression to be compiled with the REG_ICASE option.
+.Pp
+If a query message contains more than one set of key/value/operation triples,
+the result will be a logical AND. For example, to find messages from
+.Dq MyApp
+with a priority level less than or equal to
+.Dq 3 :
+.Pp
+ aslmsg q;
+ aslresponse r;
+ q = asl_new(ASL_TYPE_QUERY);
+ asl_set_query(q, ASL_KEY_SENDER, "MyApp", ASL_QUERY_OP_EQUAL);
+ asl_set_query(q, ASL_KEY_LEVEL, "3",
+ ASL_QUERY_OP_LESS_EQUAL | ASL_QUERY_OP_NUMERIC);
+ r = asl_search(NULL, q);
+.Pp
+After calling
+.Nm asl_search
+to get an
+.Ft aslresponse
+structure, use
+.Nm aslresponse_next
+to iterate through all matching messages.
+To iterate through the keys and values in a message, use
+.Nm asl_key
+to iterate through the keys, then call
+.Nm asl_get
+to get the value associated with each key.
+.Pp
+ aslmsg q, m;
+ int i;
+ const char *key, *val;
+.Pp
+ ...
+ r = asl_search(NULL, q);
+ while (NULL != (m = aslresponse_next(r)))
+ {
+ for (i = 0; (NULL != (key = asl_key(m, i))); i++)
+ {
+ val = asl_get(m, key);
+ ...
+ }
+ }
+ aslresponse_free(r);
+.Pp
+.Ss FILTERING AND REMOTE CONTROL
+Clients may set a filter mask value with
+.Nm asl_set_filter .
+The mask specifies which messages should be sent to the
+.Nm syslogd
+daemon by specifying a yes/no setting for each priority level.
+Clients typically set a filter mask to avoid sending relatively unimportant messages.
+For example, Debug or Info priority level messages are generally only useful for debugging operations.
+By setting a filter mask, a process can improve performance by avoiding
+sending messages that are in most cases unnecessary.
+.Pp
+As a convenience, the macros ASL_FILTER_MASK(level) and ASL_FILTER_MASK_UPTO(level)
+may be used to construct a bit mask corresponding to a given priority level,
+or corresponding to a bit mask for all priority levels from ASL_LEVEL_EMERG to a
+given input level.
+.Pp
+The default filter mask is ASL_FILTER_MASK_UPTO(ASL_LEVEL_NOTICE).
+This means that by default, and in the absence of remote-control changes (described below),
+ASL_LEVEL_DEBUG and ASL_LEVEL_INFO priority level messages are not sent to the
+.Mn syslogd
+server.
+.Pp
+Three different filters exist for each application.
+The first is the filter mask set using
+.Nm asl_set_filter
+as described above.
+The Apple System Log facility also manages a
+.Dq master
+filter mask.
+The master filter mask usually has a value that indicates to the library that it is
+.Dq off ,
+and thus it has no effect.
+However, the mask filter mask may be enabled by giving it a value using the
+.Nm syslog
+command, using the
+.Fl c
+0 option.
+When the master filter mask has been set,
+it takes precedence over the client's filter mask.
+The client's mask is unmodified, and will become active again if remote-control filtering is disabled.
+.Pp
+In addition to the master filter mask,
+The Apple System Log facility also manages a per-client remote-control filter mask.
+Like the master filter mask, the per-client mask is usually
+.Dq off ,
+having no effect on a client.
+If a per-client filter mask is set using the
+.Nm syslog
+command, using the
+.Fl c Ar process
+option, then it takes precedence over both the client's filter mask and the master filter mask.
+As is the case with the master filter mask, a per-client mask ceases having any effect when if is disabled.
+.Pp
+The ASL_OPT_NO_REMOTE option to
+.Nm asl_open
+causes both the master and per-client remote-control masks to be ignored in the library.
+In that case, only the client's own filter mask is used to determine which messages are
+sent to the server.
+This may be useful for Applications that produce log messages that should never be filtered
+due to security considerations.
+Note that root (administrator) access is required to set or change the master filter mask,
+and that only root may change a per-client remote-control filter mask for a root (UID 0) process.
+.Sh HISTORY
+These functions first appeared in
+Mac OS X 10.4.
+.Sh SEE ALSO
+.Xr syslogd 8 ,
+.Xr syslog 1
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * "Portions Copyright (c) 2004 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <syslog.h>
+#include <errno.h>
+#include <time.h>
+#include <crt_externs.h>
+#include <asl.h>
+#include <asl_private.h>
+#include <regex.h>
+#include <notify.h>
+#include <mach/mach.h>
+#include <pthread.h>
+
+#define _PATH_ASL_IN "/var/run/asl_input"
+
+#define streq(A, B) (strcmp(A, B) == 0)
+#define strcaseeq(A, B) (strcasecmp(A, B) == 0)
+
+#define forever for(;;)
+
+#define TOKEN_NULL 0
+#define TOKEN_OPEN 1
+#define TOKEN_CLOSE 2
+#define TOKEN_WORD 3
+#define TOKEN_INT 4
+
+/* forward */
+time_t asl_parse_time(const char *);
+const char *asl_syslog_faciliy_num_to_name(int n);
+__private_extern__ asl_client_t *_asl_open_default();
+
+/* notify SPI */
+uint32_t notify_get_state(int token, int *state);
+uint32_t notify_register_plain(const char *name, int *out_token);
+
+typedef struct
+{
+ int notify_count;
+ int notify_token;
+ int master_token;
+ char *sender;
+ pthread_mutex_t lock;
+ asl_client_t *asl;
+} _asl_global_t;
+
+#ifndef BUILDING_VARIANT
+__private_extern__ _asl_global_t _asl_global = {0, -1, -1, NULL, PTHREAD_MUTEX_INITIALIZER, NULL};
+
+static int
+_asl_connect(asl_client_t *asl)
+{
+ uint32_t len, status;
+
+ if (asl->sock >= 0) return 0;
+
+ asl->sock = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (asl->sock < 0) return -1;
+
+ memset(&(asl->server), 0, sizeof(struct sockaddr_un));
+ asl->server.sun_family = AF_UNIX;
+
+ strcpy(asl->server.sun_path, _PATH_ASL_IN);
+ len = sizeof(asl->server.sun_len) + sizeof(asl->server.sun_family) + strlen(asl->server.sun_path) + 1;
+ asl->server.sun_len = strlen(_PATH_ASL_IN) + 1;
+
+ status = connect(asl->sock, (const struct sockaddr *)&(asl->server), len);
+
+ if (status < 0) return -1;
+ return 0;
+}
+
+static int
+_asl_notify_open(int do_lock)
+{
+ char *notify_name;
+ const char *prefix;
+ uint32_t status;
+
+ if (do_lock != 0) pthread_mutex_lock(&_asl_global.lock);
+
+ _asl_global.notify_count++;
+
+ if (_asl_global.notify_token != -1)
+ {
+ if (do_lock != 0) pthread_mutex_unlock(&_asl_global.lock);
+ return 0;
+ }
+
+ notify_name = NULL;
+
+ prefix = NOTIFY_PREFIX_USER;
+ if (getuid() == 0) prefix = NOTIFY_PREFIX_SYSTEM;
+
+ if (_asl_global.master_token == -1)
+ {
+ status = notify_register_plain(NOTIFY_SYSTEM_MASTER, &_asl_global.master_token);
+ if (status != NOTIFY_STATUS_OK) _asl_global.master_token = -1;
+ }
+
+ asprintf(¬ify_name, "%s.%d", prefix, getpid());
+
+ if (notify_name != NULL)
+ {
+ status = notify_register_plain(notify_name, &_asl_global.notify_token);
+ free(notify_name);
+ if (status != NOTIFY_STATUS_OK) _asl_global.notify_token = -1;
+ }
+
+ if (do_lock != 0) pthread_mutex_unlock(&_asl_global.lock);
+
+ if (_asl_global.notify_token == -1) return -1;
+ return 0;
+}
+
+static void
+_asl_notify_close()
+{
+ pthread_mutex_lock(&_asl_global.lock);
+
+ if (_asl_global.notify_count > 0) _asl_global.notify_count--;
+
+ if (_asl_global.notify_count > 0)
+ {
+ pthread_mutex_unlock(&_asl_global.lock);
+ return;
+ }
+
+ if (_asl_global.master_token > 0) notify_cancel(_asl_global.master_token);
+ _asl_global.master_token = -1;
+
+ if (_asl_global.notify_token > 0) notify_cancel(_asl_global.notify_token);
+ _asl_global.notify_token = -1;
+
+ pthread_mutex_unlock(&_asl_global.lock);
+}
+
+aslclient
+asl_open(const char *ident, const char *facility, uint32_t opts)
+{
+ char *name, *x;
+ asl_client_t *asl;
+
+ asl = (asl_client_t *)calloc(1, sizeof(asl_client_t));
+ if (asl == NULL)
+ {
+ errno = ENOMEM;
+ return NULL;
+ }
+
+ asl->options = opts;
+
+ asl->sock = -1;
+
+ if (asl->options & ASL_OPT_NO_DELAY)
+ {
+ if (_asl_connect(asl) < 0)
+ {
+ free(asl);
+ return NULL;
+ }
+ }
+
+ asl->pid = getpid();
+ asl->uid = getuid();
+ asl->gid = getgid();
+
+ asl->filter = ASL_FILTER_MASK_UPTO(ASL_LEVEL_NOTICE);
+
+ if (ident != NULL)
+ {
+ asl->name = strdup(ident);
+ }
+ else
+ {
+ name = *(*_NSGetArgv());
+ if (name != NULL)
+ {
+ x = strrchr(name, '/');
+ if (x != NULL) x++;
+ else x = name;
+ asl->name = strdup(x);
+ }
+ }
+
+ if (facility != NULL) asl->facility = strdup(facility);
+ else asl->facility = strdup(asl_syslog_faciliy_num_to_name(LOG_USER));
+
+ if (!(asl->options & ASL_OPT_NO_REMOTE)) _asl_notify_open(1);
+
+ return (aslclient)asl;
+}
+
+void
+asl_close(aslclient ac)
+{
+ asl_client_t *asl;
+
+ asl = (asl_client_t *)ac;
+ if (asl == NULL) return;
+
+ if (asl->sock >= 0) close(asl->sock);
+ if (asl->name != NULL) free(asl->name);
+ if (asl->facility != NULL) free(asl->facility);
+ if (!(asl->options & ASL_OPT_NO_REMOTE)) _asl_notify_close();
+ if (asl->fd_list != NULL) free(asl->fd_list);
+
+ memset(asl, 0, sizeof(asl_client_t));
+ free(asl);
+}
+
+__private_extern__ asl_client_t *
+_asl_open_default()
+{
+ pthread_mutex_lock(&_asl_global.lock);
+ if (_asl_global.asl != NULL)
+ {
+ pthread_mutex_unlock(&_asl_global.lock);
+ return _asl_global.asl;
+ }
+
+ /*
+ * Do a sleight-of-hand with ASL_OPT_NO_REMOTE to avoid a deadlock
+ * since asl_open(xxx, yyy, 0) calls _asl_notify_open(1)
+ * which locks _asl_global.lock.
+ */
+ _asl_global.asl = asl_open(NULL, NULL, ASL_OPT_NO_REMOTE);
+
+ /* Reset options to clear ASL_OPT_NO_REMOTE bit */
+ if (_asl_global.asl != NULL) _asl_global.asl->options = 0;
+
+ /* Now call _asl_notify_open(0) to finish the work */
+ _asl_notify_open(0);
+
+ pthread_mutex_unlock(&_asl_global.lock);
+
+ return _asl_global.asl;
+}
+
+static uint32_t
+_asl_msg_index(asl_msg_t *msg, const char *k)
+{
+ uint32_t i;
+
+ if (msg == NULL) return (uint32_t)-1;
+ if (k == NULL) return (uint32_t)-1;
+
+ for (i = 0; i < msg->count; i++)
+ {
+ if (msg->key[i] == NULL) continue;
+ if (streq(msg->key[i], k)) return i;
+ }
+
+ return (uint32_t)-1;
+}
+
+static void
+_asl_append_string(char **m, uint32_t *x, char *s, uint32_t encode, uint32_t escspace)
+{
+ uint32_t i, n;
+
+ if (m == NULL) return;
+ if (x == NULL) return;
+ if (s == NULL) return;
+
+ n = 0;
+ if (encode == 0) n = strlen(s);
+ else
+ {
+ for (i = 0; s[i] != '\0'; i++)
+ {
+ if (s[i] == '\\') n++;
+ else if (s[i] == ']') n++;
+ else if ((escspace != 0) && (s[i] == ' ')) n++;
+ n++;
+ }
+ }
+
+ if (n == 0) return;
+
+ if (*m == NULL)
+ {
+ *m = malloc(n + 1);
+ *x = 1;
+ }
+ else
+ {
+ *m = realloc(*m, n + (*x));
+ }
+
+ if (encode == 0)
+ {
+ memcpy((*m) + (*x) - 1, s, n + 1);
+ *x += n;
+ return;
+ }
+
+ n = *x - 1;
+ for (i = 0; s[i] != '\0'; i++)
+ {
+ if ((s[i] == '\\') || (s[i] == ']') || ((escspace != 0) && (s[i] == ' ')))
+ {
+ (*m)[n++] = '\\';
+ (*m)[n++] = s[i];
+ }
+ else if (s[i] == '\n') (*m)[n++] = ';';
+ else (*m)[n++] = s[i];
+ }
+
+ (*m)[n++] = '\0';
+
+ *x = n;
+
+ return;
+}
+
+static void
+_asl_append_op(char **m, uint32_t *x, uint32_t op)
+{
+ char opstr[8];
+ uint32_t i;
+
+ if (m == NULL) return;
+ if (x == NULL) return;
+
+ if (op == ASL_QUERY_OP_NULL) return _asl_append_string(m, x, ".", 0, 0);
+
+ i = 0;
+ if (op & ASL_QUERY_OP_CASEFOLD) opstr[i++] = 'C';
+
+ if (op & ASL_QUERY_OP_CASEFOLD) opstr[i++] = 'R';
+
+ if (op & ASL_QUERY_OP_NUMERIC) opstr[i++] = 'N';
+
+ if (op & ASL_QUERY_OP_PREFIX)
+ {
+ if (op & ASL_QUERY_OP_SUFFIX) opstr[i++] = 'S';
+ else opstr[i++] = 'A';
+ }
+ if (op & ASL_QUERY_OP_SUFFIX) opstr[i++] = 'Z';
+
+ switch (op & ASL_QUERY_OP_TRUE)
+ {
+ case ASL_QUERY_OP_EQUAL:
+ opstr[i++] = '=';
+ break;
+ case ASL_QUERY_OP_GREATER:
+ opstr[i++] = '>';
+ break;
+ case ASL_QUERY_OP_GREATER_EQUAL:
+ opstr[i++] = '>';
+ opstr[i++] = '=';
+ break;
+ case ASL_QUERY_OP_LESS:
+ opstr[i++] = '<';
+ break;
+ case ASL_QUERY_OP_LESS_EQUAL:
+ opstr[i++] = '<';
+ opstr[i++] = '=';
+ break;
+ case ASL_QUERY_OP_NOT_EQUAL:
+ opstr[i++] = '!';
+ break;
+ case ASL_QUERY_OP_TRUE:
+ opstr[i++] = 'T';
+ break;
+ default:
+ break;
+ }
+
+ if (i == 0) return _asl_append_string(m, x, ".", 0, 0);
+
+ opstr[i++] = '\0';
+ return _asl_append_string(m, x, opstr, 0, 0);
+}
+
+char *
+asl_msg_to_string(asl_msg_t *msg, uint32_t *len)
+{
+ uint32_t i, outlen;
+ char *out, *s;
+
+ *len = 0;
+
+ if (msg == NULL) return NULL;
+
+ s = NULL;
+ out = NULL;
+ outlen = 0;
+
+ if (msg->type == ASL_TYPE_QUERY)
+ {
+ _asl_append_string(&out, &outlen, "Q ", 0, 0);
+ if (out == NULL) return NULL;
+ }
+
+ if (msg->count == 0)
+ {
+ if (out == NULL) return NULL;
+ *len = outlen;
+ return out;
+ }
+
+ for (i = 0; i < msg->count; i++)
+ {
+ if (msg->key[i] == NULL) continue;
+
+ if (i > 0) _asl_append_string(&out, &outlen, " [", 0, 0);
+ else _asl_append_string(&out, &outlen, "[", 0, 0);
+
+ if (msg->type == ASL_TYPE_QUERY)
+ {
+ _asl_append_op(&out, &outlen, msg->op[i]);
+ _asl_append_string(&out, &outlen, " ", 0, 0);
+ }
+
+ _asl_append_string(&out, &outlen, msg->key[i], 1, 1);
+
+ if (msg->val[i] != NULL)
+ {
+ _asl_append_string(&out, &outlen, " ", 0, 0);
+ _asl_append_string(&out, &outlen, msg->val[i], 1, 0);
+ }
+
+ _asl_append_string(&out, &outlen, "]", 0, 0);
+ }
+
+ *len = outlen;
+ return out;
+}
+
+static uint32_t
+_asl_msg_op_from_string(char *o)
+{
+ uint32_t op, i;
+
+ op = ASL_QUERY_OP_NULL;
+
+ if (o == NULL) return op;
+
+ for (i = 0; o[i] != '\0'; i++)
+ {
+ if (o[i] == '.') return ASL_QUERY_OP_NULL;
+ if (o[i] == 'C') op |= ASL_QUERY_OP_CASEFOLD;
+ if (o[i] == 'R') op |= ASL_QUERY_OP_CASEFOLD;
+ if (o[i] == 'N') op |= ASL_QUERY_OP_NUMERIC;
+ if (o[i] == 'S') op |= ASL_QUERY_OP_SUBSTRING;
+ if (o[i] == 'A') op |= ASL_QUERY_OP_PREFIX;
+ if (o[i] == 'Z') op |= ASL_QUERY_OP_SUFFIX;
+ if (o[i] == '<') op |= ASL_QUERY_OP_LESS;
+ if (o[i] == '>') op |= ASL_QUERY_OP_GREATER;
+ if (o[i] == '=') op |= ASL_QUERY_OP_EQUAL;
+ if (o[i] == '!') op |= ASL_QUERY_OP_NOT_EQUAL;
+ if (o[i] == 'T') op |= ASL_QUERY_OP_TRUE;
+ }
+
+ return op;
+}
+
+static char *
+_asl_msg_get_next_word(char **p, uint32_t *tt, uint32_t spacedel)
+{
+ char *start, *out;
+ uint32_t i, esc, len, n;
+
+ *tt = TOKEN_NULL;
+
+ if (p == NULL) return NULL;
+ if (*p == NULL) return NULL;
+ if (**p == '\0') return NULL;
+
+ /* skip one space if it's there (word separator) */
+ if (**p == ' ') (*p)++;
+
+ /* skip leading white space */
+ if (spacedel != 0)
+ {
+ while ((**p == ' ') || (**p == '\t')) (*p)++;
+ }
+
+ if (**p == '\0') return NULL;
+ if (**p == '\n') return NULL;
+
+ /* opening [ */
+ if (**p == '[')
+ {
+ *tt = TOKEN_OPEN;
+
+ (*p)++;
+ out = malloc(2);
+ out[0] = '[';
+ out[1] = '\0';
+ return out;
+ }
+
+ start = *p;
+ len = 0;
+
+ forever
+ {
+ /* stop scanning when we hit a delimiter */
+ if (((spacedel != 0) && (**p == ' ')) || (**p == ']') || (**p == '\0')) break;
+
+ esc = 0;
+ if (**p == '\\') esc = 1;
+ (*p)++;
+
+ /* skip over escaped chars so len is correct */
+ if ((esc == 1) && ((**p == ' ') || (**p == ']') || (**p == '\\'))) (*p)++;
+ len++;
+ }
+
+ if ((len == 0) && (**p == ']'))
+ {
+ *tt = TOKEN_CLOSE;
+ (*p)++;
+ out = malloc(2);
+ out[0] = ']';
+ out[1] = '\0';
+ return out;
+ }
+
+ *tt = TOKEN_INT;
+
+ out = malloc(len + 1);
+
+ for (n = 0, i = 0; n < len; i++)
+ {
+ if ((start[i] == '\\') && ((start[i+1] == ' ') || (start[i+1] == ']') || (start[i+1] == '\\')))
+ {
+ *tt = TOKEN_WORD;
+ i++;
+ }
+
+ if ((start[i] < '0') || (start[i] > '9')) *tt = TOKEN_WORD;
+ out[n++] = start[i];
+ }
+
+ out[n] = '\0';
+
+ return out;
+}
+
+asl_msg_t *
+asl_msg_from_string(const char *buf)
+{
+ uint32_t tt, type, op;
+ char *k, *v, *o, *p;
+ asl_msg_t *msg;
+
+ if (buf == NULL) return NULL;
+
+ type = ASL_TYPE_MSG;
+ p = (char *)buf;
+
+ k = _asl_msg_get_next_word(&p, &tt, 1);
+ if (k == NULL) return NULL;
+
+ if (streq(k, "Q"))
+ {
+ type = ASL_TYPE_QUERY;
+ free(k);
+
+ k = _asl_msg_get_next_word(&p, &tt, 1);
+ }
+ else if (tt == TOKEN_INT)
+ {
+ /* Leading integer is a string length - skip it */
+ free(k);
+ k = _asl_msg_get_next_word(&p, &tt, 1);
+ if (k == NULL) return NULL;
+ }
+
+ msg = calloc(1, sizeof(asl_msg_t));
+ if (msg == NULL) return NULL;
+ msg->type = type;
+
+ /* OPEN WORD [WORD [WORD]] CLOSE */
+ while (k != NULL)
+ {
+ op = ASL_QUERY_OP_NULL;
+
+ if (tt != TOKEN_OPEN)
+ {
+ asl_free(msg);
+ return NULL;
+ }
+
+ free(k);
+
+ /* get op for query type */
+ if (type == ASL_TYPE_QUERY)
+ {
+ o = _asl_msg_get_next_word(&p, &tt, 1);
+ if ((o == NULL) || (tt != TOKEN_WORD))
+ {
+ if (o != NULL) free(o);
+ asl_free(msg);
+ return NULL;
+ }
+
+ op = _asl_msg_op_from_string(o);
+ free(o);
+ }
+
+ k = _asl_msg_get_next_word(&p, &tt, 1);
+ if (tt == TOKEN_INT) tt = TOKEN_WORD;
+ if ((k == NULL) || (tt != TOKEN_WORD))
+ {
+ if (k != NULL) free(k);
+ asl_free(msg);
+ return NULL;
+ }
+
+ v = _asl_msg_get_next_word(&p, &tt, 0);
+ if (tt == TOKEN_INT) tt = TOKEN_WORD;
+ if (v == NULL)
+ {
+ asl_set_query(msg, k, NULL, op);
+ break;
+ }
+
+ if (tt == TOKEN_CLOSE)
+ {
+ asl_set_query(msg, k, NULL, op);
+ }
+ else if (tt == TOKEN_WORD)
+ {
+ asl_set_query(msg, k, v, op);
+ }
+ else
+ {
+ if (k != NULL) free(k);
+ if (v != NULL) free(v);
+ asl_free(msg);
+ return NULL;
+ }
+
+ if (k != NULL) free(k);
+ if (v != NULL) free(v);
+
+ if (tt != TOKEN_CLOSE)
+ {
+ k = _asl_msg_get_next_word(&p, &tt, 1);
+ if (k == NULL) break;
+
+ if (tt != TOKEN_CLOSE)
+ {
+ asl_free(msg);
+ return NULL;
+ }
+
+ free(k);
+ }
+
+ k = _asl_msg_get_next_word(&p, &tt, 1);
+ if (k == NULL) break;
+ }
+
+ return msg;
+}
+
+static int
+_asl_msg_equal(asl_msg_t *a, asl_msg_t *b)
+{
+ uint32_t i, j;
+
+ if (a->count != b->count) return 0;
+
+ for (i = 0; i < a->count; i++)
+ {
+ j = _asl_msg_index(b, a->key[i]);
+ if (j == (uint32_t)-1) return 0;
+
+ if (a->val[i] == NULL)
+ {
+ if (b->val[j] != NULL) return 0;
+ }
+ else
+ {
+ if (b->val[j] == NULL) return 0;
+ if (strcmp(a->val[i], b->val[j])) return 0;
+ }
+
+ if (a->type == ASL_TYPE_QUERY)
+ {
+ if (a->op[i] != b->op[j]) return 0;
+ }
+ }
+
+ return 1;
+}
+
+static int
+_asl_isanumber(char *s)
+{
+ int i;
+
+ if (s == NULL) return 0;
+
+ i = 0;
+ if ((s[0] == '-') || (s[0] == '+')) i = 1;
+
+ if (s[i] == '\0') return 0;
+
+ for (; s[i] != '\0'; i++)
+ {
+ if (!isdigit(s[i])) return 0;
+ }
+
+ return 1;
+}
+
+static int
+_asl_msg_op_test(uint32_t op, char *q, char *m, uint32_t n)
+{
+ int cmp;
+ uint32_t t;
+ int nq, nm, rflags;
+ regex_t rex;
+
+ t = op & ASL_QUERY_OP_TRUE;
+
+ if (op & ASL_QUERY_OP_REGEX)
+ {
+ memset(&rex, 0, sizeof(regex_t));
+
+ rflags = REG_EXTENDED | REG_NOSUB;
+ if (op & ASL_QUERY_OP_CASEFOLD) rflags |= REG_ICASE;
+
+ if (regcomp(&rex, q, rflags) != 0) return 0;
+ return (regexec(&rex, m, 0, NULL, 0) == 0);
+ }
+
+ if (op & ASL_QUERY_OP_NUMERIC)
+ {
+ /* We assume the query contains a numeric string */
+ if (_asl_isanumber(m) == 0) return 0;
+
+ nq = atoi(q);
+ nm = atoi(m);
+
+ switch (t)
+ {
+ case ASL_QUERY_OP_EQUAL: return (nm == nq);
+ case ASL_QUERY_OP_GREATER: return (nm > nq);
+ case ASL_QUERY_OP_GREATER_EQUAL: return (nm >= nq);
+ case ASL_QUERY_OP_LESS: return (nm < nq);
+ case ASL_QUERY_OP_LESS_EQUAL: return (nm <= nq);
+ case ASL_QUERY_OP_NOT_EQUAL: return (nm != nq);
+ default: return 0;
+ }
+ }
+
+ cmp = 0;
+ if (op & ASL_QUERY_OP_CASEFOLD)
+ {
+ if (n == 0) cmp = strcasecmp(m, q);
+ else cmp = strncasecmp(m, q, n);
+ }
+ else
+ {
+ if (n == 0) cmp = strcmp(m, q);
+ else cmp = strncmp(m, q, n);
+ }
+
+ switch (t)
+ {
+ case ASL_QUERY_OP_EQUAL: return (cmp == 0);
+ case ASL_QUERY_OP_GREATER: return (cmp > 0);
+ case ASL_QUERY_OP_GREATER_EQUAL: return (cmp >= 0);
+ case ASL_QUERY_OP_LESS: return (cmp < 0);
+ case ASL_QUERY_OP_LESS_EQUAL: return (cmp <= 0);
+ case ASL_QUERY_OP_NOT_EQUAL: return (cmp != 0);
+ default: return 0;
+ }
+
+ return 0;
+}
+
+static int
+_asl_msg_test_op_substr(uint32_t op, char *q, char *m)
+{
+ uint32_t i, d, lm, lq;
+
+ lm = strlen(m);
+ lq = strlen(q);
+
+ if (lq > lm) return 0;
+
+ d = lm - lq;
+ for (i = 0; i < d; i++)
+ {
+ if (_asl_msg_op_test(op, q, m + i, lq) != 0) return 1;
+ }
+
+ return 0;
+}
+
+static int
+_asl_msg_test_op_prefix(uint32_t op, char *q, char *m)
+{
+ uint32_t lm, lq;
+
+ lm = strlen(m);
+ lq = strlen(q);
+
+ if (lq > lm) return 0;
+
+ return _asl_msg_op_test(op, q, m, lq);
+}
+
+static int
+_asl_msg_test_op_suffix(uint32_t op, char *q, char *m)
+{
+ uint32_t lm, lq, d;
+
+ lm = strlen(m);
+ lq = strlen(q);
+
+ if (lq > lm) return 0;
+
+ d = lm - lq;
+ return _asl_msg_op_test(op, q, m + d, lq);
+}
+
+static int
+_asl_msg_test_op(uint32_t op, char *q, char *m)
+{
+ uint32_t t;
+
+ t = op & ASL_QUERY_OP_TRUE;
+ if (t == ASL_QUERY_OP_TRUE) return 1;
+
+ if (op & ASL_QUERY_OP_PREFIX)
+ {
+ if (op & ASL_QUERY_OP_SUFFIX) return _asl_msg_test_op_substr(op, q, m);
+ return _asl_msg_test_op_prefix(op, q, m);
+ }
+ if (op & ASL_QUERY_OP_SUFFIX) return _asl_msg_test_op_suffix(op, q, m);
+
+ return _asl_msg_op_test(op, q, m, 0);
+}
+
+static int
+_asl_msg_test(asl_msg_t *q, asl_msg_t *m)
+{
+ uint32_t i, j;
+ int cmp, freeval;
+ char *val;
+ struct tm gtime;
+ time_t tick;
+
+ for (i = 0; i < q->count; i++)
+ {
+ j = _asl_msg_index(m, q->key[i]);
+ if (j == (uint32_t)-1) return 0;
+
+ if (q->val[i] == NULL) continue;
+ if ((q->op[i] & ASL_QUERY_OP_TRUE) == ASL_QUERY_OP_TRUE) continue;
+
+ if (m->val[j] == NULL) return 0;
+
+ val = q->val[i];
+ freeval = 0;
+
+ if (streq(q->key[i], ASL_KEY_TIME))
+ {
+ tick = asl_parse_time(val);
+ if (tick != -1)
+ {
+ memset(>ime, 0, sizeof(struct tm));
+ gmtime_r(&tick, >ime);
+
+ /* Canonical form: YYYY.MM.DD hh:mm:ss UTC */
+ val = NULL;
+ asprintf(&val, "%d.%02d.%02d %02d:%02d:%02d UTC", gtime.tm_year + 1900, gtime.tm_mon + 1, gtime.tm_mday, gtime.tm_hour, gtime.tm_min, gtime.tm_sec);
+ freeval = 1; }
+ }
+
+ cmp = _asl_msg_test_op(q->op[i], val, m->val[j]);
+ if ((freeval == 1) && (val != NULL)) free(val);
+
+ if (cmp == 0) return 0;
+ }
+
+ return 1;
+}
+
+int
+asl_msg_cmp(asl_msg_t *a, asl_msg_t *b)
+{
+ if (a == NULL) return 0;
+ if (b == NULL) return 0;
+
+ if (a->type == b->type) return _asl_msg_equal(a, b);
+ if (a->type == ASL_TYPE_QUERY) return _asl_msg_test(a, b);
+ return _asl_msg_test(b, a);
+}
+
+static char *
+_get_line_from_file(FILE *f)
+{
+ char *s, *out;
+ size_t len;
+
+ out = fgetln(f, &len);
+ if (out == NULL) return NULL;
+ if (len == 0) return NULL;
+
+ if (out[len] != '\n') len++;
+
+ s = malloc(len);
+ memcpy(s, out, len - 1);
+
+ s[len] = '\0';
+ return s;
+}
+
+/*
+ * asl_add_file: write log messages to the given file descriptor
+ * Log messages will be written to this file as well as to the server.
+ */
+int
+asl_add_log_file(aslclient ac, int fd)
+{
+ uint32_t i;
+ int use_global_lock;
+ asl_client_t *asl;
+
+ use_global_lock = 0;
+ asl = (asl_client_t *)ac;
+ if (asl == NULL)
+ {
+ asl = _asl_open_default();
+ if (asl == NULL) return -1;
+ pthread_mutex_lock(&_asl_global.lock);
+ use_global_lock = 1;
+ }
+
+ for (i = 0; i < asl->fd_count; i++)
+ {
+ if (asl->fd_list[i] == fd)
+ {
+ if (use_global_lock != 0) pthread_mutex_unlock(&_asl_global.lock);
+ return 0;
+ }
+ }
+
+ if (asl->fd_count == 0)
+ {
+ asl->fd_list = (int *)calloc(1, sizeof(int));
+ }
+ else
+ {
+ asl->fd_list = (int *)realloc(asl->fd_list, (1 + asl->fd_count) * sizeof(int));
+ }
+
+ if (asl->fd_list == NULL)
+ {
+ if (use_global_lock != 0) pthread_mutex_unlock(&_asl_global.lock);
+ return -1;
+ }
+
+ asl->fd_list[asl->fd_count] = fd;
+ asl->fd_count++;
+
+ if (use_global_lock != 0) pthread_mutex_unlock(&_asl_global.lock);
+ return 0;
+}
+
+/*
+ * asl_remove_file: stop writing log messages to the given file descriptor
+ */
+int
+asl_remove_log_file(aslclient ac, int fd)
+{
+ uint32_t i;
+ int x, use_global_lock;
+ asl_client_t *asl;
+
+ use_global_lock = 0;
+ asl = (asl_client_t *)ac;
+ if (asl == NULL)
+ {
+ asl = _asl_open_default();
+ if (asl == NULL) return -1;
+ pthread_mutex_lock(&_asl_global.lock);
+ use_global_lock = 1;
+ }
+
+ if (asl->fd_count == 0)
+ {
+ if (use_global_lock != 0) pthread_mutex_unlock(&_asl_global.lock);
+ return 0;
+ }
+
+ x = -1;
+ for (i = 0; i < asl->fd_count; i++)
+ {
+ if (asl->fd_list[i] == fd)
+ {
+ x = i;
+ break;
+ }
+ }
+
+ if (x == -1)
+ {
+ if (use_global_lock != 0) pthread_mutex_unlock(&_asl_global.lock);
+ return 0;
+ }
+
+ for (i = x + 1; i < asl->fd_count; i++, x++) asl->fd_list[x] = asl->fd_list[i];
+ asl->fd_count--;
+
+ if (asl->fd_count == 0)
+ {
+ free(asl->fd_list);
+ asl->fd_list = NULL;
+ }
+ else
+ {
+ asl->fd_list = (int *)realloc(asl->fd_list, asl->fd_count * sizeof(int));
+ if (asl->fd_list == NULL)
+ {
+ asl->fd_count = 0;
+ if (use_global_lock != 0) pthread_mutex_unlock(&_asl_global.lock);
+ return -1;
+ }
+ }
+
+ if (use_global_lock != 0) pthread_mutex_unlock(&_asl_global.lock);
+ return 0;
+}
+
+int
+asl_set_filter(aslclient ac, int f)
+{
+ int last, use_global_lock;
+ asl_client_t *asl;
+
+ use_global_lock = 0;
+ asl = (asl_client_t *)ac;
+ if (asl == NULL)
+ {
+ asl = _asl_open_default();
+ if (asl == NULL) return -1;
+ pthread_mutex_lock(&_asl_global.lock);
+ use_global_lock = 1;
+ }
+
+ last = asl->filter;
+ asl->filter = f;
+
+ if (use_global_lock != 0) pthread_mutex_unlock(&_asl_global.lock);
+ return last;
+}
+
+/*
+ * asl_key: examine attribute keys
+ * returns the key of the nth attribute in a message (beginning at zero)
+ * returns NULL if the message has fewer attributes
+ */
+const char *
+asl_key(aslmsg a, uint32_t n)
+{
+ asl_msg_t *msg;
+
+ msg = (asl_msg_t *)a;
+ if (msg == NULL) return NULL;
+
+ if (n >= msg->count) return NULL;
+ return msg->key[n];
+}
+
+/*
+ * asl_new: create a new log message.
+ */
+aslmsg
+asl_new(uint32_t type)
+{
+ uint32_t i;
+ asl_msg_t *msg;
+ char *name, *x;
+
+ msg = calloc(1, sizeof(asl_msg_t));
+ if (msg == NULL) return NULL;
+
+ msg->type = type;
+ if (type == ASL_TYPE_QUERY) return (aslmsg)msg;
+
+ /*
+ * Defaut attributes are:
+ * 0 Time
+ * 1 Host
+ * 2 Sender
+ * 3 PID
+ * 4 UID
+ * 5 GID
+ * 6 Level
+ * 7 Message
+ */
+ msg->count = 8;
+
+ msg->key = calloc(msg->count, sizeof(char *));
+ if (msg->key == NULL)
+ {
+ free(msg);
+ return NULL;
+ }
+
+ msg->val = calloc(msg->count, sizeof(char *));
+ if (msg->val == NULL)
+ {
+ free(msg->key);
+ free(msg);
+ return NULL;
+ }
+
+ i = 0;
+ msg->key[i] = strdup(ASL_KEY_TIME);
+ if (msg->key[i] == NULL)
+ {
+ asl_free(msg);
+ return NULL;
+ }
+
+ i++;
+ msg->key[i] = strdup(ASL_KEY_HOST);
+ if (msg->key[i] == NULL)
+ {
+ asl_free(msg);
+ return NULL;
+ }
+
+ i++;
+ msg->key[i] = strdup(ASL_KEY_SENDER);
+ if (msg->key[i] == NULL)
+ {
+ asl_free(msg);
+ return NULL;
+ }
+
+ /* Get the value for ASL_KEY_SENDER from cache */
+ if (_asl_global.sender == NULL)
+ {
+ name = *(*_NSGetArgv());
+ if (name != NULL)
+ {
+ x = strrchr(name, '/');
+ if (x != NULL) x++;
+ else x = name;
+
+ pthread_mutex_lock(&_asl_global.lock);
+ if (_asl_global.sender == NULL) _asl_global.sender = strdup(x);
+ pthread_mutex_unlock(&_asl_global.lock);
+ }
+ }
+
+ if (_asl_global.sender == NULL)
+ {
+ msg->val[i] = strdup("Unknown");
+ if (msg->val[i] == NULL)
+ {
+ asl_free(msg);
+ return NULL;
+ }
+ }
+ else
+ {
+ msg->val[i] = strdup(_asl_global.sender);
+ if (msg->val[i] == NULL)
+ {
+ asl_free(msg);
+ return NULL;
+ }
+ }
+
+ i++;
+ msg->key[i] = strdup(ASL_KEY_PID);
+ if (msg->key[i] == NULL)
+ {
+ asl_free(msg);
+ return NULL;
+ }
+
+ i++;
+ msg->key[i] = strdup(ASL_KEY_UID);
+ if (msg->key[i] == NULL)
+ {
+ asl_free(msg);
+ return NULL;
+ }
+
+ i++;
+ msg->key[i] = strdup(ASL_KEY_GID);
+ if (msg->key[i] == NULL)
+ {
+ asl_free(msg);
+ return NULL;
+ }
+
+ i++;
+ msg->key[i] = strdup(ASL_KEY_LEVEL);
+ if (msg->key[i] == NULL)
+ {
+ asl_free(msg);
+ return NULL;
+ }
+
+ i++;
+ msg->key[i] = strdup(ASL_KEY_MSG);
+ if (msg->key[i] == NULL)
+ {
+ asl_free(msg);
+ return NULL;
+ }
+
+ return (aslmsg)msg;
+}
+
+/*
+ * asl_get: get attribute values from a message
+ * msg: an aslmsg
+ * key: attribute key
+ * returns the attribute value
+ * returns NULL if the message does not contain the key
+ */
+const char *
+asl_get(aslmsg a, const char *key)
+{
+ asl_msg_t *msg;
+ uint32_t i;
+
+ msg = (asl_msg_t *)a;
+
+ if (msg == NULL) return NULL;
+
+ i = _asl_msg_index(msg, key);
+ if (i == (uint32_t)-1) return NULL;
+ return msg->val[i];
+}
+
+#endif /* BUILDING_VARIANT */
+
+/*
+ * asl_vlog: Similar to asl_log, but taking a va_list instead of a list of
+ * arguments.
+ * msg: an aslmsg
+ * level: the log level of the associated message
+ * format: A formating string followed by a list of arguments, like vprintf()
+ * returns 0 for success, non-zero for failure
+ */
+int
+asl_vlog(aslclient ac, aslmsg a, int level, const char *format, va_list ap)
+{
+ int status, saved_errno;
+ asl_msg_t *msg;
+ char *str, *fmt, *estr;
+ uint32_t i, len, elen, expand, my_msg;
+ asl_client_t *asl;
+
+ asl = (asl_client_t *)ac;
+ if (asl == NULL)
+ {
+ /*
+ * Initialize _asl_global so that asl_new will have global data.
+ * Not strictly necessary, but helps performance.
+ */
+ asl = _asl_open_default();
+ if (asl == NULL) return -1;
+ }
+
+ saved_errno = errno;
+
+ if (format == NULL) return -1;
+
+ msg = (asl_msg_t *)a;
+
+ my_msg = 0;
+ if (msg == NULL)
+ {
+ my_msg = 1;
+ msg = asl_new(ASL_TYPE_MSG);
+ if (msg == NULL) return -1;
+ }
+
+ if (msg->type != ASL_TYPE_MSG) return -1;
+
+ if (level < ASL_LEVEL_EMERG) level = ASL_LEVEL_EMERG;
+ if (level > ASL_LEVEL_DEBUG) level = ASL_LEVEL_DEBUG;
+
+ str = NULL;
+ asprintf(&str, "%d", level);
+ if (str == NULL)
+ {
+ if ((msg != NULL) && (my_msg != 0)) asl_free(msg);
+ return -1;
+ }
+
+ asl_set(msg, ASL_KEY_LEVEL, str);
+ free(str);
+
+ /* insert strerror for %m */
+ len = 0;
+ elen = 0;
+ estr = strdup(strerror(saved_errno));
+ expand = 0;
+
+ if (estr != NULL)
+ {
+ elen = strlen(estr);
+
+ for (i = 0; format[i] != '\0'; i++)
+ {
+ if (format[i] == '%')
+ {
+ if (format[i+1] == '\0') len++;
+ else if (format[i+1] == 'm')
+ {
+ expand = 1;
+ len += elen;
+ i++;
+ }
+ else
+ {
+ len += 2;
+ i++;
+ }
+ }
+ else len++;
+ }
+ }
+
+ fmt = (char *)format;
+
+ if (expand != 0)
+ {
+ fmt = malloc(len + 1);
+ len = 0;
+
+ for (i = 0; format[i] != '\0'; i++)
+ {
+ if (format[i] == '%')
+ {
+ if (format[i+1] == '\0')
+ {
+ }
+ else if (format[i+1] == 'm')
+ {
+ memcpy(fmt+len, estr, elen);
+ len += elen;
+ i++;
+ }
+ else
+ {
+ fmt[len++] = format[i++];
+ fmt[len++] = format[i];
+ }
+ }
+ else fmt[len++] = format[i];
+ }
+
+ fmt[len] = '\0';
+ }
+
+ if (estr != NULL) free(estr);
+
+ vasprintf(&str, fmt, ap);
+ if (expand != 0) free(fmt);
+
+ if (str == NULL)
+ {
+ if ((msg != NULL) && (my_msg != 0)) asl_free(msg);
+ return -1;
+ }
+
+ asl_set(msg, ASL_KEY_MSG, str);
+ free(str);
+
+ status = asl_send(ac, (aslmsg)msg);
+
+ if ((msg != NULL) && (my_msg != 0)) asl_free(msg);
+ return status;
+}
+
+/*
+ * asl_log: log a message with a particular log level
+ * msg: an aslmsg
+ * level: the log level
+ * format: A formating string followed by a list of arguments, like printf()
+ * returns 0 for success, non-zero for failure
+ */
+int
+asl_log(aslclient ac, aslmsg a, int level, const char *format, ...)
+{
+ va_list ap;
+ int status;
+
+ if (format == NULL) return -1;
+
+ va_start(ap, format);
+ status = asl_vlog(ac, a, level, format, ap);
+ va_end(ap);
+
+ return status;
+}
+
+#ifndef BUILDING_VARIANT
+
+/*
+ * asl_send: send a message
+ * This routine may be used instead of asl_log() or asl_vlog() if asl_set()
+ * has been used to set all of a message's attributes.
+ * msg: an aslmsg
+ * returns 0 for success, non-zero for failure
+ */
+int
+asl_send(aslclient ac, aslmsg msg)
+{
+ char *str, *out;
+ uint32_t i, len, level, lmask, outstatus, filter;
+ const char *val;
+ time_t tick;
+ int status, rc_filter;
+ asl_client_t *asl;
+ int use_global_lock;
+
+ use_global_lock = 0;
+ asl = (asl_client_t *)ac;
+ if (asl == NULL)
+ {
+ asl = _asl_open_default();
+ if (asl == NULL) return -1;
+ use_global_lock = 1;
+ }
+
+ if (msg == NULL) return 0;
+
+ level = ASL_LEVEL_DEBUG;
+
+ val = asl_get(msg, ASL_KEY_LEVEL);
+ if (val != NULL) level = atoi(val);
+
+ lmask = ASL_FILTER_MASK(level);
+
+ filter = asl->filter;
+ rc_filter = 0;
+
+ if (!(asl->options & ASL_OPT_NO_REMOTE))
+ {
+ pthread_mutex_lock(&_asl_global.lock);
+
+ if (_asl_global.notify_token >= 0)
+ {
+ status = notify_get_state(_asl_global.notify_token, &i);
+ if ((status == NOTIFY_STATUS_OK) && (i != 0))
+ {
+ filter = i;
+ rc_filter = 1;
+ }
+ }
+
+ if ((rc_filter == 0) && (_asl_global.master_token >= 0))
+ {
+ status = notify_get_state(_asl_global.master_token, &i);
+ if ((status == NOTIFY_STATUS_OK) && (i != 0))
+ {
+ filter = i;
+ }
+ }
+
+ pthread_mutex_unlock(&_asl_global.lock);
+ }
+
+ /*
+ * Time, PID, UID, and GID values get set here
+ */
+ str = NULL;
+ tick = time(NULL);
+ asprintf(&str, "%u", tick);
+ if (str != NULL)
+ {
+ asl_set(msg, ASL_KEY_TIME, str);
+ free(str);
+ }
+
+ str = NULL;
+ asprintf(&str, "%u", getpid());
+ if (str != NULL)
+ {
+ asl_set(msg, ASL_KEY_PID, str);
+ free(str);
+ }
+
+ str = NULL;
+ asprintf(&str, "%d", getuid());
+ if (str != NULL)
+ {
+ asl_set(msg, ASL_KEY_UID, str);
+ free(str);
+ }
+
+ str = NULL;
+ asprintf(&str, "%u", getgid());
+ if (str != NULL)
+ {
+ asl_set(msg, ASL_KEY_GID, str);
+ free(str);
+ }
+
+ len = 0;
+ str = asl_msg_to_string((asl_msg_t *)msg, &len);
+ if (str == NULL) return -1;
+
+ asprintf(&out, "%10u %s\n", len+1, str);
+ free(str);
+ if (out == NULL) return -1;
+
+ outstatus = 0;
+
+ if (use_global_lock != 0) pthread_mutex_lock(&_asl_global.lock);
+
+ if ((filter != 0) && ((filter & lmask) != 0))
+ {
+ if (asl->sock == -1) _asl_connect(asl);
+
+ status = write(asl->sock, out, len + 12);
+ if (status < 0)
+ {
+ /* Write failed - try resetting */
+ asl->sock = -1;
+ _asl_connect(asl);
+ status = write(asl->sock, out, len + 12);
+ if (status < 0) outstatus = -1;
+ }
+ }
+
+ if (asl->options & ASL_OPT_STDERR) fprintf(stderr, "%s", out);
+
+ for (i = 0; i < asl->fd_count; i++)
+ {
+ if (asl->fd_list[i] < 0) continue;
+ status = write(asl->fd_list[i], out, len + 12);
+ if (status < 0)
+ {
+ asl->fd_list[i] = -1;
+ outstatus = -1;
+ }
+ }
+
+ if (use_global_lock != 0) pthread_mutex_unlock(&_asl_global.lock);
+
+ free(out);
+
+ return outstatus;
+}
+
+char *
+asl_msg_string(aslmsg a)
+{
+ uint32_t len;
+
+ return asl_msg_to_string((asl_msg_t *)a, &len);
+}
+
+/*
+ * asl_free: free a message
+ * msg: an aslmsg to free
+ */
+void
+asl_free(aslmsg a)
+{
+ uint32_t i;
+ asl_msg_t *msg;
+
+ msg = (asl_msg_t *)a;
+
+ if (msg == NULL) return;
+
+ for (i = 0; i < msg->count; i++)
+ {
+ if (msg->key[i] != NULL) free(msg->key[i]);
+ if (msg->val[i] != NULL) free(msg->val[i]);
+ }
+
+ if (msg->count > 0)
+ {
+ if (msg->key != NULL) free(msg->key);
+ if (msg->val != NULL) free(msg->val);
+ if (msg->op != NULL) free(msg->op);
+ }
+
+ free(msg);
+}
+
+/*
+ * asl_set_query: set arbitrary parameters of a query
+ * Similar to als_set, but allows richer query operations.
+ * See ASL_QUERY_OP_* above.
+ * msg: an aslmsg
+ * key: attribute key
+ * value: attribute value
+ * op: an operation from the set above.
+ * returns 0 for success, non-zero for failure
+ */
+int asl_set_query(aslmsg a, const char *key, const char *val, uint32_t op)
+{
+ uint32_t i;
+ char *dk, *dv;
+ asl_msg_t *msg;
+
+ msg = (asl_msg_t *)a;
+
+ if (msg == NULL) return 0;
+
+ if (key == NULL) return -1;
+
+ dv = NULL;
+
+ if (streq(key, ASL_KEY_LEVEL))
+ {
+ if (val == NULL) return -1;
+ if (val[0] == '\0') return -1;
+ if ((val[0] >= '0') && (val[0] <= '9'))
+ {
+ i = atoi(val);
+ asprintf(&dv, "%d", i);
+ if (dv == NULL) return -1;
+ }
+ else if (!strcasecmp(val, ASL_STRING_EMERG)) dv = strdup("0");
+ else if (!strcasecmp(val, ASL_STRING_ALERT)) dv = strdup("1");
+ else if (!strcasecmp(val, ASL_STRING_CRIT)) dv = strdup("2");
+ else if (!strcasecmp(val, ASL_STRING_ERR)) dv = strdup("3");
+ else if (!strcasecmp(val, ASL_STRING_WARNING)) dv = strdup("4");
+ else if (!strcasecmp(val, ASL_STRING_NOTICE)) dv = strdup("5");
+ else if (!strcasecmp(val, ASL_STRING_INFO)) dv = strdup("6");
+ else if (!strcasecmp(val, ASL_STRING_DEBUG)) dv = strdup("7");
+ else return -1;
+ }
+
+ if ((dv == NULL) && (val != NULL))
+ {
+ dv = strdup(val);
+ if (dv == NULL) return -1;
+ }
+
+ for (i = 0; i < msg->count; i++)
+ {
+ if (msg->key[i] == NULL) continue;
+
+ if ((msg->type != ASL_TYPE_QUERY) && (streq(msg->key[i], key)))
+ {
+ if (msg->val[i] != NULL) free(msg->val[i]);
+ msg->val[i] = NULL;
+ if (val != NULL) msg->val[i] = dv;
+ if (msg->op != NULL) msg->op[i] = op;
+ return 0;
+ }
+ }
+
+ if (msg->count == 0)
+ {
+ msg->key = (char **)calloc(1, sizeof(char *));
+ if (msg->key == NULL)
+ {
+ asl_free(msg);
+ return -1;
+ }
+
+ msg->val = (char **)calloc(1, sizeof(char *));
+ if (msg->val == NULL)
+ {
+ asl_free(msg);
+ return -1;
+ }
+
+ if (msg->type == ASL_TYPE_QUERY)
+ {
+ msg->op = (uint32_t *)calloc(1, sizeof(uint32_t));
+ if (msg->op == NULL)
+ {
+ asl_free(msg);
+ return -1;
+ }
+ }
+ }
+ else
+ {
+ msg->key = (char **)realloc(msg->key, (msg->count + 1) * sizeof(char *));
+ if (msg->key == NULL)
+ {
+ asl_free(msg);
+ return -1;
+ }
+
+ msg->val = (char **)realloc(msg->val, (msg->count + 1) * sizeof(char *));
+ if (msg->val == NULL)
+ {
+ asl_free(msg);
+ return -1;
+ }
+
+ if (msg->type == ASL_TYPE_QUERY)
+ {
+ msg->op = (uint32_t *)realloc(msg->op, (msg->count + 1) * sizeof(uint32_t));
+ if (msg->op == NULL)
+ {
+ asl_free(msg);
+ return -1;
+ }
+ }
+ }
+
+ dk = strdup(key);
+ if (dk == NULL) return -1;
+
+ msg->key[msg->count] = dk;
+ msg->val[msg->count] = dv;
+ if (msg->op != NULL) msg->op[msg->count] = op;
+ msg->count++;
+
+ return 0;
+}
+
+/*
+ * asl_set: set attributes of a message
+ * msg: an aslmsg
+ * key: attribute key
+ * value: attribute value
+ * returns 0 for success, non-zero for failure
+ */
+int
+asl_set(aslmsg msg, const char *key, const char *val)
+{
+ return asl_set_query(msg, key, val, 0);
+}
+
+/*
+ * asl_unset: remove attributes of a message
+ * msg: an aslmsg
+ * key: attribute key
+ * returns 0 for success, non-zero for failure
+ */
+int
+asl_unset(aslmsg a, const char *key)
+{
+ uint32_t i, j;
+ asl_msg_t *msg;
+
+ msg = (asl_msg_t *)a;
+
+ if (msg == NULL) return 0;
+ if (key == NULL) return 0;
+
+ for (i = 0; i < msg->count; i++)
+ {
+ if (msg->key[i] == NULL) continue;
+
+ if (streq(msg->key[i], key))
+ {
+ free(msg->key[i]);
+ if (msg->val[i] != NULL) free(msg->val[i]);
+
+ for (j = i + 1; j < msg->count; j++, i++)
+ {
+ msg->key[i] = msg->key[j];
+ msg->val[i] = msg->val[j];
+ if (msg->op != NULL) msg->op[i] = msg->op[j];
+ }
+
+ msg->count--;
+
+ if (msg->count == 0)
+ {
+ free(msg->key);
+ msg->key = NULL;
+
+ free(msg->val);
+ msg->val = NULL;
+
+ if (msg->op != NULL) free(msg->op);
+ msg->op = NULL;
+ }
+ else
+ {
+ msg->key = (char **)realloc(msg->key, msg->count * sizeof(char *));
+ if (msg->key == NULL) return -1;
+
+ msg->val = (char **)realloc(msg->val, msg->count * sizeof(char *));
+ if (msg->val == NULL) return -1;
+
+ if (msg->op != NULL)
+ {
+ msg->op = (uint32_t *)realloc(msg->op, msg->count * sizeof(uint32_t));
+ if (msg->op == NULL) return -1;
+ }
+ }
+
+ return 0;
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * asl_search: Search for messages matching the criteria described
+ * by the aslmsg . The caller should set the attributes to match using
+ * asl_set_query() or asl_set(). The operatoin ASL_QUERY_OP_EQUAL is
+ * used for attributes set with asl_set().
+ * a: an aslmsg
+ * returns: a set of messages that can be iterated over using aslresp_next(),
+ * and the values can be retrieved using aslresp_get.
+ */
+aslresponse
+asl_search(aslclient ac, aslmsg a)
+{
+ FILE *log;
+ asl_msg_t *q, *m;
+ asl_search_result_t *res;
+ char *str;
+
+ q = (asl_msg_t *)a;
+
+ if (q == NULL) return 0;
+
+ log = fopen(_PATH_ASL_OUT, "r");
+ if (log == NULL) return NULL;
+
+ res = (asl_search_result_t *)calloc(1, sizeof(asl_search_result_t));
+
+ while (NULL != (str = _get_line_from_file(log)))
+ {
+ m = asl_msg_from_string(str);
+ if (m == NULL) continue;
+ if (asl_msg_cmp(q, m) == 0)
+ {
+ asl_free(m);
+ continue;
+ }
+
+ if (res->count == 0)
+ {
+ res->msg = (asl_msg_t **)calloc(1, sizeof(asl_msg_t *));
+ }
+ else
+ {
+ res->msg = (asl_msg_t **)realloc(res->msg, (res->count + 1) * sizeof(asl_msg_t *));
+ }
+
+ res->msg[res->count] = m;
+ res->count++;
+ }
+
+ fclose(log);
+ return res;
+}
+
+/*
+ * aslresponse_next: Iterate over responses returned from asl_search()
+ * a: a response returned from asl_search();
+ * returns: The next log message (an aslmsg) or NULL on failure
+ */
+aslmsg
+aslresponse_next(aslresponse r)
+{
+ asl_search_result_t *res;
+ aslmsg m;
+
+ res = (asl_search_result_t *)r;
+ if (res == NULL) return NULL;
+
+ if (res->curr >= res->count) return NULL;
+ m = res->msg[res->curr];
+ res->curr++;
+
+ return m;
+}
+
+/*
+ * aslresponse_free: Free a response returned from asl_search()
+ * a: a response returned from asl_search()
+ */
+void
+aslresponse_free(aslresponse r)
+{
+ asl_search_result_t *res;
+ uint32_t i;
+
+ res = (asl_search_result_t *)r;
+ if (res == NULL) return;
+
+ for (i = 0; i < res->count; i++) free(res->msg[i]);
+ free(res->msg);
+ free(res);
+}
+
+int
+asl_syslog_faciliy_name_to_num(const char *name)
+{
+ if (name == NULL) return -1;
+
+ if (strcaseeq(name, "auth")) return LOG_AUTH;
+ if (strcaseeq(name, "authpriv")) return LOG_AUTHPRIV;
+ if (strcaseeq(name, "cron")) return LOG_CRON;
+ if (strcaseeq(name, "daemon")) return LOG_DAEMON;
+ if (strcaseeq(name, "ftp")) return LOG_FTP;
+ if (strcaseeq(name, "install")) return LOG_INSTALL;
+ if (strcaseeq(name, "kern")) return LOG_KERN;
+ if (strcaseeq(name, "lpr")) return LOG_LPR;
+ if (strcaseeq(name, "mail")) return LOG_MAIL;
+ if (strcaseeq(name, "netinfo")) return LOG_NETINFO;
+ if (strcaseeq(name, "remoteauth")) return LOG_REMOTEAUTH;
+ if (strcaseeq(name, "news")) return LOG_NEWS;
+ if (strcaseeq(name, "security")) return LOG_AUTH;
+ if (strcaseeq(name, "syslog")) return LOG_SYSLOG;
+ if (strcaseeq(name, "user")) return LOG_USER;
+ if (strcaseeq(name, "uucp")) return LOG_UUCP;
+ if (strcaseeq(name, "local0")) return LOG_LOCAL0;
+ if (strcaseeq(name, "local1")) return LOG_LOCAL1;
+ if (strcaseeq(name, "local2")) return LOG_LOCAL2;
+ if (strcaseeq(name, "local3")) return LOG_LOCAL3;
+ if (strcaseeq(name, "local4")) return LOG_LOCAL4;
+ if (strcaseeq(name, "local5")) return LOG_LOCAL5;
+ if (strcaseeq(name, "local6")) return LOG_LOCAL6;
+ if (strcaseeq(name, "local7")) return LOG_LOCAL7;
+ if (strcaseeq(name, "launchd")) return LOG_LAUNCHD;
+
+ return -1;
+}
+
+const char *
+asl_syslog_faciliy_num_to_name(int n)
+{
+ if (n < 0) return NULL;
+
+ if (n == LOG_AUTH) return "auth";
+ if (n == LOG_AUTHPRIV) return "authpriv";
+ if (n == LOG_CRON) return "cron";
+ if (n == LOG_DAEMON) return "daemon";
+ if (n == LOG_FTP) return "ftp";
+ if (n == LOG_INSTALL) return "install";
+ if (n == LOG_KERN) return "kern";
+ if (n == LOG_LPR) return "lpr";
+ if (n == LOG_MAIL) return "mail";
+ if (n == LOG_NETINFO) return "netinfo";
+ if (n == LOG_REMOTEAUTH) return "remoteauth";
+ if (n == LOG_NEWS) return "news";
+ if (n == LOG_AUTH) return "security";
+ if (n == LOG_SYSLOG) return "syslog";
+ if (n == LOG_USER) return "user";
+ if (n == LOG_UUCP) return "uucp";
+ if (n == LOG_LOCAL0) return "local0";
+ if (n == LOG_LOCAL1) return "local1";
+ if (n == LOG_LOCAL2) return "local2";
+ if (n == LOG_LOCAL3) return "local3";
+ if (n == LOG_LOCAL4) return "local4";
+ if (n == LOG_LOCAL5) return "local5";
+ if (n == LOG_LOCAL6) return "local6";
+ if (n == LOG_LOCAL7) return "local7";
+ if (n == LOG_LAUNCHD) return "launchd";
+
+ return NULL;
+}
+
+/*
+ * utility for converting a time string into a time_t
+ * we only deal with the following formats:
+ * Canonical form YYYY.MM.DD hh:mm:ss UTC
+ * ctime() form Mth dd hh:mm:ss (e.g. Aug 25 09:54:37)
+ * absolute form - # seconds since the epoch (e.g. 1095789191)
+ * relative time - seconds before or after now (e.g. -300, +43200)
+ * relative time - days/hours/minutes/seconds before or after now (e.g. -1d, +6h, +30m, -10s)
+ */
+
+#define CANONICAL_TIME_REX "^[0-9][0-9][0-9][0-9].[01]?[0-9].[0-3]?[0-9][ ]+[0-2]?[0-9]:[0-5][0-9]:[0-5][0-9][ ]+UTC$"
+#define CTIME_REX "^[adfjmnos][aceopu][bcglnprtvy][ ]+[0-3]?[0-9][ ]+[0-2]?[0-9]:[0-5][0-9]:[0-5][0-9]$"
+#define ABSOLUTE_TIME_REX "^[0-9]+[s]?$"
+#define RELATIVE_TIME_REX "^[\\+-\\][0-9]+[smhdw]?$"
+
+#define SECONDS_PER_MINUTE 60
+#define SECONDS_PER_HOUR 3600
+#define SECONDS_PER_DAY 86400
+#define SECONDS_PER_WEEK 604800
+
+/*
+ * We use the last letter in the month name to determine
+ * the month number (0-11). There are two collisions:
+ * Jan and Jun both end in n
+ * Mar and Apr both end in r
+ * In these cases we check the second letter.
+ *
+ * The MTH_LAST array maps the last letter to a number.
+ */
+static const int8_t MTH_LAST[] = {-1, 1, 11, -1, -1, -1, 7, -1, -1, -1, -1, 6, -1, 5, -1, 8, -1, 3, -1, 9, -1, 10, -1, -1, 4, -1};
+
+static int
+_month_num(char *s)
+{
+ int i;
+ int8_t v8;
+
+ v8 = -1;
+ if (s[2] > 90) v8 = s[2] - 'a';
+ else v8 = s[2] - 'A';
+
+ if ((v8 < 0) || (v8 > 25)) return -1;
+
+ v8 = MTH_LAST[v8];
+ if (v8 < 0) return -1;
+
+ i = v8;
+ if ((i == 5) && ((s[1] == 'a') || (s[1] == 'A'))) return 0;
+ if ((i == 3) && ((s[1] == 'a') || (s[1] == 'A'))) return 2;
+ return i;
+}
+
+time_t
+asl_parse_time(const char *in)
+{
+ int len, y, status, rflags, factor;
+ struct tm t;
+ time_t tick, delta;
+ char *str, *p, *x;
+ static regex_t rex_canon, rex_ctime, rex_abs, rex_rel;
+ static int init_canon = 0;
+ static int init_ctime = 0;
+ static int init_abs = 0;
+ static int init_rel = 0;
+
+ if (in == NULL) return -1;
+
+ rflags = REG_EXTENDED | REG_NOSUB | REG_ICASE;
+
+ if (init_canon == 0)
+ {
+ memset(&rex_canon, 0, sizeof(regex_t));
+ status = regcomp(&rex_canon, CANONICAL_TIME_REX, rflags);
+ if (status != 0) return -1;
+ init_canon = 1;
+ }
+
+ if (init_ctime == 0)
+ {
+ memset(&rex_ctime, 0, sizeof(regex_t));
+ status = regcomp(&rex_ctime, CTIME_REX, rflags);
+ if (status != 0) return -1;
+ init_ctime = 1;
+ }
+
+ if (init_abs == 0)
+ {
+ memset(&rex_abs, 0, sizeof(regex_t));
+ status = regcomp(&rex_abs, ABSOLUTE_TIME_REX, rflags);
+ if (status != 0) return -1;
+ init_abs = 1;
+ }
+
+ if (init_rel == 0)
+ {
+ memset(&rex_rel, 0, sizeof(regex_t));
+ status = regcomp(&rex_rel, RELATIVE_TIME_REX, rflags);
+ if (status != 0) return -1;
+ init_rel = 1;
+ }
+
+ len = strlen(in) + 1;
+
+ if (regexec(&rex_abs, in, 0, NULL, 0) == 0)
+ {
+ /*
+ * Absolute time (number of seconds since the epoch)
+ */
+ str = strdup(in);
+ if ((str[len-2] == 's') || (str[len-2] == 'S')) str[len-2] = '\0';
+
+ tick = atoi(str);
+ free(str);
+
+ return tick;
+ }
+ else if (regexec(&rex_rel, in, 0, NULL, 0) == 0)
+ {
+ /*
+ * Reletive time (number of seconds before or after right now)
+ */
+ str = strdup(in);
+
+ factor = 1;
+
+ if ((str[len-2] == 's') || (str[len-2] == 'S'))
+ {
+ str[len-2] = '\0';
+ }
+ else if ((str[len-2] == 'm') || (str[len-2] == 'M'))
+ {
+ str[len-2] = '\0';
+ factor = SECONDS_PER_MINUTE;
+ }
+ else if ((str[len-2] == 'h') || (str[len-2] == 'H'))
+ {
+ str[len-2] = '\0';
+ factor = SECONDS_PER_HOUR;
+ }
+ else if ((str[len-2] == 'd') || (str[len-2] == 'D'))
+ {
+ str[len-2] = '\0';
+ factor = SECONDS_PER_DAY;
+ }
+ else if ((str[len-2] == 'w') || (str[len-2] == 'W'))
+ {
+ str[len-2] = '\0';
+ factor = SECONDS_PER_WEEK;
+ }
+
+ tick = time(NULL);
+ delta = factor * atoi(str);
+ tick += delta;
+
+ free(str);
+
+ return tick;
+ }
+ else if (regexec(&rex_canon, in, 0, NULL, 0) == 0)
+ {
+ memset(&t, 0, sizeof(struct tm));
+ str = strdup(in);
+
+ /* Get year */
+ x = str;
+ p = strchr(x, '.');
+ *p = '\0';
+ t.tm_year = atoi(x) - 1900;
+
+ /* Get month */
+ x = p + 1;
+ p = strchr(x, '.');
+ *p = '\0';
+ t.tm_mon = atoi(x) - 1;
+
+ /* Get day */
+ x = p + 1;
+ p = strchr(x, ' ');
+ *p = '\0';
+ t.tm_mday = atoi(x);
+
+ /* Get hour */
+ for (x = p + 1; *x == ' '; x++);
+ p = strchr(x, ':');
+ *p = '\0';
+ t.tm_hour = atoi(x);
+
+ /* Get minutes */
+ x = p + 1;
+ p = strchr(x, ':');
+ *p = '\0';
+ t.tm_min = atoi(x);
+
+ /* Get seconds */
+ x = p + 1;
+ p = strchr(x, ' ');
+ *p = '\0';
+ t.tm_sec = atoi(x);
+
+ free(str);
+ return timegm(&t);
+ }
+ else if (regexec(&rex_ctime, in, 0, NULL, 0) == 0)
+ {
+ /* We assume it's in the current year */
+ memset(&t, 0, sizeof(struct tm));
+ tick = time(NULL);
+ gmtime_r(&tick, &t);
+ y = t.tm_year;
+
+ memset(&t, 0, sizeof(struct tm));
+ str = strdup(in);
+
+ t.tm_year = y;
+ t.tm_mon = _month_num(str);
+ if (t.tm_mon < 0) return -1;
+
+ for (x = strchr(str, ' '); *x == ' '; x++);
+ p = strchr(x, ' ');
+ *p = '\0';
+ t.tm_mday = atoi(x);
+
+ /* Get hour */
+ for (x = p + 1; *x == ' '; x++);
+ p = strchr(x, ':');
+ *p = '\0';
+ t.tm_hour = atoi(x);
+
+ /* Get minutes */
+ x = p + 1;
+ p = strchr(x, ':');
+ *p = '\0';
+ t.tm_min = atoi(x);
+
+ /* Get seconds */
+ x = p + 1;
+ t.tm_sec = atoi(x);
+
+ t.tm_isdst = -1;
+
+ free(str);
+ return mktime(&t);
+ }
+
+ return -1;
+}
+
+#ifdef ASL_SYSLOG_COMPAT
+
+__private_extern__ void
+asl_syslog_syslog(int pri, const char *fmt, ...)
+{
+ va_list ap;
+ asl_msg_t *m;
+
+ if (fmt == NULL) return;
+
+ m = asl_new(ASL_TYPE_MSG);
+
+ va_start(ap, fmt);
+ asl_vlog(NULL, m, pri, fmt, ap);
+ va_end(ap);
+
+ asl_free(m);
+}
+
+__private_extern__ void
+asl_syslog_vsyslog(int pri, const char *fmt, va_list ap)
+{
+ asl_msg_t *m;
+
+ m = asl_new(ASL_TYPE_MSG);
+ asl_vlog(NULL, m, pri, fmt, ap);
+ asl_free(m);
+}
+
+__private_extern__ void
+asl_syslog_openlog(const char *ident, int flags, int facility)
+{
+ const char *fname;
+ uint32_t opts;
+
+ opts = 0;
+
+ if (flags & LOG_NDELAY) opts |= ASL_OPT_NO_DELAY;
+ if (flags & LOG_PERROR) opts |= ASL_OPT_STDERR;
+
+ fname = asl_syslog_faciliy_num_to_name(facility);
+ if (fname == NULL) fname = "user";
+
+ asl_global_client = asl_open(ident, fname, opts);
+}
+
+__private_extern__ void
+asl_syslog_closelog()
+{
+ asl_close();
+}
+
+__private_extern__ int
+asl_syslog_setlogmask(int p)
+{
+ return asl_set_filter(p);
+}
+
+#endif ASL_SYSLOG_COMPAT
+
+#endif /* BUILDING_VARIANT */
--- /dev/null
+#include <stdint.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#define _PATH_ASL_OUT "/var/log/asl.log"
+
+#define ASL_QUERY_OP_NULL 0x00000
+
+#define NOTIFY_SYSTEM_MASTER "com.apple.system.syslog.master"
+#define NOTIFY_SYSTEM_ASL_FILTER "com.apple.system.syslog.asl_filter"
+#define NOTIFY_PREFIX_SYSTEM "com.apple.system.syslog"
+#define NOTIFY_PREFIX_USER "user.syslog"
+
+typedef struct __aslclient
+{
+ uint32_t options;
+ struct sockaddr_un server;
+ int sock;
+ pid_t pid;
+ uid_t uid;
+ gid_t gid;
+ char *name;
+ char *facility;
+ uint32_t filter;
+ int notify_token;
+ int notify_master_token;
+ uint32_t fd_count;
+ int *fd_list;
+ uint32_t reserved1;
+ void *reserved2;
+} asl_client_t;
+
+typedef struct __aslmsg
+{
+ uint32_t type;
+ uint32_t count;
+ char **key;
+ char **val;
+ uint32_t *op;
+} asl_msg_t;
+
+typedef struct __aslresponse
+{
+ uint32_t count;
+ uint32_t curr;
+ asl_msg_t **msg;
+} asl_search_result_t;
+++ /dev/null
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-/*
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- */
-
-
-/* We let the compiler's assert.h own the implementation */
-#if !defined(__APPLE__)
-
-#include <sys/types.h>
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-void
-__assert(file, line, failedexpr)
- const char *file, *failedexpr;
- int line;
-{
- (void)fprintf(stderr,
- "assertion \"%s\" failed: file \"%s\", line %d\n",
- failedexpr, file, line);
- abort();
- /* NOTREACHED */
-}
-#endif
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+.Dd October 7, 2004
+.Os Darwin
+.Dt COMPAT 5
+.Sh NAME
+.Nm compat
+.Nd manipulate compatibility settings
+.Sh SYNOPSIS
+.Ev COMMAND_MODE=legacy|unix2003
+.Lp
+.Fd #define _POSIX_C_SOURCE
+.Fd #define _APPLE_C_SOURE
+.Fd #define _NONSTD_SOURCE
+.Fd #define __LP64__
+.Sh DESCRIPTION
+Setting the environment variable
+.Ev COMMAND_MODE
+to the value legacy causes utility programs to behave as closely to Mac OS X 10.3's utility programs as possible. When in this mode all of 10.3's flags are accepted, and in some cases extra flags are accepted, but no flags that were used in 10.3 will have been removed or changed in meaning. Any behavioral changes in this mode are documented in the LEGACY sections of the individual utilities.
+.Pp
+Setting the environment variable
+.Ev COMMAND_MODE
+to the value unix03 causes utility programs to obey the
+.St -susv3
+standards even if doing so would alter the behavior of flags used in 10.3.
+.Pp
+.Ev COMMAND_MODE's
+value is case insensitive and if it is unset or set to something other than legacy or unix03 it behaves as if it were set to unix03.
+.Pp
+Defining
+.Dv _NONSTD_SOURCE
+causes library and kernel calls to behave as closely to Mac OS X 10.3's library and kernel calls as possible. Any behavioral changes in this mode are documented in the LEGACY sections of the individual function calls.
+.Pp
+Defining any of
+.Dv _POSIX_C_SOURCE,
+.Dv _APPLE_C_SOURE,
+or
+.Dv __LP64__
+causes library and kernel calls to conform to
+.St -susv3
+standards even if doing so would alter the behavior of functions used in 10.3. Defining
+.Dv _POSIX_C_SOURCE
+also removes functions, types, and other interfaces that are not part of
+.St -susv3
+from the normal C namespace, while
+.Dv _APPLE_C_SOURE
+does not.
+.Pp
+Failing to define any of those symbols currently acts as if you have defined
+.Dv _NONSTD_SOURCE
+but it is expected that in a future OS X release the default behavior will change to be as if
+.Dv _APPLE_C_SOURE
+were defined.
+.Sh STANDARDS
+With COMMAND_MODE set to unix2003 utility functions conform to
+.St -susv3
+.Pp
+With
+.Dv _POSIX_C_SOURCE,
+.Dv _APPLE_C_SOURE,
+or
+.Dv __LP64__
+system and library calls conform to
+.St -susv3
+.Sh BUGS
+Different parts of a program can be compiled with different compatibility settings. The resultant program will normally work as expected, for example a regex created by the
+.St -susv3
+.Fn regcomp 3
+can be passed to the legacy
+.Fn regfree 3
+with no unexpected results. Some cases are less clear cut, for example
+what does the programmer intend when they use the
+.Fn -susv3
+.Fn regcomp 3
+to compile a regex, but the legacy
+.Fn regexec 3
+to execute it? Any interpretation will surprise someone.
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
-/*
- * PR-3509199
- *
- * encrypt() and setkey() should return void, but were returning int. For
- * backwards compatibility, define __APPLE_PR_3509199_COMPAT__ to continue
- * to return int, even though unistd.h declares void. We will need to not
- * include unistd.h so as to avoid the prototype mismatch.
- */
-#ifndef __APPLE_PR_3509199_COMPAT__
+#include <sys/cdefs.h>
#include <unistd.h>
-#endif /* __APPLE_PR_3509199_COMPAT__ */
#include <limits.h>
+#include <sys/types.h>
#include <pwd.h>
#include <stdlib.h>
/*
* define "MUST_ALIGN" if your compiler cannot load/store
* long integers at arbitrary (e.g. odd) memory locations.
- * (Either that or never pass unaligned addresses to des_cipher!)
+ * (Either that or never pass unaligned addresses to __crypt_des_cipher!)
*/
#if !defined(vax)
#define MUST_ALIGN
* define "LONG_IS_32_BITS" only if sizeof(long)==4.
* This avoids use of bit fields (your compiler may be sloppy with them).
*/
-#if !defined(cray)
+#if !defined(cray) && (LONG_BIT == 32)
#define LONG_IS_32_BITS
#endif
/*
* define "LARGEDATA" to get faster permutations, by using about 72 kilobytes
- * of lookup tables. This speeds up des_setkey() and des_cipher(), but has
+ * of lookup tables. This speeds up __crypt_des_setkey() and __crypt_des_cipher(), but has
* little effect on crypt().
*/
#if defined(notdef)
#ifndef STATIC
#define STATIC static
#endif
+#ifndef BUILDING_VARIANT
STATIC void init_des(), init_perm(), permute();
-STATIC int des_cipher(), des_setkey();
+#endif /* BUILDING_VARIANT */
+__private_extern__ int __crypt_des_cipher(), __crypt_des_setkey();
#ifdef DEBUG
STATIC prtab();
#endif
#define PERM3264(d,d0,d1,cpp,p) \
{ C_block tblk; permute(cpp,&tblk,p,4); LOAD (d,d0,d1,tblk); }
+#ifndef BUILDING_VARIANT
STATIC void permute(cp, out, p, chars_in)
unsigned char *cp;
C_block *out;
} while (--chars_in > 0);
STORE(D,D0,D1,*out);
}
+#endif /* BUILDING_VARIANT */
#endif /* LARGEDATA */
/* ===== (mostly) Standard DES Tables ==================== */
+#ifndef BUILDING_VARIANT
static unsigned char IP[] = { /* initial permutation */
58, 50, 42, 34, 26, 18, 10, 2,
60, 52, 44, 36, 28, 20, 12, 4,
key++;
keyblock.b[i] = t;
}
- if (des_setkey((char *)keyblock.b)) /* also initializes "a64toi" */
+ if (__crypt_des_setkey((char *)keyblock.b)) /* also initializes "a64toi" */
return (NULL);
encp = &cryptresult[0];
* Involve the rest of the password 8 characters at a time.
*/
while (*key) {
- if (des_cipher((char *)&keyblock,
+ if (__crypt_des_cipher((char *)&keyblock,
(char *)&keyblock, 0L, 1))
return (NULL);
for (i = 0; i < 8; i++) {
key++;
keyblock.b[i] ^= t;
}
- if (des_setkey((char *)keyblock.b))
+ if (__crypt_des_setkey((char *)keyblock.b))
return (NULL);
}
salt = (salt<<6) | a64toi[t];
}
encp += salt_size;
- if (des_cipher((char *)&constdatablock, (char *)&rsltblock,
+ if (__crypt_des_cipher((char *)&constdatablock, (char *)&rsltblock,
salt, num_iter))
return (NULL);
/*
- * The Key Schedule, filled in by des_setkey() or setkey().
+ * The Key Schedule, filled in by __crypt_des_setkey() or setkey().
*/
#define KS_SIZE 16
static C_block KS[KS_SIZE];
/*
* Set up the key schedule from the key.
*/
-STATIC int des_setkey(key)
+__private_extern__ int __crypt_des_setkey(key)
register const char *key;
{
register DCL_BLOCK(K, K0, K1);
* NOTE: the performance of this routine is critically dependent on your
* compiler and machine architecture.
*/
-STATIC int des_cipher(in, out, salt, num_iter)
+__private_extern__ int __crypt_des_cipher(in, out, salt, num_iter)
const char *in;
char *out;
long salt;
#endif
register long L0, L1, R0, R1, k;
register C_block *kp;
- register int ks_inc, loop_count;
+ register int loop_count;
+ ssize_t ks_inc;
C_block B;
L0 = salt;
}
}
}
+#endif /* BUILDING_VARIANT */
/*
* "setkey" routine (for backwards compatibility)
*/
-#ifdef __APPLE_PR_3509199_COMPAT__
-int setkey(key)
-#else /* __APPLE_PR_3509199_COMPAT__ */
+#if __DARWIN_UNIX03
void setkey(key)
-#endif /* __APPLE_PR_3509199_COMPAT__ */
+#else /* !__DARWIN_UNIX03 */
+int setkey(key)
+#endif /* __DARWIN_UNIX03 */
register const char *key;
{
register int i, j, k;
}
keyblock.b[i] = k;
}
-#ifdef __APPLE_PR_3509199_COMPAT__
- return (des_setkey((char *)keyblock.b));
-#else /* __APPLE_PR_3509199_COMPAT__ */
- des_setkey((char *)keyblock.b);
-#endif /* __APPLE_PR_3509199_COMPAT__ */
+#if __DARWIN_UNIX03
+ __crypt_des_setkey((char *)keyblock.b);
+#else /* !__DARWIN_UNIX03 */
+ return (__crypt_des_setkey((char *)keyblock.b));
+#endif /* __DARWIN_UNIX03 */
}
/*
* "encrypt" routine (for backwards compatibility)
*/
-#ifdef __APPLE_PR_3509199_COMPAT__
-int encrypt(block, flag)
-#else /* __APPLE_PR_3509199_COMPAT__ */
+#if __DARWIN_UNIX03
void encrypt(block, flag)
-#endif /* __APPLE_PR_3509199_COMPAT__ */
+#else /* !__DARWIN_UNIX03 */
+int encrypt(block, flag)
+#endif /* __DARWIN_UNIX03 */
register char *block;
int flag;
{
}
cblock.b[i] = k;
}
-#ifdef __APPLE_PR_3509199_COMPAT__
- if (des_cipher((char *)&cblock, (char *)&cblock, 0L, (flag ? -1: 1)))
+ if (__crypt_des_cipher((char *)&cblock, (char *)&cblock, 0L, (flag ? -1: 1)))
+#if __DARWIN_UNIX03
+ return;
+#else /* !__DARWIN_UNIX03 */
return (1);
-#else /* __APPLE_PR_3509199_COMPAT__ */
- (void)des_cipher((char *)&cblock, (char *)&cblock, 0L, (flag ? -1: 1));
-#endif /* __APPLE_PR_3509199_COMPAT__ */
+#endif /* __DARWIN_UNIX03 */
for (i = 7; i >= 0; i--) {
k = cblock.b[i];
for (j = 7; j >= 0; j--) {
k >>= 1;
}
}
-#ifdef __APPLE_PR_3509199_COMPAT__
+#if !__DARWIN_UNIX03
return (0);
-#endif /* __APPLE_PR_3509199_COMPAT__ */
+#endif /* !__DARWIN_UNIX03 */
}
+#ifndef BUILDING_VARIANT
#ifdef DEBUG
STATIC
prtab(s, t, num_rows)
(void)printf("\n");
}
#endif
+#endif /* BUILDING_VARIANT */
.\" @(#)devname.3 8.2 (Berkeley) 4/29/95
.\" $FreeBSD: src/lib/libc/gen/devname.3,v 1.11 2001/10/01 16:08:50 ru Exp $
.\"
-.Dd April 29, 1995
+.Dd October 25, 2004
.Dt DEVNAME 3
.Os
.Sh NAME
.In stdlib.h
.Ft char *
.Fn devname "dev_t dev" "mode_t type"
+.Ft char *
+.Fn devname_r "dev_t dev" "mode_t type" "char *buf" "int len"
.Sh DESCRIPTION
The
.Fn devname
.Fa dev ,
and a file type matching the one encoded in
.Fa type
-which must be one of S_IFBLK or S_IFCHR.
+which must be one of
+.Dv S_IFBLK
+or
+.Dv S_IFCHR .
If no device matches the specified values, or no information is
available, NULL is returned.
.Pp
+The
+.Fn devname
+function uses a static buffer, which will be overwritten
+on subsequent calls.
+The
+.Fn devname_r
+functions takes a buffer and length as arguments to avoid this problem.
+.Pp
The traditional display for applications when no device is
found is the string
.Dq ?? .
/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999, 2004 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#include <stdlib.h>
char *
-devname(dev, type)
- dev_t dev;
- mode_t type;
+devname_r(dev_t dev, mode_t type, char *buf, int len)
{
register DIR *dp;
register struct dirent *dirp;
struct stat sb;
- static char *buf = NULL;
+ char _buf[sizeof(_PATH_DEV) + MAXNAMLEN];
- if( buf == NULL ) {
- buf = malloc(sizeof(_PATH_DEV) + MAXNAMLEN);
- if( buf == NULL )
- return NULL;
- strcpy(buf, _PATH_DEV);
- }
+ strcpy(_buf, _PATH_DEV);
if ((dp = opendir(_PATH_DEV)) == NULL)
return (NULL);
while ( (dirp = readdir(dp)) ) {
- bcopy(dirp->d_name, buf + sizeof(_PATH_DEV) - 1,
+ bcopy(dirp->d_name, _buf + sizeof(_PATH_DEV) - 1,
dirp->d_namlen + 1);
- if (stat(buf, &sb))
+ if (lstat(_buf, &sb))
continue;
if (dev != sb.st_rdev)
continue;
if (type != (sb.st_mode & S_IFMT))
continue;
+ if (dirp->d_namlen + 1 > len)
+ break;
+ strcpy(buf, dirp->d_name);
(void)closedir(dp);
- return (buf + sizeof(_PATH_DEV) - 1);
+ return (buf);
}
(void)closedir(dp);
return (NULL);
}
+
+char *
+devname(dev_t dev, mode_t type)
+{
+ static char *buf = NULL;
+
+ if( buf == NULL ) {
+ buf = malloc(MAXNAMLEN);
+ if( buf == NULL )
+ return NULL;
+ }
+
+ return (devname_r(dev, type, buf, MAXNAMLEN));
+}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
"Protocol not available", /* 42 - ENOPROTOOPT */
"Protocol not supported", /* 43 - EPROTONOSUPPORT */
"Socket type not supported", /* 44 - ESOCKTNOSUPPORT */
- "Operation not supported", /* 45 - EOPNOTSUPP */
+ "Operation not supported", /* 45 - ENOTSUP */
"Protocol family not supported", /* 46 - EPFNOSUPPORT */
/* 47 - EAFNOSUPPORT */
"Address family not supported by protocol family",
"Not a STREAM", /* 99 - ENOSTR */
"Protocol error", /* 100 - EPROTO */
"STREAM ioctl timeout", /* 101 - ETIME */
+ "Operation not supported on socket", /* 102 - EOPNOTSUPP */
};
const int sys_nerr = sizeof(sys_errlist) / sizeof(sys_errlist[0]);
--- /dev/null
+/*
+ * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include <sys/types.h>
+#include <sys/acl.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <strings.h>
+#include <errno.h>
+#include <uuid/uuid.h>
+
+
+struct _filesec {
+ int fs_valid;
+#define FS_VALID_UID (1<<0)
+#define FS_VALID_GID (1<<1)
+#define FS_VALID_UUID (1<<2)
+#define FS_VALID_GRPUUID (1<<3)
+#define FS_VALID_MODE (1<<4)
+#define FS_VALID_ACL (1<<5)
+ uid_t fs_uid;
+ gid_t fs_gid;
+ uuid_t fs_uuid;
+ uuid_t fs_grpuuid;
+ mode_t fs_mode;
+ size_t fs_aclsize;
+ void *fs_aclbuf;
+};
+
+#define FS_ISVALID(_fsec, _bit) ((_fsec)->fs_valid & (_bit))
+#define FS_CLEAR(_fsec, _bit) ((_fsec)->fs_valid &= ~(_bit))
+#define FS_SET(_fsec, _bit) ((_fsec)->fs_valid |= (_bit))
+
+static void filesec_discard_aclbuf(struct _filesec *fsec);
+
+filesec_t
+filesec_init(void)
+{
+ struct _filesec *fsp;
+
+ fsp = malloc(sizeof(*fsp));
+ if (fsp != NULL)
+ fsp->fs_valid = 0;
+ return(fsp);
+}
+
+filesec_t
+filesec_dup(filesec_t fsec)
+{
+ struct _filesec *fsp;
+
+ fsp = malloc(sizeof(*fsp));
+ if (fsp != NULL) {
+ *fsp = *fsec;
+ if (FS_ISVALID(fsec, FS_VALID_ACL)) {
+ if (fsec->fs_aclbuf != _FILESEC_REMOVE_ACL) {
+ fsp->fs_aclbuf = malloc(fsec->fs_aclsize);
+ if (fsp->fs_aclbuf == NULL) {
+ free(fsp);
+ return(NULL);
+ }
+ bcopy(fsec->fs_aclbuf, fsp->fs_aclbuf, fsec->fs_aclsize);
+ }
+ }
+ }
+ return(fsp);
+}
+
+void
+filesec_free(filesec_t fsec)
+{
+ filesec_discard_aclbuf(fsec);
+ free(fsec);
+}
+
+int
+filesec_get_property(filesec_t fsec, filesec_property_t property, void *propptr)
+{
+ int error;
+
+ error = 0;
+ switch(property) {
+ case FILESEC_OWNER:
+ if (!FS_ISVALID(fsec, FS_VALID_UID)) {
+ error = ENOENT;
+ break;
+ }
+ if (propptr != NULL)
+ *(uid_t *)propptr = fsec->fs_uid;
+ break;
+ case FILESEC_GROUP:
+ if (!FS_ISVALID(fsec, FS_VALID_GID)) {
+ error = ENOENT;
+ break;
+ }
+ if (propptr != NULL)
+ *(gid_t *)propptr = fsec->fs_gid;
+ break;
+ case FILESEC_UUID:
+ if (!FS_ISVALID(fsec, FS_VALID_UUID)) {
+ error = ENOENT;
+ break;
+ }
+ if (propptr != NULL)
+ uuid_copy(*(uuid_t *)propptr, fsec->fs_uuid);
+ break;
+ case FILESEC_GRPUUID:
+ if (!FS_ISVALID(fsec, FS_VALID_GRPUUID)) {
+ error = ENOENT;
+ break;
+ }
+ if (propptr != NULL)
+ uuid_copy(*(uuid_t *)propptr, fsec->fs_grpuuid);
+ break;
+ case FILESEC_MODE:
+ if (!FS_ISVALID(fsec, FS_VALID_MODE)) {
+ error = ENOENT;
+ break;
+ }
+ if (propptr != NULL)
+ *(mode_t *)propptr = fsec->fs_mode;
+ break;
+ case FILESEC_ACL:
+ if (!FS_ISVALID(fsec, FS_VALID_ACL)) {
+ error = ENOENT;
+ break;
+ }
+ if (propptr != NULL) {
+ if (fsec->fs_aclbuf == _FILESEC_REMOVE_ACL) {
+ *(acl_t *)propptr = _FILESEC_REMOVE_ACL;
+ } else {
+ *(acl_t *)propptr = acl_copy_int(fsec->fs_aclbuf);
+ if (*(acl_t *)propptr == NULL)
+ error = errno;
+ }
+ }
+ break;
+ case FILESEC_ACL_RAW:
+ if (!FS_ISVALID(fsec, FS_VALID_ACL)) {
+ error = ENOENT;
+ break;
+ }
+ if (propptr != NULL)
+ *(void **)propptr = fsec->fs_aclbuf;
+ break;
+ case FILESEC_ACL_ALLOCSIZE:
+ if (!FS_ISVALID(fsec, FS_VALID_ACL)) {
+ error = ENOENT;
+ break;
+ }
+ if (propptr != NULL)
+ *(size_t *)propptr = fsec->fs_aclsize;
+ break;
+ default:
+ error = EINVAL;
+ break;
+ }
+ if (error) {
+ errno = error;
+ return(-1);
+ }
+ return(0);
+}
+
+int
+filesec_set_property(filesec_t fsec, filesec_property_t property, const void *propptr)
+{
+ void *aclbuf;
+ ssize_t aclsize, copysize;
+ acl_t acl;
+ int error;
+
+ error = 0;
+ switch(property) {
+ case FILESEC_OWNER:
+ if (propptr == _FILESEC_UNSET_PROPERTY) {
+ FS_CLEAR(fsec, FS_VALID_UID);
+ } else {
+ fsec->fs_uid = *(uid_t *)propptr;
+ FS_SET(fsec, FS_VALID_UID);
+ }
+ break;
+ case FILESEC_GROUP:
+ if (propptr == _FILESEC_UNSET_PROPERTY) {
+ FS_CLEAR(fsec, FS_VALID_GID);
+ } else {
+ fsec->fs_gid = *(gid_t *)propptr;
+ FS_SET(fsec, FS_VALID_GID);
+ }
+ break;
+ case FILESEC_UUID:
+ if (propptr == _FILESEC_UNSET_PROPERTY) {
+ FS_CLEAR(fsec, FS_VALID_UUID);
+ } else {
+ uuid_copy(fsec->fs_uuid, *(uuid_t *)propptr);
+ FS_SET(fsec, FS_VALID_UUID);
+ }
+ break;
+ case FILESEC_GRPUUID:
+ if (propptr == _FILESEC_UNSET_PROPERTY) {
+ FS_CLEAR(fsec, FS_VALID_GRPUUID);
+ } else {
+ uuid_copy(fsec->fs_grpuuid, *(uuid_t *)propptr);
+ FS_SET(fsec, FS_VALID_GRPUUID);
+ }
+ break;
+ case FILESEC_MODE:
+ if (propptr == _FILESEC_UNSET_PROPERTY) {
+ FS_CLEAR(fsec, FS_VALID_MODE);
+ } else {
+ fsec->fs_mode = *(mode_t *)propptr;
+ FS_SET(fsec, FS_VALID_MODE);
+ }
+ break;
+ case FILESEC_ACL:
+ if (propptr == _FILESEC_UNSET_PROPERTY) {
+ filesec_discard_aclbuf(fsec);
+ FS_CLEAR(fsec, FS_VALID_ACL);
+ } else if (propptr == _FILESEC_REMOVE_ACL) {
+ filesec_discard_aclbuf(fsec);
+ fsec->fs_aclbuf = _FILESEC_REMOVE_ACL;
+ fsec->fs_aclsize = 0;
+ FS_SET(fsec, FS_VALID_ACL);
+ } else {
+ acl = *(acl_t *)propptr;
+ aclsize = acl_size(acl);
+ if (aclsize < 0) {
+ error = errno;
+ break;
+ }
+ if ((aclbuf = malloc(aclsize)) == NULL) {
+ error = errno;
+ break;
+ }
+ copysize = acl_copy_ext(aclbuf, acl, aclsize);
+ if (copysize < 0) {
+ free(aclbuf);
+ error = EINVAL;
+ break;
+ }
+ filesec_discard_aclbuf(fsec);
+ fsec->fs_aclbuf = aclbuf;
+ fsec->fs_aclsize = aclsize;
+ FS_SET(fsec, FS_VALID_ACL);
+ }
+ break;
+ case FILESEC_ACL_RAW:
+ filesec_discard_aclbuf(fsec);
+ if ((propptr != NULL) && (*(void **)propptr != NULL)) {
+ fsec->fs_aclbuf = *(void **)propptr;
+ FS_SET(fsec, FS_VALID_ACL);
+ }
+ break;
+ case FILESEC_ACL_ALLOCSIZE:
+ if (propptr != NULL) {
+ fsec->fs_aclsize = *(size_t *)propptr;
+ } else {
+ error = EINVAL;
+ }
+ break;
+ default:
+ error = EINVAL;
+ break;
+ }
+ if (error != 0) {
+ errno = error;
+ return (-1);
+ }
+ return (0);
+}
+
+int
+filesec_query_property(filesec_t fsec, filesec_property_t property, int *validptr)
+{
+ int valid, error;
+
+ error = 0;
+ switch(property) {
+ case FILESEC_OWNER:
+ valid = FS_ISVALID(fsec, FS_VALID_UID);
+ break;
+ case FILESEC_GROUP:
+ valid = FS_ISVALID(fsec, FS_VALID_GID);
+ break;
+ case FILESEC_UUID:
+ valid = FS_ISVALID(fsec, FS_VALID_UUID);
+ break;
+ case FILESEC_GRPUUID:
+ valid = FS_ISVALID(fsec, FS_VALID_GRPUUID);
+ break;
+ case FILESEC_MODE:
+ valid = FS_ISVALID(fsec, FS_VALID_MODE);
+ break;
+ case FILESEC_ACL:
+ case FILESEC_ACL_RAW:
+ case FILESEC_ACL_ALLOCSIZE:
+ valid = FS_ISVALID(fsec, FS_VALID_ACL);
+ break;
+ default:
+ error = EINVAL;
+ break;
+ }
+
+ if (error != 0) {
+ errno = error;
+ return(-1);
+ }
+ *validptr = valid;
+ return(0);
+}
+
+static void
+filesec_discard_aclbuf(struct _filesec *fsec)
+{
+ if (FS_ISVALID(fsec, FS_VALID_ACL)) {
+ if (fsec->fs_aclbuf != _FILESEC_REMOVE_ACL)
+ free(fsec->fs_aclbuf);
+ fsec->fs_aclbuf = NULL;
+ fsec->fs_aclsize = 0;
+ FS_CLEAR(fsec, FS_VALID_ACL);
+ }
+}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
and
.Xr readdir 3 .
If the
-.Dv FGTW_CHDIR
+.Dv FTW_CHDIR
flag is set, the
.Fn nftw
function may fail and set
argument is less than 1 or greater than
.Dv OPEN_MAX .
.El
+.Sh LEGACY ERRORS
+The
+.Fn ftw
+and
+.Fn nftw
+functions are far more tolerant of symlink cycles and are lax in reporting
+errors while accessing the initial path. When
+.Fn nftw
+is passed
+.Dv FTW_MOUNT
+it will pass the callback the mount point.
.Sh SEE ALSO
.Xr chdir 2 ,
.Xr close 2 ,
.Xr open 2 ,
.Xr stat 2 ,
+.Xr compat 5 ,
.Xr fts 3 ,
.Xr malloc 3 ,
.Xr opendir 3 ,
and
.Fn nftw
functions conform to
-.St -p1003.1-2001 .
+.St -p1003.1-2001 and
+.St -susv3 .
+.Sh HISTORY
+Prior to MacOS X 10.4
+.Nm ftw
+did not follow symlinks.
.Sh BUGS
The
.Fa maxfds
+++ /dev/null
-/* $OpenBSD: ftw.c,v 1.2 2003/07/21 21:15:32 millert Exp $ */
-
-/*
- * Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Sponsored in part by the Defense Advanced Research Projects
- * Agency (DARPA) and Air Force Research Laboratory, Air Force
- * Materiel Command, USAF, under agreement number F39502-99-1-0512.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$OpenBSD: ftw.c,v 1.2 2003/07/21 21:15:32 millert Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <fts.h>
-#include <ftw.h>
-#include <limits.h>
-
-int
-ftw(const char *path, int (*fn)(const char *, const struct stat *, int),
- int nfds)
-{
- const char *paths[2];
- FTSENT *cur;
- FTS *ftsp;
- int fnflag, error, sverrno;
-
- /* XXX - nfds is currently unused */
- if (nfds < 1 || nfds > OPEN_MAX) {
- errno = EINVAL;
- return (-1);
- }
-
- paths[0] = path;
- paths[1] = NULL;
- ftsp = fts_open((char * const *)paths, FTS_COMFOLLOW | FTS_NOCHDIR,
- NULL);
- if (ftsp == NULL)
- return (-1);
- error = 0;
- while ((cur = fts_read(ftsp)) != NULL) {
- switch (cur->fts_info) {
- case FTS_D:
- fnflag = FTW_D;
- break;
- case FTS_DNR:
- fnflag = FTW_DNR;
- break;
- case FTS_DP:
- /* we only visit in preorder */
- continue;
- case FTS_F:
- case FTS_DEFAULT:
- fnflag = FTW_F;
- break;
- case FTS_NS:
- case FTS_NSOK:
- case FTS_SLNONE:
- fnflag = FTW_NS;
- break;
- case FTS_SL:
- fnflag = FTW_SL;
- break;
- case FTS_DC:
- errno = ELOOP;
- /* FALLTHROUGH */
- default:
- error = -1;
- goto done;
- }
- error = fn(cur->fts_path, cur->fts_statp, fnflag);
- if (error != 0)
- break;
- }
-done:
- sverrno = errno;
- (void) fts_close(ftsp);
- errno = sverrno;
- return (error);
-}
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <pthread.h>
+
+static bool def_unix03 = false;
+/* Catastrophic errors only, including "out of memory" */
+static bool parse_error = false;
+static bool bootstrapping = false;
+static bool parsed = false;
+#define UNIX2003_DEFAULT_MODE true
+static bool unix2003_mode = UNIX2003_DEFAULT_MODE;
+
+static pthread_once_t threadsafe = PTHREAD_ONCE_INIT;
+
+/* There was once a lot of parsing and the ability to set diffrent commands
+ to diffrent modes. That is gone, but some of the scaffolding remains */
+
+static void check_env_var(void) {
+ char *mode = getenv("COMMAND_MODE");
+
+ if (mode) {
+ if (!strcasecmp(mode, "legacy")) {
+ unix2003_mode = false;
+ } else {
+ if (!strcasecmp(mode, "unix2003")) {
+ unix2003_mode = true;
+ } else {
+ parse_error = true;
+ unix2003_mode = UNIX2003_DEFAULT_MODE;
+ }
+ }
+ }
+}
+
+/* Function is expected to be something like libc/malloc for a libc call,
+or bin/date for command line utilities. Modes are currently:
+ Legacy - pre-tiger behaviour, presumably UNIX2003 incompatable
+ UNIX2003 - Unix 2003 spec compliant
+ Bootstrap - only seen by (parts of) libc. The compat_mode system is
+ still starting up. This will be seen while compat_mode parses it's
+ config file, or reads the cache file, and only by libc functions it calls.
+ Error - the conf file could not be parsed, either due to a severe
+ syntax error, an I/O error, or an out of memory condition
+
+ mode names are case insensitatave. You can use | ^ & and even !
+ but no () yet, and that stuff hasn't been tested much yet, nor
+ has it been optimised.
+*/
+
+bool
+compat_mode(const char *function, const char *mode) {
+ if (!parsed && !bootstrapping) {
+ pthread_once(&threadsafe, check_env_var);
+ parsed = true;
+ }
+
+ bool want2003 = !strcasecmp("unix2003", mode);
+
+ if (want2003) {
+ return unix2003_mode;
+ }
+
+ bool want_legacy = !strcasecmp("legacy", mode);
+
+ if (want_legacy) {
+ return !unix2003_mode;
+ }
+
+ bool want_bootstrap = !strcasecmp("bootstrap", mode);
+
+ if (want_bootstrap) {
+ return bootstrapping;
+ }
+
+ bool want_error = !strcasecmp("error", mode);
+
+ if (want_error) {
+ return parse_error;
+ }
+
+ char *op = NULL;
+
+ if (op = strpbrk(mode, "!^&|")) {
+ if (*op == '!') {
+ if (op != mode) goto syn_error;
+ return !compat_mode(function, mode +1);
+ }
+
+ /* XXX char tmp[] would be better for left_arg, but
+ we are not sure what the max size should be... is
+ alloca(3) frowned on? */
+ int left_sz = 1 + (op - mode);
+ char *left_arg = malloc(left_sz);
+ strlcpy(left_arg, mode, left_sz);
+ bool left = compat_mode(function, left_arg);
+ free(left_arg);
+ bool right = compat_mode(function, op +1);
+
+ /* XXX check leftOPright syntax errors */
+
+ switch(*op) {
+ case '^':
+ return left ^ right;
+ case '&':
+ return left && right;
+ case '|':
+ return left || right;
+ default:
+ goto syn_error;
+ }
+ }
+
+syn_error:
+ fprintf(stderr, "invalid mode %s (while checking for %s)\n",
+ mode, function);
+
+ return false;
+}
+
+#ifdef SELF_TEST_COMPAT_MODE
+
+#include <assert.h>
+
+#define NEXPECTED 3
+
+typedef struct {
+ char *mode;
+ /* [0] is unix2003 mode, [1] is legacy, [2] is Invalid_Mode */
+ bool expected[NEXPECTED];
+} testcase;
+
+testcase cases[] = {
+ { "unix2003", {true, false, true}},
+ { "legacy", {false, true, false}},
+ { "bootstrap", {false, false, false}},
+ { "unix2003|legacy", {true, true, true}},
+ { "unix2003&legacy", {false, false, false}},
+ { "unix2003|legacy|bootstrap", {true, true, true}},
+ { "unix2003&legacy&bootstrap", {false, false, false}},
+ { "!unix2003", {false, true, false}},
+ { "!legacy", {true, false, true}},
+ /* XXX ! with compound statments */
+ { "unix2003^bootstrap", {true, false, true}},
+ { "unix2003^legacy", {true, true, true}},
+ { "&unix2003", {false, false, false}},
+ { "unix2003&", {false, false, false}},
+ { "unix2003!legacy", {false, false, false}},
+ { "unix2003&error", {false, false, true}},
+ { "error", {false, false, true}},
+ { "error|unix2003", {true, false, true}},
+ { "error|legacy", {false, true, true}},
+ { "error&legacy", {false, false, false}},
+};
+
+int ncases = sizeof(cases)/sizeof(testcase);
+
+int
+main(int argc, char *argv[]) {
+ int i, j;
+ int failures = 0;
+ char *settings[] = { "unix2003", "legacy", "Invalid Mode"};
+
+ assert(sizeof(settings) / sizeof(char *) == NEXPECTED);
+
+ for(i = 0; i < NEXPECTED; ++i) {
+ setenv("COMMAND_MODE", settings[i], 1);
+ char *compat_env = getenv("COMMAND_MODE");
+ printf("$COMMAND_MODE = %s\n", compat_env);
+ if (i != 0) {
+ /* here we force COMMAND_MODE to be checked again, which
+ is normally impossiable because check_env_var() is a static
+ function, but really nothing except the test cases wants to
+ try it anyway... */
+ check_env_var();
+ }
+ for(j = 0; j < ncases; ++j) {
+ bool ret = compat_mode("bin/compat_mode", cases[j].mode);
+ bool expect = cases[j].expected[i];
+
+ if (expect != ret) {
+ failures++;
+ }
+
+ printf("Case %s got %d expected %d%s\n",
+ cases[j].mode, ret, expect, (ret == expect) ? "" : " FAILED");
+ }
+ }
+
+ /* We have ncases entries in cases[], but each is run multiple
+ times (once per entry in the settings array) thus the multiply */
+ printf("Passed %d of %d cases\n",
+ NEXPECTED*ncases - failures, NEXPECTED*ncases);
+
+ return failures ? 1 : 0;
+}
+
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include <stdbool.h>
+
+extern bool compat_mode(const char *function, const char *mode);
+
+/* this will eventually cache the result, you need to call it with a
+ static string otherwise it will cache the wrong result. It ought
+ to be fast enough to use in things like malloc(2) without extra
+ tricks */
+#define COMPAT_MODE(func, mode) compat_mode(func, mode)
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
-.In sys/types.h
.In grp.h
.Ft struct group *
.Fn getgrent void
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
+++ /dev/null
-.\"
-.\" Copyright (c) 2001 Dima Dorfman.
-.\" 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.
-.\"
-.\" $FreeBSD: src/lib/libc/gen/getpeereid.3,v 1.2 2001/08/21 19:32:47 dd Exp $
-.\"
-.Dd July 15, 2001
-.Dt GETPEEREID 3
-.Os
-.Sh NAME
-.Nm getpeereid
-.Nd get the effective credentials of a UNIX-domain peer
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In sys/types.h
-.In unistd.h
-.Ft int
-.Fn getpeereid "int s" "uid_t *euid" "gid_t *egid"
-.Sh DESCRIPTION
-The
-.Fn getpeereid
-function returns the effective user and group IDs of the
-peer connected to a
-.Ux Ns -domain
-socket.
-The argument
-.Fa s
-must be a
-.Ux Ns -domain
-socket
-.Pq Xr unix 4
-of type
-.Dv SOCK_STREAM
-on which either
-.Xr connect 2
-or
-.Xr listen 2
-have been called.
-The effective used ID is placed in
-.Fa euid ,
-and the effective group ID in
-.Fa egid .
-.Pp
-The credentials returned to the
-.Xr listen 2
-caller are those of its peer at the time it called
-.Xr connect 2 ;
-the credentials returned to the
-.Xr connect 2
-caller are those of its peer at the time it called
-.Xr listen 2 .
-This mechanism is reliable; there is no way for either side to influence
-the credentials returned to its peer except by calling the appropriate
-system call (i.e., either
-.Xr connect 2
-or
-.Xr listen 2 )
-under different effective credentials.
-.Pp
-One common use of this routine is for a
-.Ux Ns -domain
-server
-to verify the credentials of its client.
-Likewise, the client can verify the credentials of the server.
-.Sh IMPLEMENTATION NOTES
-On
-.Fx ,
-.Fn getpeereid
-is implemented in terms of the
-.Dv LOCAL_PEERCRED
-.Xr unix 4
-socket option.
-.Sh RETURN VALUES
-.Rv -std getpeereid
-.Sh ERRORS
-.Fn getpeereid
-fails if:
-.Bl -tag -width Er
-.It Bq Er EBADF
-The argument
-.Fa s
-is not a valid descriptor.
-.It Bq Er ENOTSOCK
-The argument
-.Fa s
-is a file, not a socket.
-.It Bq Er ENOTCONN
-The argument
-.Fa s
-does not refer to a socket on which
-.Xr connect 2
-or
-.Xr listen 2
-have been called.
-.It Bq Er EINVAL
-The argument
-.Fa s
-does not refer to a socket of type
-.Dv SOCK_STREAM .
-.El
-.Sh SEE ALSO
-.Xr connect 2 ,
-.Xr getpeername 2 ,
-.Xr getsockname 2 ,
-.Xr getsockopt 2 ,
-.Xr listen 2 ,
-.Xr unix 4
-.Sh HISTORY
-The
-.Fn getpeereid
-function appeared in
-.Fx 5.0 .
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* SUCH DAMAGE.
*/
+#include "xlocale_private.h"
#include <ttyent.h>
#include <stdio.h>
return (t);
}
+static char *skip(), *value();
+
struct ttyent *
getttyent()
{
register char *p;
#define MAXLINELENGTH 1024
static char *line = NULL;
- static char *skip(), *value();
+ locale_t loc = __current_locale();
if ( line == NULL ) {
line = malloc(MAXLINELENGTH);
;
continue;
}
- while (isspace(*p))
+ while (isspace_l(*p, loc))
++p;
if (*p && *p != '#')
break;
tty.ty_onerror = NULL;
tty.ty_onoption = NULL;
-#define scmp(e) !strncmp(p, e, sizeof(e) - 1) && isspace(p[sizeof(e) - 1])
+#define scmp(e) !strncmp(p, e, sizeof(e) - 1) && isspace_l(p[sizeof(e) - 1], loc)
#define vcmp(e) !strncmp(p, e, sizeof(e) - 1) && p[sizeof(e) - 1] == '='
for (; *p; p = skip(p)) {
if (scmp(_TTYS_OFF))
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* SUCH DAMAGE.
*/
+#include "xlocale_private.h"
#include <sys/param.h>
#include <sys/file.h>
register char **sp, *cp;
register FILE *fp;
struct stat statb;
+ locale_t loc = __current_locale();
if (shells != NULL)
free(shells);
if (*cp == '#' || *cp == '\0')
continue;
*sp++ = cp;
- while (!isspace(*cp) && *cp != '#' && *cp != '\0')
+ while (!isspace_l(*cp, loc) && *cp != '#' && *cp != '\0')
cp++;
*cp++ = '\0';
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#import <objc/zone.h>
#import <malloc/malloc.h>
#import <fcntl.h>
-#include <crt_externs.h>
+#import <crt_externs.h>
+#import <errno.h>
#import <pthread_internals.h>
#import "scalable_malloc.h"
static int malloc_free_abort = 0; // default is not to abort
-static FILE *malloc_debug_file;
+static int malloc_debug_file;
#define MALLOC_LOCK() LOCK(_malloc_lock)
#define MALLOC_UNLOCK() UNLOCK(_malloc_lock)
/********* Utilities ************/
+static inline malloc_zone_t * find_registered_zone(const void *, size_t *) __attribute__((always_inline));
static inline malloc_zone_t *
find_registered_zone(const void *ptr, size_t *returned_size) {
// locates the proper zone
// malloc_printf("malloc_zones is at %p; malloc_num_zones is at %p\n", (unsigned)&malloc_zones, (unsigned)&malloc_num_zones);
}
+static inline malloc_zone_t *inline_malloc_default_zone(void) __attribute__((always_inline));
static inline malloc_zone_t *
inline_malloc_default_zone(void) {
if (!malloc_num_zones) _malloc_initialize();
if (flag) {
fd = open(flag, O_WRONLY|O_APPEND|O_CREAT, 0644);
if (fd >= 0) {
- malloc_debug_file = fdopen(fd, "a+");
+ malloc_debug_file = fd;
fcntl(fd, F_SETFD, 0); // clear close-on-exec flag XXX why?
} else {
malloc_printf("Could not open %s, using stderr\n", flag);
char **p;
char *c;
/* Given that all environment variables start with "Malloc" we optimize by scanning quickly first the environment, therefore avoiding repeated calls to getenv() */
- malloc_debug_file = stderr;
+ malloc_debug_file = STDERR_FILENO;
for (p = env; (c = *p) != NULL; ++p) {
if (!strncmp(c, "Malloc", 6)) {
set_flags_from_environment();
}
/*
- * XXX malloc_printf cannot handle the %ls, %a and %A formats. It must also not
- * be used for the printing of vectors, or with formats with positional arguments.
+ * XXX malloc_printf now uses _simple_{,v}dprintf. It only deals with a
+ * subset of printf format specifiers, but it doesn't call malloc.
*/
+void _simple_dprintf(int, const char *, ...);
+void _simple_vdprintf(int, const char *, va_list);
+
void
malloc_printf(const char *format, ...)
{
if (__is_threaded) {
/* XXX somewhat rude 'knowing' that pthread_t is a pointer */
- fprintf(malloc_debug_file, "%s(%d,%p) malloc: ", getprogname(), getpid(), (void *)pthread_self());
+ _simple_dprintf(malloc_debug_file, "%s(%d,%p) malloc: ", getprogname(), getpid(), (void *)pthread_self());
} else {
- fprintf(malloc_debug_file, "%s(%d) malloc: ", getprogname(), getpid());
+ _simple_dprintf(malloc_debug_file, "%s(%d) malloc: ", getprogname(), getpid());
}
va_start(ap, format);
- vfprintf(malloc_debug_file, format, ap);
+ _simple_vdprintf(malloc_debug_file, format, ap);
va_end(ap);
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#include <mach/mach_time.h>
#include <stdio.h>
+
+#ifdef BUILDING_VARIANT
+#include "pthread_internals.h"
+
+extern int __unix_conforming;
+extern mach_port_t clock_port;
+extern semaphore_t clock_sem;
+
+int
+nanosleep(const struct timespec *requested_time, struct timespec *remaining_time) {
+ kern_return_t kret;
+ int ret;
+ mach_timespec_t remain;
+ mach_timespec_t current;
+
+ if (__unix_conforming == 0)
+ __unix_conforming = 1;
+
+ if ((requested_time == NULL) || (requested_time->tv_sec < 0) || (requested_time->tv_nsec >= NSEC_PER_SEC)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (remaining_time != NULL) {
+ kret = clock_get_time(clock_port, ¤t);
+ if (kret != KERN_SUCCESS) {
+ fprintf(stderr, "clock_get_time() failed: %s\n", mach_error_string(ret));
+ return -1;
+ }
+ }
+ ret = __semwait_signal(clock_sem, MACH_PORT_NULL, 1, 1, requested_time->tv_sec, requested_time->tv_nsec);
+ if (ret < 0) {
+ if (errno == ETIMEDOUT) {
+ return 0;
+ } else if (errno == EINTR) {
+ if (remaining_time != NULL) {
+ ret = clock_get_time(clock_port, &remain);
+ if (ret != KERN_SUCCESS) {
+ fprintf(stderr, "clock_get_time() failed: %s\n", mach_error_string(ret));
+ return -1;
+ }
+ /* This depends on the layout of a mach_timespec_t and timespec_t being equivalent */
+ ADD_MACH_TIMESPEC(¤t, requested_time);
+ SUB_MACH_TIMESPEC(¤t, &remain);
+ remaining_time->tv_sec = current.tv_sec;
+ remaining_time->tv_nsec = current.tv_nsec;
+ }
+ } else {
+ errno = EINVAL;
+ }
+ }
+ return -1;
+}
+
+
+#else /* BUILDING_VARIANT */
+
int
nanosleep(const struct timespec *requested_time, struct timespec *remaining_time) {
kern_return_t ret;
}
return 0;
}
+
+
+#endif /* BUILDING_VARIANT */
static const char rcsid[] = "$OpenBSD: nftw.c,v 1.2 2003/07/21 21:15:32 millert Exp $";
#endif /* LIBC_SCCS and not lint */
+#include <stdio.h>
+#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fts.h>
#include <ftw.h>
#include <limits.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
-int
-nftw(const char *path, int (*fn)(const char *, const struct stat *, int,
- struct FTW *), int nfds, int ftwflags)
+static int
+both_ftw(const char *path,
+ int (*ofn)(const char *, const struct stat *, int),
+ int (*nfn)(const char *, const struct stat *, int, struct FTW *),
+ int nfds, int ftwflags)
{
const char *paths[2];
struct FTW ftw;
FTSENT *cur;
FTS *ftsp;
int ftsflags, fnflag, error, postorder, sverrno;
+ int cwd_fd = -1; /* cwd_fd != -1 means call chdir a lot */
+
+#if __DARWIN_UNIX03
+ /* Macro to skip the mount point itself in UNiX03 mode, in legcy
+ mode the mount point is returned, but we don't decend into it */
+#define SKIP_MOUNT if ((ftwflags & FTW_MOUNT) \
+ && cur->fts_statp->st_dev != path_stat.st_dev) { \
+ continue; \
+ }
+#else
+#define SKIP_MOUNT
+#endif
/* XXX - nfds is currently unused */
if (nfds < 1 || nfds > OPEN_MAX) {
ftsflags |= FTS_NOCHDIR;
if (ftwflags & FTW_MOUNT)
ftsflags |= FTS_XDEV;
- if (ftwflags & FTW_PHYS)
+ if (ftwflags & FTW_PHYS) {
ftsflags |= FTS_PHYSICAL;
+ } else {
+ ftsflags |= FTS_LOGICAL;
+ }
postorder = (ftwflags & FTW_DEPTH) != 0;
+
+ /* We have been requested to change directories, and fts doesn't
+ always do it (never for FTS_LOGICAL, and sometimes not for
+ FTS_PHYSICAL) */
+ if (ftwflags & FTW_CHDIR) {
+ cwd_fd = open(".", O_RDONLY, 0);
+ if (cwd_fd < 0) {
+ return -1;
+ }
+ /* Prevent problems if fts ever starts using chdir when passed
+ FTS_PHYSICAL */
+ ftsflags |= FTS_NOCHDIR;
+ }
+
+#if __DARWIN_UNIX03
+ struct stat path_stat;
+
+ /* UNIX03 requires us to return -1/errno=ELOOP if path
+ is a looping symlink; fts_open is succesful and fts_read
+ gives us FTS_NS which isn't very useful, in fact we get
+ pretty much the same behaviour for ENAMETOOLONG, ENOENT,
+ ENOTDIR, and EACCES */
+ {
+ int rc = stat(path, &path_stat);
+ int e = errno;
+ if (rc < 0
+ && (errno == ELOOP || errno == ENAMETOOLONG || errno == ENOENT
+ || errno == ENOTDIR || errno == EACCES)) {
+ return -1;
+ }
+ if (rc >= 0 && nfn) {
+ if (!S_ISDIR(path_stat.st_mode)) {
+ errno = ENOTDIR;
+ return -1;
+ }
+ }
+ }
+#endif
paths[0] = path;
paths[1] = NULL;
ftsp = fts_open((char * const *)paths, ftsflags, NULL);
- if (ftsp == NULL)
- return (-1);
+ if (ftsp == NULL) {
+ return (-1);
+ }
error = 0;
while ((cur = fts_read(ftsp)) != NULL) {
switch (cur->fts_info) {
case FTS_D:
if (postorder)
continue;
+ SKIP_MOUNT;
+ /* we will get FTS_DNR next (this is not an issue for
+ FTS_DP, only FTS_D) */
+ if (access(cur->fts_path, R_OK) != 0)
+ continue;
fnflag = FTW_D;
break;
case FTS_DNR:
case FTS_DP:
if (!postorder)
continue;
+ SKIP_MOUNT;
fnflag = FTW_DP;
break;
case FTS_F:
fnflag = FTW_SL;
break;
case FTS_SLNONE:
- fnflag = FTW_SLN;
+ fnflag = nfn ? FTW_SLN : FTW_SL;
+#if __DARWIN_UNIX03
+ {
+ /* The legacy behaviour did not signal an error
+ on symlink loops unless they ended up causing
+ a directory cycle, but the Unix2003 standard
+ requires ELOOP to end ftw and nftw walks with
+ an error */
+ struct stat sb;
+ int rc = stat(cur->fts_path, &sb);
+ if (rc < 0 && errno == ELOOP) {
+ error = -1;
+ goto done;
+ }
+ }
+#endif
break;
case FTS_DC:
+#if __DARWIN_UNIX03
+ /* Unix03 says nftw should break cycles and not return
+ errors in physical mode (which is definitly what it
+ says ftw can't do) */
+ if (nfn && !(ftwflags & FTW_PHYS)) {
+ fnflag = FTW_D;
+ break;
+ }
+#endif
errno = ELOOP;
/* FALLTHROUGH */
default:
error = -1;
goto done;
}
- ftw.base = cur->fts_pathlen - cur->fts_namelen;
- ftw.level = cur->fts_level;
- error = fn(cur->fts_path, cur->fts_statp, fnflag, &ftw);
+
+ if (cwd_fd >= 0) {
+ char *dir, *free_me = NULL;
+ if (fnflag == FTW_D) {
+ dir = cur->fts_path;
+ } else {
+ /* we could alloc just enough for the directory,
+ and use memmove -- but that is a little more
+ error prone, and not noticable in with all the
+ extra work... */
+ dir = free_me = strdup(cur->fts_path);
+ dir[cur->fts_pathlen - cur->fts_namelen] = '\0';
+ }
+ int rc = chdir(dir);
+ if (free_me) {
+ free(free_me);
+ }
+ if (rc < 0) {
+ error = -1;
+ goto done;
+ }
+ }
+ if (nfn) {
+ ftw.base = cur->fts_pathlen - cur->fts_namelen;
+ ftw.level = cur->fts_level;
+ error = nfn(cur->fts_path, cur->fts_statp, fnflag, &ftw);
+ } else {
+ error = ofn(cur->fts_path, cur->fts_statp, fnflag);
+ }
+ if (cwd_fd >= 0) {
+ if (fchdir(cwd_fd) < 0) {
+ error = -1;
+ goto done;
+ }
+ }
+
if (error != 0)
break;
}
errno = sverrno;
return (error);
}
+
+int
+ftw(const char *path, int (*fn)(const char *, const struct stat *, int),
+ int nfds)
+{
+ /* The legacy implmentation didn't follow symlinks, but Unix03
+ does - this was likely a bug in the legacy implemtation; JKH
+ thinks we ought change the legacy behaviour, and I agree; anyone
+ who doesn't should replace FTW_PHYS with
+ __DARWIN_UNIX03 ? 0 : FTW_PHYS */
+ return both_ftw(path, fn, NULL, nfds, FTW_PHYS);
+}
+
+int
+nftw(const char *path, int (*fn)(const char *, const struct stat *, int,
+ struct FTW *), int nfds, int ftwflags)
+{
+ return both_ftw(path, NULL, fn, nfds, ftwflags);
+}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* SUCH DAMAGE.
*/
+/* temporarily comment this file out for LP64, until code can be modified */
+#ifndef __LP64__
#include <stdlib.h>
#include <sys/types.h>
}
return (nreq);
}
+
+#endif /* !__LP64__ */
--- /dev/null
+/*
+ * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+/*
+ * Copyright (c) 1993
+ * The Regents of the University of California. 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <sys/types.h>
+#include <sys/socket.h>
+#include <sys/syslog.h>
+#include <sys/uio.h>
+#include <sys/un.h>
+#include <netdb.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <paths.h>
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#ifdef __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
+#include <crt_externs.h>
+
+#ifdef BUILDING_VARIANT
+__private_extern__ int _sl_LogFile; /* fd for log */
+__private_extern__ int _sl_connected; /* have done connect */
+__private_extern__ int _sl_LogStat; /* status bits, set by openlog() */
+__private_extern__ const char *_sl_LogTag; /* string to tag the entry with */
+__private_extern__ int _sl_LogFacility; /* default facility code */
+__private_extern__ int _sl_LogMask; /* mask of priorities to be logged */
+#else /* !BUILDING_VARIANT */
+__private_extern__ int _sl_LogFile = -1; /* fd for log */
+__private_extern__ int _sl_connected = 0; /* have done connect */
+__private_extern__ int _sl_LogStat = 0; /* status bits, set by openlog() */
+__private_extern__ const char *_sl_LogTag = NULL; /* string to tag the entry with */
+__private_extern__ int _sl_LogFacility = LOG_USER; /* default facility code */
+__private_extern__ int _sl_LogMask = 0xff; /* mask of priorities to be logged */
+#endif /* BUILDING_VARIANT */
+
+/*
+ * syslog, vsyslog --
+ * print message on log file; output is intended for syslogd(8).
+ */
+void
+#ifdef __STDC__
+syslog(int pri, const char *fmt, ...)
+#else
+syslog(pri, fmt, va_alist)
+ int pri;
+ char *fmt;
+ va_dcl
+#endif
+{
+ va_list ap;
+
+#ifdef __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ vsyslog(pri, fmt, ap);
+ va_end(ap);
+}
+
+void
+vsyslog(pri, fmt, ap)
+ int pri;
+ register const char *fmt;
+ va_list ap;
+{
+ register int cnt;
+ register char ch, *p, *t;
+ time_t now;
+ int fd, saved_errno;
+#define TBUF_LEN 2048
+#define FMT_LEN 1024
+ char *stdp, tbuf[TBUF_LEN], fmt_cpy[FMT_LEN];
+ int tbuf_left, fmt_left, prlen;
+
+#define INTERNALLOG LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID
+ /* Check for invalid bits. */
+ if (pri & ~(LOG_PRIMASK|LOG_FACMASK)) {
+ syslog(INTERNALLOG,
+ "syslog: unknown facility/priority: %x", pri);
+ pri &= LOG_PRIMASK|LOG_FACMASK;
+ }
+
+ /* Check priority against setlogmask values. */
+ if (!(LOG_MASK(LOG_PRI(pri)) & _sl_LogMask))
+ return;
+
+ saved_errno = errno;
+
+ /* Set default facility if none specified. */
+ if ((pri & LOG_FACMASK) == 0)
+ pri |= _sl_LogFacility;
+
+ /* Build the message. */
+
+ /*
+ * Although it's tempting, we can't ignore the possibility of
+ * overflowing the buffer when assembling the "fixed" portion
+ * of the message. Strftime's "%h" directive expands to the
+ * locale's abbreviated month name, but if the user has the
+ * ability to construct to his own locale files, it may be
+ * arbitrarily long.
+ */
+ (void)time(&now);
+
+ p = tbuf;
+ tbuf_left = TBUF_LEN;
+
+#define DEC() \
+ do { \
+ if (prlen >= tbuf_left) \
+ prlen = tbuf_left - 1; \
+ p += prlen; \
+ tbuf_left -= prlen; \
+ } while (0)
+
+ prlen = snprintf(p, tbuf_left, "<%d>", pri);
+ DEC();
+
+ prlen = strftime(p, tbuf_left, "%h %e %T ", localtime(&now));
+ DEC();
+
+ if (_sl_LogStat & LOG_PERROR)
+ stdp = p;
+ if (_sl_LogTag == NULL)
+ _sl_LogTag = *(*_NSGetArgv());
+ if (_sl_LogTag != NULL) {
+ prlen = snprintf(p, tbuf_left, "%s", _sl_LogTag);
+ DEC();
+ }
+ if (_sl_LogStat & LOG_PID) {
+ prlen = snprintf(p, tbuf_left, "[%d]", getpid());
+ DEC();
+ }
+ if (_sl_LogTag != NULL) {
+ if (tbuf_left > 1) {
+ *p++ = ':';
+ tbuf_left--;
+ }
+ if (tbuf_left > 1) {
+ *p++ = ' ';
+ tbuf_left--;
+ }
+ }
+
+ /*
+ * We wouldn't need this mess if printf handled %m, or if
+ * strerror() had been invented before syslog().
+ */
+ for (t = fmt_cpy, fmt_left = FMT_LEN; (ch = *fmt); ++fmt) {
+ if (ch == '%' && fmt[1] == 'm') {
+ ++fmt;
+ prlen = snprintf(t, fmt_left, "%s",
+ strerror(saved_errno));
+ if (prlen >= fmt_left)
+ prlen = fmt_left - 1;
+ t += prlen;
+ fmt_left -= prlen;
+ } else {
+ if (fmt_left > 1) {
+ *t++ = ch;
+ fmt_left--;
+ }
+ }
+ }
+ *t = '\0';
+
+ prlen = vsnprintf(p, tbuf_left, fmt_cpy, ap);
+ DEC();
+ cnt = p - tbuf;
+
+ /* Output to stderr if requested. */
+ if (_sl_LogStat & LOG_PERROR) {
+ struct iovec iov[2];
+
+ iov[0].iov_base = stdp;
+ iov[0].iov_len = cnt - (stdp - tbuf);
+ iov[1].iov_base = "\n";
+ iov[1].iov_len = 1;
+ (void)writev(STDERR_FILENO, iov, 2);
+ }
+
+ /* Get connected, output the message to the local logger. */
+ if (!_sl_connected)
+ openlog(_sl_LogTag, _sl_LogStat | LOG_NDELAY, 0);
+ if (send(_sl_LogFile, tbuf, cnt, 0) >= 0)
+ return;
+
+ /*
+ * Output the message to the console; don't worry about blocking,
+ * if console blocks everything will. Make sure the error reported
+ * is the one from the syslogd failure.
+ */
+ if (_sl_LogStat & LOG_CONS &&
+ (fd = open(_PATH_CONSOLE, O_WRONLY, 0)) >= 0) {
+ struct iovec iov[2];
+
+ p = strchr(tbuf, '>') + 1;
+ iov[0].iov_base = p;
+ iov[0].iov_len = cnt - (p - tbuf);
+ iov[1].iov_base = "\r\n";
+ iov[1].iov_len = 2;
+ (void)writev(fd, iov, 2);
+ (void)close(fd);
+ }
+}
+
+#ifndef BUILDING_VARIANT
+
+static struct sockaddr_un SyslogAddr; /* AF_UNIX address of local logger */
+
+void
+openlog(ident, logstat, logfac)
+ const char *ident;
+ int logstat, logfac;
+{
+ if (ident != NULL)
+ _sl_LogTag = ident;
+ _sl_LogStat = logstat;
+ if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0)
+ _sl_LogFacility = logfac;
+
+ if (_sl_LogFile == -1) {
+ SyslogAddr.sun_family = AF_UNIX;
+ (void)strncpy(SyslogAddr.sun_path, _PATH_LOG,
+ sizeof(SyslogAddr.sun_path));
+ if (_sl_LogStat & LOG_NDELAY) {
+ if ((_sl_LogFile = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1)
+ return;
+ (void)fcntl(_sl_LogFile, F_SETFD, 1);
+ }
+ }
+ if (_sl_LogFile != -1 && !_sl_connected)
+ if (connect(_sl_LogFile, (struct sockaddr *)&SyslogAddr, sizeof(SyslogAddr)) == -1) {
+ (void)close(_sl_LogFile);
+ _sl_LogFile = -1;
+ } else
+ _sl_connected = 1;
+}
+
+void
+closelog()
+{
+ (void)close(_sl_LogFile);
+ _sl_LogFile = -1;
+ _sl_connected = 0;
+}
+
+/* setlogmask -- set the log mask level */
+int
+setlogmask(pmask)
+ int pmask;
+{
+ int omask;
+
+ omask = _sl_LogMask;
+ if (pmask != 0)
+ _sl_LogMask = pmask;
+ return (omask);
+}
+
+#endif /* !BUILDING_VARIANT */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#if DEBUG_MALLOC
#warning DEBUG_MALLOC ENABLED
# define INLINE
+# define ALWAYSINLINE
# define CHECK_LOCKED(szone, fun) \
do { \
if (__is_threaded && TRY_LOCK(szone->lock)) { \
} while (0)
#else
# define INLINE __inline__
+# define ALWAYSINLINE __attribute__((always_inline))
# define CHECK_LOCKED(szone, fun) {}
#endif
static void deallocate_pages(szone_t *szone, void *addr, size_t size, unsigned debug_flags);
static kern_return_t _szone_default_reader(task_t task, vm_address_t address, vm_size_t size, void **ptr);
-static INLINE void free_list_checksum(szone_t *szone, free_list_t *ptr, const char *msg);
-static INLINE void free_list_set_checksum(szone_t *szone, free_list_t *ptr);
+static INLINE void free_list_checksum(szone_t *szone, free_list_t *ptr, const char *msg) ALWAYSINLINE;
+static INLINE void free_list_set_checksum(szone_t *szone, free_list_t *ptr) ALWAYSINLINE;
static unsigned free_list_count(const free_list_t *ptr);
-static INLINE msize_t get_tiny_meta_header(const void *ptr, boolean_t *is_free);
-static INLINE void set_tiny_meta_header_in_use(const void *ptr, msize_t msize);
-static INLINE void set_tiny_meta_header_middle(const void *ptr);
-static INLINE void set_tiny_meta_header_free(const void *ptr, msize_t msize);
-static INLINE boolean_t tiny_meta_header_is_free(const void *ptr);
-static INLINE void *tiny_previous_preceding_free(void *ptr, msize_t *prev_msize);
-static INLINE void tiny_free_list_add_ptr(szone_t *szone, void *ptr, msize_t msize);
-static INLINE void tiny_free_list_remove_ptr(szone_t *szone, void *ptr, msize_t msize);
-static INLINE tiny_region_t *tiny_region_for_ptr_no_lock(szone_t *szone, const void *ptr);
-static INLINE void tiny_free_no_lock(szone_t *szone, tiny_region_t *region, void *ptr, msize_t msize);
+static INLINE msize_t get_tiny_meta_header(const void *ptr, boolean_t *is_free) ALWAYSINLINE;
+static INLINE void set_tiny_meta_header_in_use(const void *ptr, msize_t msize) ALWAYSINLINE;
+static INLINE void set_tiny_meta_header_middle(const void *ptr) ALWAYSINLINE;
+static INLINE void set_tiny_meta_header_free(const void *ptr, msize_t msize) ALWAYSINLINE;
+static INLINE boolean_t tiny_meta_header_is_free(const void *ptr) ALWAYSINLINE;
+static INLINE void *tiny_previous_preceding_free(void *ptr, msize_t *prev_msize) ALWAYSINLINE;
+static INLINE void tiny_free_list_add_ptr(szone_t *szone, void *ptr, msize_t msize) ALWAYSINLINE;
+static INLINE void tiny_free_list_remove_ptr(szone_t *szone, void *ptr, msize_t msize) ALWAYSINLINE;
+static INLINE tiny_region_t *tiny_region_for_ptr_no_lock(szone_t *szone, const void *ptr) ALWAYSINLINE;
+static INLINE void tiny_free_no_lock(szone_t *szone, tiny_region_t *region, void *ptr, msize_t msize) ALWAYSINLINE;
static void *tiny_malloc_from_region_no_lock(szone_t *szone, msize_t msize);
-static INLINE boolean_t try_realloc_tiny_in_place(szone_t *szone, void *ptr, size_t old_size, size_t new_size);
+static INLINE boolean_t try_realloc_tiny_in_place(szone_t *szone, void *ptr, size_t old_size, size_t new_size) ALWAYSINLINE;
static boolean_t tiny_check_region(szone_t *szone, tiny_region_t *region);
static kern_return_t tiny_in_use_enumerator(task_t task, void *context, unsigned type_mask, vm_address_t region_address, unsigned short num_regions, size_t tiny_bytes_free_at_end, memory_reader_t reader, vm_range_recorder_t recorder);
-static INLINE void *tiny_malloc_from_free_list(szone_t *szone, msize_t msize);
-static INLINE void *tiny_malloc_should_clear(szone_t *szone, msize_t msize, boolean_t cleared_requested);
-static INLINE void free_tiny(szone_t *szone, void *ptr, tiny_region_t *tiny_region);
+static INLINE void *tiny_malloc_from_free_list(szone_t *szone, msize_t msize) ALWAYSINLINE;
+static INLINE void *tiny_malloc_should_clear(szone_t *szone, msize_t msize, boolean_t cleared_requested) ALWAYSINLINE;
+static INLINE void free_tiny(szone_t *szone, void *ptr, tiny_region_t *tiny_region) ALWAYSINLINE;
static void print_tiny_free_list(szone_t *szone);
static void print_tiny_region(boolean_t verbose, tiny_region_t region, size_t bytes_at_end);
static boolean_t tiny_free_list_check(szone_t *szone, grain_t slot);
-static INLINE void small_meta_header_set_is_free(msize_t *meta_headers, unsigned index, msize_t msize);
-static INLINE void small_meta_header_set_in_use(msize_t *meta_headers, msize_t index, msize_t msize);
-static INLINE void small_meta_header_set_middle(msize_t *meta_headers, msize_t index);
+static INLINE void small_meta_header_set_is_free(msize_t *meta_headers, unsigned index, msize_t msize) ALWAYSINLINE;
+static INLINE void small_meta_header_set_in_use(msize_t *meta_headers, msize_t index, msize_t msize) ALWAYSINLINE;
+static INLINE void small_meta_header_set_middle(msize_t *meta_headers, msize_t index) ALWAYSINLINE;
static void small_free_list_add_ptr(szone_t *szone, void *ptr, msize_t msize);
static void small_free_list_remove_ptr(szone_t *szone, void *ptr, msize_t msize);
-static INLINE small_region_t *small_region_for_ptr_no_lock(szone_t *szone, const void *ptr);
-static INLINE void small_free_no_lock(szone_t *szone, small_region_t *region, void *ptr, msize_t msize);
+static INLINE small_region_t *small_region_for_ptr_no_lock(szone_t *szone, const void *ptr) ALWAYSINLINE;
+static INLINE void small_free_no_lock(szone_t *szone, small_region_t *region, void *ptr, msize_t msize) ALWAYSINLINE;
static void *small_malloc_from_region_no_lock(szone_t *szone, msize_t msize);
-static INLINE boolean_t try_realloc_small_in_place(szone_t *szone, void *ptr, size_t old_size, size_t new_size);
+static INLINE boolean_t try_realloc_small_in_place(szone_t *szone, void *ptr, size_t old_size, size_t new_size) ALWAYSINLINE;
static boolean_t szone_check_small_region(szone_t *szone, small_region_t *region);
static kern_return_t small_in_use_enumerator(task_t task, void *context, unsigned type_mask, vm_address_t region_address, unsigned short num_regions, size_t small_bytes_free_at_end, memory_reader_t reader, vm_range_recorder_t recorder);
-static INLINE void *small_malloc_from_free_list(szone_t *szone, msize_t msize);
-static INLINE void *small_malloc_should_clear(szone_t *szone, msize_t msize, boolean_t cleared_requested);
-static INLINE void *small_malloc_cleared_no_lock(szone_t *szone, msize_t msize);
-static INLINE void free_small(szone_t *szone, void *ptr, small_region_t *small_region);
+static INLINE void *small_malloc_from_free_list(szone_t *szone, msize_t msize) ALWAYSINLINE;
+static INLINE void *small_malloc_should_clear(szone_t *szone, msize_t msize, boolean_t cleared_requested) ALWAYSINLINE;
+static INLINE void *small_malloc_cleared_no_lock(szone_t *szone, msize_t msize) ALWAYSINLINE;
+static INLINE void free_small(szone_t *szone, void *ptr, small_region_t *small_region) ALWAYSINLINE;
static void print_small_free_list(szone_t *szone);
static void print_small_region(szone_t *szone, boolean_t verbose, small_region_t *region, size_t bytes_at_end);
static boolean_t small_free_list_check(szone_t *szone, grain_t grain);
#endif
static large_entry_t *large_entry_for_pointer_no_lock(szone_t *szone, const void *ptr);
static void large_entry_insert_no_lock(szone_t *szone, large_entry_t range);
-static INLINE void large_entries_rehash_after_entry_no_lock(szone_t *szone, large_entry_t *entry);
-static INLINE large_entry_t *large_entries_alloc_no_lock(szone_t *szone, unsigned num);
+static INLINE void large_entries_rehash_after_entry_no_lock(szone_t *szone, large_entry_t *entry) ALWAYSINLINE;
+static INLINE large_entry_t *large_entries_alloc_no_lock(szone_t *szone, unsigned num) ALWAYSINLINE;
static void large_entries_free_no_lock(szone_t *szone, large_entry_t *entries, unsigned num, vm_range_t *range_to_deallocate);
static void large_entries_grow_no_lock(szone_t *szone, vm_range_t *range_to_deallocate);
static vm_range_t large_free_no_lock(szone_t *szone, large_entry_t *entry);
static boolean_t huge_entry_append(szone_t *szone, huge_entry_t huge);
static kern_return_t huge_in_use_enumerator(task_t task, void *context, unsigned type_mask, vm_address_t huge_entries_address, unsigned num_entries, memory_reader_t reader, vm_range_recorder_t recorder);
static void *large_and_huge_malloc(szone_t *szone, unsigned num_pages);
-static INLINE void free_large_or_huge(szone_t *szone, void *ptr);
-static INLINE int try_realloc_large_or_huge_in_place(szone_t *szone, void *ptr, size_t old_size, size_t new_size);
+static INLINE void free_large_or_huge(szone_t *szone, void *ptr) ALWAYSINLINE;
+static INLINE int try_realloc_large_or_huge_in_place(szone_t *szone, void *ptr, size_t old_size, size_t new_size) ALWAYSINLINE;
static void szone_free(szone_t *szone, void *ptr);
-static INLINE void *szone_malloc_should_clear(szone_t *szone, size_t size, boolean_t cleared_requested);
+static INLINE void *szone_malloc_should_clear(szone_t *szone, size_t size, boolean_t cleared_requested) ALWAYSINLINE;
static void *szone_malloc(szone_t *szone, size_t size);
static void *szone_calloc(szone_t *szone, size_t num_items, size_t size);
static void *szone_valloc(szone_t *szone, size_t size);
} else {
malloc_printf("*** error: %s\n", msg);
}
+ malloc_printf("*** set a breakpoint in szone_error to debug\n");
#if DEBUG_MALLOC
szone_print(szone, 1);
szone_sleep();
// think tiny
msize = TINY_MSIZE_FOR_BYTES(size + TINY_QUANTUM - 1);
if (! msize) msize = 1;
- return TINY_BYTES_FOR_MSIZE(msize << SHIFT_TINY_QUANTUM);
+ return TINY_BYTES_FOR_MSIZE(msize);
}
if (!((szone->debug_flags & SCALABLE_MALLOC_ADD_GUARD_PAGES) && PROTECT_SMALL) && (size < LARGE_THRESHOLD)) {
// think small
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <string.h>
+#include <stdarg.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <errno.h>
+
+/* we use a small buffer to minimize stack usage constraints */
+#define MYBUFSIZE 32
+
+typedef struct {
+ char buf[MYBUFSIZE];
+ char *ptr;
+ char *end;
+ int fd;
+} BUF;
+
+/* flush the buffer and reset the pointer */
+static inline void
+flush(BUF *b)
+{
+ char *buf = b->buf;
+ int n = b->ptr - buf;
+ int w;
+
+ while(n > 0) {
+ w = write(b->fd, buf, n);
+ if(w < 0) {
+ if(errno == EINTR || errno == EAGAIN)
+ continue;
+ break;
+ }
+ n -= w;
+ buf += n;
+ }
+ b->ptr = b->buf;
+}
+
+/* output a single character */
+static inline void
+put_c(BUF *b, int c)
+{
+ if(b->ptr >= b->end)
+ flush(b);
+ *b->ptr++ = c;
+}
+
+/* output a null-terminated string */
+static inline void
+put_s(BUF *b, const char *str)
+{
+ while(*str)
+ put_c(b, *str++);
+}
+
+/* output a string of the specified size */
+static inline void
+put_n(BUF *b, const char *str, int n)
+{
+ while(n-- > 0)
+ put_c(b, *str++);
+}
+
+/*
+ * Output the signed decimal string representing the number in "in". "width" is
+ * the minimum field width, and "zero" is a boolean value, true for zero padding
+ * (otherwise blank padding).
+ */
+static void
+dec(BUF *b, long long in, int width, int zero)
+{
+ char buf[32];
+ char *cp = buf + sizeof(buf);
+ int pad;
+ int neg = 0;
+ unsigned long long n = (unsigned long long)in;
+
+ if(in < 0) {
+ neg++;
+ width--;
+ n = ~n + 1;
+ }
+ *--cp = 0;
+ if(n) {
+ while(n) {
+ *--cp = (n % 10) + '0';
+ n /= 10;
+ }
+ } else
+ *--cp = '0';
+ if(neg && zero) {
+ put_c(b, '-');
+ neg = 0;
+ }
+ pad = width - strlen(cp);
+ zero = zero ? '0' : ' ';
+ while(pad-- > 0)
+ put_c(b, zero);
+ if(neg)
+ put_c(b, '-');
+ put_s(b, cp);
+}
+
+/*
+ * Output the hex string representing the number in "i". "width" is the
+ * minimum field width, and "zero" is a boolean value, true for zero padding
+ * (otherwise blank padding). "upper" is a boolean value, true for upper
+ * case hex characters, lower case otherwise. "p" is a boolean value, true
+ * if 0x should be prepended (for %p), otherwise nothing.
+ */
+static char _h[] = "0123456789abcdef";
+static char _H[] = "0123456789ABCDEF";
+static char _0x[] = "0x";
+
+static void
+hex(BUF *b, unsigned long long n, int width, int zero, int upper, int p)
+{
+ char buf[32];
+ char *cp = buf + sizeof(buf);
+ char *h = upper ? _H : _h;
+
+ *--cp = 0;
+ if(n) {
+ while(n) {
+ *--cp = h[n & 0xf];
+ n >>= 4;
+ }
+ } else
+ *--cp = '0';
+ if(p) {
+ width -= 2;
+ if(zero) {
+ put_s(b, _0x);
+ p = 0;
+ }
+ }
+ width -= strlen(cp);
+ zero = zero ? '0' : ' ';
+ while(width-- > 0)
+ put_c(b, zero);
+ if(p)
+ put_s(b, _0x);
+ put_s(b, cp);
+}
+
+/*
+ * Output the unsigned decimal string representing the number in "in". "width"
+ * is the minimum field width, and "zero" is a boolean value, true for zero
+ * padding (otherwise blank padding).
+ */
+static void
+udec(BUF *b, unsigned long long n, int width, int zero)
+{
+ char buf[32];
+ char *cp = buf + sizeof(buf);
+ int pad;
+
+ *--cp = 0;
+ if(n) {
+ while(n) {
+ *--cp = (n % 10) + '0';
+ n /= 10;
+ }
+ } else
+ *--cp = '0';
+ pad = width - strlen(cp);
+ zero = zero ? '0' : ' ';
+ while(pad-- > 0)
+ put_c(b, zero);
+ put_s(b, cp);
+}
+
+/*
+ * A simplified vfprintf variant. The format string is interpreted with
+ * arguments for the va_list, and the results are written to the given
+ * file descriptor.
+ */
+void
+_simple_vdprintf(int fd, const char *fmt, va_list ap)
+{
+ BUF b;
+
+ b.fd = fd;
+ b.ptr = b.buf;
+ b.end = b.buf + MYBUFSIZE;
+ while(*fmt) {
+ int lflag, zero, width;
+ char *cp;
+ if(!(cp = strchr(fmt, '%'))) {
+ put_s(&b, fmt);
+ break;
+ }
+ put_n(&b, fmt, cp - fmt);
+ fmt = cp + 1;
+ if(*fmt == '%') {
+ put_c(&b, '%');
+ fmt++;
+ continue;
+ }
+ lflag = zero = width = 0;
+ for(;;) {
+ switch(*fmt) {
+ case '0':
+ zero++;
+ fmt++;
+ /* drop through */
+ case '1': case '2': case '3': case '4': case '5':
+ case '6': case '7': case '8': case '9':
+ while(*fmt >= '0' && *fmt <= '9')
+ width = 10 * width + (*fmt++ - '0');
+ continue;
+ case 'c':
+ zero = zero ? '0' : ' ';
+ width--;
+ while(width-- > 0)
+ put_c(&b, zero);
+ put_c(&b, va_arg(ap, int));
+ break;
+ case 'd': case 'i':
+ switch(lflag) {
+ case 0:
+ dec(&b, va_arg(ap, int), width, zero);
+ break;
+ case 1:
+ dec(&b, va_arg(ap, long), width, zero);
+ break;
+ default:
+ dec(&b, va_arg(ap, long long), width, zero);
+ break;
+ }
+ break;
+ case 'l':
+ lflag++;
+ fmt++;
+ continue;
+ case 'p':
+ hex(&b, (unsigned long)va_arg(ap, void *), width, zero, 0, 1);
+ break;
+ case 's':
+ cp = va_arg(ap, char *);
+ width -= strlen(cp);
+ zero = zero ? '0' : ' ';
+ while(width-- > 0)
+ put_c(&b, zero);
+ put_s(&b, cp);
+ break;
+ case 'u':
+ switch(lflag) {
+ case 0:
+ udec(&b, va_arg(ap, unsigned int), width, zero);
+ break;
+ case 1:
+ udec(&b, va_arg(ap, unsigned long), width, zero);
+ break;
+ default:
+ udec(&b, va_arg(ap, unsigned long long), width, zero);
+ break;
+ }
+ break;
+ case 'X': case 'x':
+ switch(lflag) {
+ case 0:
+ hex(&b, va_arg(ap, unsigned int), width, zero,
+ *fmt == 'X', 0);
+ break;
+ case 1:
+ hex(&b, va_arg(ap, unsigned long), width, zero,
+ *fmt == 'X', 0);
+ break;
+ default:
+ hex(&b, va_arg(ap, unsigned long long), width, zero,
+ *fmt == 'X', 0);
+ break;
+ }
+ break;
+ default:
+ put_c(&b, *fmt);
+ break;
+ }
+ break;
+ }
+ fmt++;
+ }
+ flush(&b);
+}
+
+/*
+ * A simplified fprintf variant. The format string is interpreted with
+ * arguments for the variable argument list, and the results are written
+ * to the given file descriptor.
+ */
+void
+_simple_dprintf(int fd, const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+ _simple_vdprintf(fd, format, ap);
+ va_end(ap);
+}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
extern void spin_lock(int *);
+static inline void *allocate_pages(unsigned) __attribute__((always_inline));
static inline void *allocate_pages(unsigned bytes) {
void *address;
if (vm_allocate(mach_task_self(), (vm_address_t *)&address, bytes,
return (void *)address;
}
+static inline void deallocate_pages(void *, unsigned) __attribute__((always_inline));
static inline void deallocate_pages(void *ptr, unsigned bytes) {
vm_deallocate(mach_task_self(), (vm_address_t)ptr, bytes);
}
+static inline void copy_pages(const void *, void *, unsigned) __attribute__((always_inline));
static inline void copy_pages(const void *source, void *dest, unsigned bytes) {
if (vm_copy(mach_task_self(), (vm_address_t)source, bytes, (vm_address_t)dest)) memmove(dest, source, bytes);
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#include <fcntl.h>
#include <paths.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
+#include <notify.h>
#ifdef __STDC__
#include <stdarg.h>
#endif
#include <crt_externs.h>
-
-static int LogFile = -1; /* fd for log */
-static int connected; /* have done connect */
-static int LogStat = 0; /* status bits, set by openlog() */
-static const char *LogTag = NULL; /* string to tag the entry with */
-static int LogFacility = LOG_USER; /* default facility code */
-static int LogMask = 0xff; /* mask of priorities to be logged */
+
+#define LOG_NO_NOTIFY 0x1000
+
+#ifdef BUILDING_VARIANT
+__private_extern__ int _sl_LogFile; /* fd for log */
+__private_extern__ int _sl_connected; /* have done connect */
+__private_extern__ int _sl_LogStat; /* status bits, set by openlog() */
+__private_extern__ const char *_sl_LogTag; /* string to tag the entry with */
+__private_extern__ int _sl_LogFacility; /* default facility code */
+__private_extern__ int _sl_LogMask; /* mask of priorities to be logged */
+__private_extern__ int _sl_NotifyToken; /* for remote control of priority filter */
+__private_extern__ int _sl_NotifyMaster; /* for remote control of priority filter */
+#else /* !BUILDING_VARIANT */
+__private_extern__ int _sl_LogFile = -1; /* fd for log */
+__private_extern__ int _sl_connected = 0; /* have done connect */
+__private_extern__ int _sl_LogStat = 0; /* status bits, set by openlog() */
+__private_extern__ const char *_sl_LogTag = NULL; /* string to tag the entry with */
+__private_extern__ int _sl_LogFacility = LOG_USER; /* default facility code */
+__private_extern__ int _sl_LogMask = 0xff; /* mask of priorities to be logged */
+__private_extern__ int _sl_NotifyToken = -1; /* for remote control of max logged priority */
+__private_extern__ int _sl_NotifyMaster = -1; /* for remote control of max logged priority */
+#endif /* BUILDING_VARIANT */
+
+__private_extern__ void _sl_init_notify();
+
+#define NOTIFY_SYSTEM_MASTER "com.apple.system.syslog.master"
+#define NOTIFY_PREFIX_SYSTEM "com.apple.system.syslog"
+#define NOTIFY_PREFIX_USER "user.syslog"
+#define NOTIFY_STATE_OFFSET 1000
+
+/* notify SPI */
+uint32_t notify_get_state(int token, int *state);
+uint32_t notify_register_plain(const char *name, int *out_token);
/*
* syslog, vsyslog --
register int cnt;
register char ch, *p, *t;
time_t now;
- int fd, saved_errno;
+ int fd, saved_errno, filter, cval, rc_filter, primask;
#define TBUF_LEN 2048
#define FMT_LEN 1024
char *stdp, tbuf[TBUF_LEN], fmt_cpy[FMT_LEN];
int tbuf_left, fmt_left, prlen;
-
+
#define INTERNALLOG LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID
/* Check for invalid bits. */
- if (pri & ~(LOG_PRIMASK|LOG_FACMASK)) {
- syslog(INTERNALLOG,
- "syslog: unknown facility/priority: %x", pri);
+ if (pri & ~(LOG_PRIMASK|LOG_FACMASK))
+ {
+ syslog(INTERNALLOG, "syslog: unknown facility/priority: %x", pri);
pri &= LOG_PRIMASK|LOG_FACMASK;
}
- /* Check priority against setlogmask values. */
- if (!(LOG_MASK(LOG_PRI(pri)) & LogMask))
- return;
+ /* Get remote-control priority filter */
+ filter = _sl_LogMask;
+ rc_filter = 0;
+
+ _sl_init_notify();
+
+ if (_sl_NotifyToken >= 0)
+ {
+ if (notify_get_state(_sl_NotifyToken, &cval) == NOTIFY_STATUS_OK)
+ {
+ if (cval != 0)
+ {
+ filter = cval;
+ rc_filter = 1;
+ }
+ }
+ }
+
+ if ((rc_filter == 0) && (_sl_NotifyMaster >= 0))
+ {
+ if (notify_get_state(_sl_NotifyMaster, &cval) == NOTIFY_STATUS_OK)
+ {
+ if (cval != 0)
+ {
+ filter = cval;
+ }
+ }
+ }
+
+ primask = LOG_MASK(LOG_PRI(pri));
+ if ((primask & filter) == 0) return;
saved_errno = errno;
/* Set default facility if none specified. */
- if ((pri & LOG_FACMASK) == 0)
- pri |= LogFacility;
+ if ((pri & LOG_FACMASK) == 0) pri |= _sl_LogFacility;
/* Build the message. */
prlen = strftime(p, tbuf_left, "%h %e %T ", localtime(&now));
DEC();
- if (LogStat & LOG_PERROR)
- stdp = p;
- if (LogTag == NULL)
- LogTag = *(*_NSGetArgv());
- if (LogTag != NULL) {
- prlen = snprintf(p, tbuf_left, "%s", LogTag);
+ if (_sl_LogStat & LOG_PERROR) stdp = p;
+
+ if (_sl_LogTag == NULL) _sl_LogTag = *(*_NSGetArgv());
+
+ if (_sl_LogTag != NULL)
+ {
+ prlen = snprintf(p, tbuf_left, "%s", _sl_LogTag);
DEC();
}
- if (LogStat & LOG_PID) {
+
+ if (_sl_LogStat & LOG_PID)
+ {
prlen = snprintf(p, tbuf_left, "[%d]", getpid());
DEC();
}
- if (LogTag != NULL) {
- if (tbuf_left > 1) {
+
+ if (_sl_LogTag != NULL)
+ {
+ if (tbuf_left > 1)
+ {
*p++ = ':';
tbuf_left--;
}
- if (tbuf_left > 1) {
+ if (tbuf_left > 1)
+ {
*p++ = ' ';
tbuf_left--;
}
* We wouldn't need this mess if printf handled %m, or if
* strerror() had been invented before syslog().
*/
- for (t = fmt_cpy, fmt_left = FMT_LEN; (ch = *fmt); ++fmt) {
- if (ch == '%' && fmt[1] == 'm') {
+ for (t = fmt_cpy, fmt_left = FMT_LEN; (ch = *fmt); ++fmt)
+ {
+ if (ch == '%' && fmt[1] == 'm')
+ {
++fmt;
- prlen = snprintf(t, fmt_left, "%s",
- strerror(saved_errno));
- if (prlen >= fmt_left)
- prlen = fmt_left - 1;
+ prlen = snprintf(t, fmt_left, "%s", strerror(saved_errno));
+ if (prlen >= fmt_left) prlen = fmt_left - 1;
t += prlen;
fmt_left -= prlen;
- } else {
- if (fmt_left > 1) {
+ }
+ else
+ {
+ if (fmt_left > 1)
+ {
*t++ = ch;
fmt_left--;
}
}
}
+
*t = '\0';
prlen = vsnprintf(p, tbuf_left, fmt_cpy, ap);
cnt = p - tbuf;
/* Output to stderr if requested. */
- if (LogStat & LOG_PERROR) {
+ if (_sl_LogStat & LOG_PERROR)
+ {
struct iovec iov[2];
iov[0].iov_base = stdp;
}
/* Get connected, output the message to the local logger. */
- if (!connected)
- openlog(LogTag, LogStat | LOG_NDELAY, 0);
- if (send(LogFile, tbuf, cnt, 0) >= 0)
- return;
+ if (_sl_connected == 0) openlog(_sl_LogTag, _sl_LogStat | LOG_NDELAY, 0);
+ if (send(_sl_LogFile, tbuf, cnt, 0) >= 0) return;
/*
* Output the message to the console; don't worry about blocking,
* if console blocks everything will. Make sure the error reported
* is the one from the syslogd failure.
*/
- if (LogStat & LOG_CONS &&
- (fd = open(_PATH_CONSOLE, O_WRONLY, 0)) >= 0) {
+ if (_sl_LogStat & LOG_CONS && (fd = open(_PATH_CONSOLE, O_WRONLY, 0)) >= 0)
+ {
struct iovec iov[2];
p = strchr(tbuf, '>') + 1;
}
}
+#ifndef BUILDING_VARIANT
+
static struct sockaddr_un SyslogAddr; /* AF_UNIX address of local logger */
+__private_extern__ void
+_sl_init_notify()
+{
+ int status;
+ char *notify_name;
+ const char *prefix;
+
+ if (_sl_LogStat & LOG_NO_NOTIFY)
+ {
+ _sl_NotifyMaster = -2;
+ _sl_NotifyToken = -2;
+ return;
+ }
+
+ if (_sl_NotifyMaster == -1)
+ {
+ status = notify_register_plain(NOTIFY_SYSTEM_MASTER, &_sl_NotifyMaster);
+ if (status != NOTIFY_STATUS_OK) _sl_NotifyMaster = -2;
+ }
+
+ if (_sl_NotifyToken == -1)
+ {
+ _sl_NotifyToken = -2;
+
+ notify_name = NULL;
+ prefix = NOTIFY_PREFIX_USER;
+ if (getuid() == 0) prefix = NOTIFY_PREFIX_SYSTEM;
+ asprintf(¬ify_name, "%s.%d", prefix, getpid());
+
+ if (notify_name != NULL)
+ {
+ status = notify_register_plain(notify_name, &_sl_NotifyToken);
+ free(notify_name);
+ if (status != NOTIFY_STATUS_OK) _sl_NotifyToken = -2;
+ }
+ }
+}
+
void
openlog(ident, logstat, logfac)
const char *ident;
int logstat, logfac;
{
- if (ident != NULL)
- LogTag = ident;
- LogStat = logstat;
- if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0)
- LogFacility = logfac;
+ if (ident != NULL) _sl_LogTag = ident;
+
+ _sl_LogStat = logstat;
+
+ if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0) _sl_LogFacility = logfac;
- if (LogFile == -1) {
+ if (_sl_LogFile == -1)
+ {
SyslogAddr.sun_family = AF_UNIX;
- (void)strncpy(SyslogAddr.sun_path, _PATH_LOG,
- sizeof(SyslogAddr.sun_path));
- if (LogStat & LOG_NDELAY) {
- if ((LogFile = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1)
- return;
- (void)fcntl(LogFile, F_SETFD, 1);
+ (void)strncpy(SyslogAddr.sun_path, _PATH_LOG, sizeof(SyslogAddr.sun_path));
+ if (_sl_LogStat & LOG_NDELAY)
+ {
+ if ((_sl_LogFile = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) return;
+ (void)fcntl(_sl_LogFile, F_SETFD, 1);
}
}
- if (LogFile != -1 && !connected)
- if (connect(LogFile, (struct sockaddr *)&SyslogAddr, sizeof(SyslogAddr)) == -1) {
- (void)close(LogFile);
- LogFile = -1;
- } else
- connected = 1;
+
+ if ((_sl_LogFile != -1) && (_sl_connected == 0))
+ {
+ if (connect(_sl_LogFile, (struct sockaddr *)&SyslogAddr, sizeof(SyslogAddr)) == -1)
+ {
+ (void)close(_sl_LogFile);
+ _sl_LogFile = -1;
+ }
+ else
+ {
+ _sl_connected = 1;
+ }
+ }
+
+ _sl_init_notify();
}
void
closelog()
{
- (void)close(LogFile);
- LogFile = -1;
- connected = 0;
+ (void)close(_sl_LogFile);
+ _sl_LogFile = -1;
+ _sl_connected = 0;
}
/* setlogmask -- set the log mask level */
{
int omask;
- omask = LogMask;
- if (pmask != 0)
- LogMask = pmask;
+ omask = _sl_LogMask;
+ if (pmask != 0) _sl_LogMask = pmask;
return (omask);
}
+
+#endif /* !BUILDING_VARIANT */
#define B9600 9600
#define B19200 19200
#define B38400 38400
-#ifndef _POSIX_SOURCE
+#ifndef _POSIX_C_SOURCE
#define EXTA 19200
#define EXTB 38400
-#endif /*_POSIX_SOURCE */
+#endif /*_POSIX_C_SOURCE */
.Ed
.Pp
The
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* NOT fully functional
*/
+#include "xlocale_private.h"
+
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
const char *sp;
char *dp;
int status = 0;
+ locale_t loc = __current_locale();
/* devour leading white space */
- for(ccp = words; *ccp != 0 && isspace(*ccp); )
+ for(ccp = words; *ccp != 0 && isspace_l(*ccp, loc); )
ccp++;
/* skip comments */
if(*ccp == '#')
if (*sp == 0)
class = EOS;
- else if (isspace(*sp))
+ else if (isspace_l(*sp, loc))
class = SPACE;
else if (*sp == '"')
class = QUOTE;
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
# mcount cannot be compiled with profiling
gmon.po:
${CC} -O -pipe -arch ${MACHINE_ARCH} -Wmost -g -fno-common \
- -no-cpp-precomp -force_cpusubtype_ALL -I${.CURDIR}/include \
- -I${.CURDIR}/include/objc \
+ -no-cpp-precomp -force_cpusubtype_ALL \
+ -I${.CURDIR}/include \
+ -I${INCLUDEDIR} \
+ -I${INCLUDEDIR}/objc \
${PRIVINC} \
-c ${.CURDIR}/gmon/gmon.c -o gmon.po
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
void);
extern void monoutput(
const char *filename);
-extern int add_profil(char *, int, int, int);
static char profiling = -1; /* tas (test and set) location for NeXT */
static char init = 0; /* set while moninit() is being serviced */
.PATH: ${.CURDIR}/i386/gen
-MDSRCS+= ecvt.c \
- icacheinval.s \
+MDSRCS+= icacheinval.s \
mcount.s \
setjmperr.c
+++ /dev/null
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-/*
- * ecvt converts to decimal
- * the number of digits is specified by ndigit
- * decptp is set to the position of the decimal point
- * signp is set to 0 for positive, 1 for negative
- */
-
-
-static double ecvt_rint(double x);
-static double ecvt_copysign(double x, double y);
-
-static char *cvt();
-
-/* big enough to handle %.20f conversion of 1e308 */
-#define NDIG 350
-
-char*
-ecvt(arg, ndigits, decptp, signp)
-double arg;
-int ndigits, *decptp, *signp;
-{
- return(cvt(arg, ndigits, decptp, signp, 1));
-}
-
-char*
-fcvt(arg, ndigits, decptp, signp)
-double arg;
-int ndigits, *decptp, *signp;
-{
- return(cvt(arg, ndigits, decptp, signp, 0));
-}
-
-static char*
-cvt(arg, ndigits, decptp, signp, eflag)
-double arg;
-int ndigits, *decptp, *signp;
-int eflag;
-{
- register int decpt;
- double fi, fj;
- register char *p, *p1;
- static char buf[NDIG] = { 0 };
- double modf();
-
- if (ndigits < 0)
- ndigits = 0;
- if (ndigits >= NDIG-1)
- ndigits = NDIG-2;
-
- decpt = 0;
- *signp = 0;
- p = &buf[0];
-
- if (arg == 0) {
- *decptp = 0;
- while (p < &buf[ndigits])
- *p++ = '0';
- *p = '\0';
- return(buf);
- } else if (arg < 0) {
- *signp = 1;
- arg = -arg;
- }
-
- arg = modf(arg, &fi);
- p1 = &buf[NDIG];
-
- /*
- * Do integer part
- */
- if (fi != 0) {
- while (fi != 0) {
- fj = modf(fi/10, &fi);
- /**--p1 = (int)((fj+.03)*10) + '0';*/
- *--p1 = (int)ecvt_rint((fj)*10) + '0';
- decpt++;
- }
- while (p1 < &buf[NDIG])
- *p++ = *p1++;
- } else if (arg > 0) {
- while ((fj = arg*10) < 1) {
- arg = fj;
- decpt--;
- }
- }
- *decptp = decpt;
-
- /*
- * do fraction part
- * p pts to where fraction should be concatenated
- * p1 is how far conversion must go to
- */
- p1 = &buf[ndigits];
- if (eflag==0) {
- /* fcvt must provide ndigits after decimal pt */
- p1 += decpt;
- /* if decpt was negative, we might done for fcvt */
- if (p1 < &buf[0]) {
- buf[0] = '\0';
- return(buf);
- }
- }
- while (p <= p1 && p < &buf[NDIG]) {
- arg *= 10;
- arg = modf(arg, &fj);
- *p++ = (int)fj + '0';
- }
- /*
- * if we converted all the way to the end of the
- * buf, don't mess with rounding since there's nothing
- * significant out here anyway
- */
- if (p1 >= &buf[NDIG]) {
- buf[NDIG-1] = '\0';
- return(buf);
- }
- /*
- * round by adding 5 to last digit and propagating
- * carries
- */
- p = p1;
- *p1 += 5;
- while (*p1 > '9') {
- *p1 = '0';
- if (p1 > buf)
- ++*--p1;
- else {
- *p1 = '1';
- (*decptp)++;
- if (eflag == 0) {
- if (p > buf)
- *p = '0';
- p++;
- }
- }
- }
- *p = '\0';
- return(buf);
-}
-
-static double ecvt_rint(double x)
-{
- asm("frndint" : "=t" (x) : "0" (x));
- return(x);
-}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
ATsocket.s \
_exit.s \
_getlogin.s \
+ __mmap.s \
_pthread_kill.s \
+ __pthread_canceled.s \
+ __pthread_markcancel.s \
+ __semwait_signal.s \
_setjmp.s \
_setlogin.s \
_sysctl.s \
audit.s \
auditctl.s \
auditon.s \
- auditsvc.s \
bind.s \
cerror.s \
chdir.s \
getauid.s \
getdirentries.s \
getdirentriesattr.s \
+ getdtablesize.s \
getegid.s \
geteuid.s \
getfh.s \
mknod.s \
mlock.s \
mlockall.s \
- mmap.s \
mount.s \
- mprotect.s \
- msgctl.s \
msgget.s \
msgrcv.s \
msgsnd.s \
msgsys.s \
- msync.s \
munlock.s \
munlockall.s \
- munmap.s \
new_system_shared_regions.s \
nfsclnt.s \
nfssvc.s \
open.s \
+ OSAtomic.s \
pathconf.s \
pipe.s \
+ poll.s \
posix_madvise.s \
pread.s \
profil.s \
sem_trywait.s \
sem_wait.s \
semconfig.s \
- semctl.s \
semget.s \
semop.s \
semsys.s \
setuid.s \
setxattr.s \
shmat.s \
- shmctl.s \
shmdt.s \
shmget.s \
shmsys.s \
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include <machine/cpu_capabilities.h>
+
+#define DECLARE(x) \
+.align 2, 0x90 ; \
+.globl x ; \
+.globl x ## Barrier ; \
+x: ; \
+x ## Barrier:
+
+.text
+
+DECLARE(_OSAtomicAnd32)
+ movl 8(%esp), %ecx
+ movl (%ecx), %eax
+1:
+ movl 4(%esp), %edx
+ andl %eax, %edx
+ call *_COMM_PAGE_COMPARE_AND_SWAP32
+ jnz 1b
+ movl %edx, %eax
+ ret
+
+DECLARE(_OSAtomicOr32)
+ movl 8(%esp), %ecx
+ movl (%ecx), %eax
+1:
+ movl 4(%esp), %edx
+ orl %eax, %edx
+ call *_COMM_PAGE_COMPARE_AND_SWAP32
+ jnz 1b
+ movl %edx, %eax
+ ret
+
+DECLARE(_OSAtomicXor32)
+ movl 8(%esp), %ecx
+ movl (%ecx), %eax
+1:
+ movl 4(%esp), %edx
+ xorl %eax, %edx
+ call *_COMM_PAGE_COMPARE_AND_SWAP32
+ jnz 1b
+ movl %edx, %eax
+ ret
+
+DECLARE(_OSAtomicCompareAndSwap32)
+ movl 4(%esp), %eax
+ movl 8(%esp), %edx
+ movl 12(%esp), %ecx
+ call *_COMM_PAGE_COMPARE_AND_SWAP32
+ sete %al
+ ret
+
+.align 2, 0x90
+DECLARE(_OSAtomicCompareAndSwap64)
+ pushl %ebx
+ pushl %esi
+ movl 12(%esp), %eax
+ movl 16(%esp), %edx
+ movl 20(%esp), %ebx
+ movl 24(%esp), %ecx
+ movl 28(%esp), %esi
+ call *_COMM_PAGE_COMPARE_AND_SWAP64
+ sete %al
+ popl %esi
+ popl %ebx
+ ret
+
+DECLARE(_OSAtomicAdd32)
+ movl 4(%esp), %eax
+ movl 8(%esp), %edx
+ movl %eax, %ecx
+ call *_COMM_PAGE_ATOMIC_ADD32
+ addl %ecx, %eax
+ ret
+
+DECLARE(_OSAtomicAdd64)
+ pushl %ebx
+ pushl %esi
+ movl 20(%esp), %esi
+ movl 0(%esi), %eax
+ movl 4(%esi), %edx
+1: movl 12(%esp), %ebx
+ movl 16(%esp), %ecx
+ addl %eax, %ebx
+ adcl %edx, %ecx
+ call *_COMM_PAGE_COMPARE_AND_SWAP64
+ jnz 1b
+ movl %ebx, %eax
+ movl %ecx, %ebx
+ popl %esi
+ popl %ebx
+ ret
+
+DECLARE(_OSAtomicTestAndSet)
+ movl 4(%esp), %eax
+ movl 8(%esp), %edx
+ call *_COMM_PAGE_BTS
+ setc %al
+ ret
+
+DECLARE(_OSAtomicTestAndClear)
+ movl 4(%esp), %eax
+ movl 8(%esp), %edx
+ call *_COMM_PAGE_BTC
+ setc %al
+ ret
+
+.align 2, 0x90
+.globl _OSSpinLockTry
+_OSSpinLockTry:
+ movl $(_COMM_PAGE_SPINLOCK_TRY), %eax
+ jmpl %eax
+
+.align 2, 0x90
+.globl _OSSpinLockLock
+_OSSpinLockLock:
+ movl $(_COMM_PAGE_SPINLOCK_LOCK), %eax
+ jmpl %eax
+
+.align 2, 0x90
+.globl _OSSpinLockUnlock
+_OSSpinLockUnlock:
+ movl 4(%esp), %eax
+ movl $0, (%eax)
+ ret
+
+.align 2, 0x90
+.globl _OSMemoryBarrier
+_OSMemoryBarrier:
+ ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#define MACHDEP_SYSCALL_TRAP lcall $0x7, $0
+/*
+ * This is the same as UNIX_SYSCALL, but it can call an alternate error
+ * return function. It's generic to support potential future callers.
+ */
+#define UNIX_SYSCALL_ERR(name, nargs,error_ret) \
+ .globl error_ret ;\
+LEAF(_##name, 0) ;\
+ movl $ SYS_##name, %eax ;\
+ UNIX_SYSCALL_TRAP ;\
+ jnb 2f ;\
+ BRANCH_EXTERN(error_ret) ;\
+2:
+
#define UNIX_SYSCALL(name, nargs) \
.globl cerror ;\
LEAF(_##name, 0) ;\
#define SYS_shmget 265
#endif
+#if !defined(SYS___pthread_canceled)
+#define SYS___pthread_markcancel 332
+#define SYS___pthread_canceled 333
+#define SYS___semwait_signal 334
+#endif
+
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include "SYS.h"
+
+PSEUDO(__mmap, mmap, 6)
+ ret
--- /dev/null
+/*
+ * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+/*
+ * Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved
+ */
+#include "SYS.h"
+
+UNIX_SYSCALL(__pthread_canceled, 1)
+ ret
--- /dev/null
+/*
+ * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+/*
+ * Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved
+ */
+#include "SYS.h"
+
+UNIX_SYSCALL(__pthread_markcancel, 1)
+ ret
--- /dev/null
+/*
+ * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+/*
+ * Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved
+ */
+#include "SYS.h"
+
+UNIX_SYSCALL(__semwait_signal, 6)
+ ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
-UNIX_SYSCALL(accept, 3)
+PSEUDO(accept$UNIX2003, accept, 3)
+ ret
+
+UNIX_SYSCALL_ERR(accept, 3, cerror_cvt)
ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
-UNIX_SYSCALL(bind, 3)
+PSEUDO(bind$UNIX2003, bind, 3)
+ ret
+
+UNIX_SYSCALL_ERR(bind, 3, cerror_cvt)
ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
.globl _errno
+LABEL(cerror_cvt)
+ cmpl $102, %eax /* EOPNOTSUPP? */
+ jnz cerror
+ movl $45, %eax /* Yes; make ENOTSUP for compatibility */
LABEL(cerror)
REG_TO_EXTERN(%eax, _errno)
pushl %eax
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
-UNIX_SYSCALL(connect, 3)
+PSEUDO(connect$UNIX2003, connect, 3)
+ ret
+
+UNIX_SYSCALL_ERR(connect, 3, cerror_cvt)
ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
-UNIX_SYSCALL(getattrlist, 0)
+PSEUDO(getattrlist$UNIX2003, getattrlist, 0)
+ ret
+
+UNIX_SYSCALL_ERR(getattrlist, 0, cerror_cvt)
ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include "SYS.h"
+
+UNIX_SYSCALL(getdtablesize, 0)
+ ret // i = getdtablesize();
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
-UNIX_SYSCALL(getpeername, 3)
+PSEUDO(getpeername$UNIX2003, getpeername, 3)
+ ret
+
+UNIX_SYSCALL_ERR(getpeername, 3, cerror_cvt)
ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
-UNIX_SYSCALL(getsockname, 3)
+PSEUDO(getsockname$UNIX2003, getsockname, 3)
+ ret
+
+UNIX_SYSCALL_ERR(getsockname, 3, cerror_cvt)
ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
/*
- * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
-UNIX_SYSCALL(lchown, 3)
+PSEUDO(lchown$UNIX2003, lchown, 3)
+ ret
+
+UNIX_SYSCALL_ERR(lchown, 3, cerror_cvt)
ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
-UNIX_SYSCALL(listen, 2)
+PSEUDO(listen$UNIX2003, listen, 2)
+ ret
+
+UNIX_SYSCALL_ERR(listen, 2, cerror_cvt)
ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
+++ /dev/null
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-/*
- * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
- */
-#include "SYS.h"
-
-UNIX_SYSCALL(mmap, 6)
- ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
+++ /dev/null
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-/*
- * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
- */
-#include "SYS.h"
-
-UNIX_SYSCALL(mprotect, 3)
- ret
+++ /dev/null
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-/*
- * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
- */
-#include "SYS.h"
-
-UNIX_SYSCALL(msgctl, 3)
- ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
+++ /dev/null
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-/*
- * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
- */
-#include "SYS.h"
-
-UNIX_SYSCALL(msync, 3)
- ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
+++ /dev/null
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-/*
- * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
- */
-#include "SYS.h"
-
-UNIX_SYSCALL(munmap, 2)
- ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include "SYS.h"
+
+UNIX_SYSCALL(poll, 3)
+ ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
-UNIX_SYSCALL(recvfrom, 6)
+PSEUDO(recvfrom$UNIX2003, recvfrom, 6)
+ ret
+
+UNIX_SYSCALL_ERR(recvfrom, 6, cerror_cvt)
ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
-UNIX_SYSCALL(recvmsg, 3)
+PSEUDO(recvmsg$UNIX2003, recvmsg, 3)
+ ret
+
+UNIX_SYSCALL_ERR(recvmsg, 3, cerror_cvt)
ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
+++ /dev/null
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-/*
- * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
- */
-#include "SYS.h"
-
-UNIX_SYSCALL(semctl, 3)
- ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
-UNIX_SYSCALL(sendmsg, 3)
+PSEUDO(sendmsg$UNIX2003, sendmsg, 3)
+ ret
+
+UNIX_SYSCALL_ERR(sendmsg, 3, cerror_cvt)
ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
-UNIX_SYSCALL(sendto, 6)
+PSEUDO(sendto$UNIX2003, sendto, 6)
+ ret
+
+UNIX_SYSCALL_ERR(sendto, 6, cerror_cvt)
ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
-UNIX_SYSCALL(setattrlist, 0)
+PSEUDO(setattrlist$UNIX2003, setattrlist, 0)
+ ret
+
+UNIX_SYSCALL_ERR(setattrlist, 0, cerror_cvt)
ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
+++ /dev/null
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-/*
- * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
- */
-#include "SYS.h"
-
-UNIX_SYSCALL(shmctl, 3)
- ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
-UNIX_SYSCALL(socketpair, 5)
+PSEUDO(socketpair$UNIX2003, socketpair, 5)
+ ret
+
+UNIX_SYSCALL_ERR(socketpair, 5, cerror_cvt)
ret
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
.include "${.CURDIR}/include/arpa/Makefile.inc"
.include "${.CURDIR}/include/libkern/Makefile.inc"
.include "${.CURDIR}/include/protocols/Makefile.inc"
+.include "${.CURDIR}/include/machine/Makefile.inc"
.include "${.CURDIR}/include/malloc/Makefile.inc"
.include "${.CURDIR}/include/objc/Makefile.inc"
.include "${.CURDIR}/include/sys/Makefile.inc"
+.include "${.CURDIR}/include/xlocale/Makefile.inc"
INC_INSTHDRS += NSSystemDirectories.h \
+ _locale.h \
_types.h \
+ _wctype.h \
+ _xlocale.h \
aio.h \
alloca.h \
ar.h \
+ asl.h \
+ assert.h \
asm.h \
bitstring.h \
c.h \
err.h \
errno.h \
fcntl.h \
+ float.h \
fmtmsg.h \
fnmatch.h \
fsproperties.h \
getopt.h \
glob.h \
grp.h \
+ inttypes.h \
iso646.h \
kvm.h \
langinfo.h \
nl_types.h \
nlist.h \
paths.h \
+ poll.h \
pwd.h \
ranlib.h \
readpassphrase.h \
regex.h \
- regexp.h \
rune.h \
runetype.h \
search.h \
signal.h \
stab.h \
standards.h \
+ stdarg.h \
+ stdbool.h \
stddef.h \
stdio.h \
stdlib.h \
time.h \
timeconv.h \
ttyent.h \
- tzfile.h \
ucontext.h \
ulimit.h \
unistd.h \
util.h \
utime.h \
utmp.h \
+ varargs.h \
vis.h \
wchar.h \
wctype.h \
- wordexp.h
+ wordexp.h \
+ xlocale.h
.PATH: ${.CURDIR}/include
MAN3 += sysexits.3
INC_INSTHDRS := ${INC_INSTHDRS:S/^/${.CURDIR}\/include\//}
INSTHDRS += ${INC_INSTHDRS}
+
+STRIP_HDRS += ctype.h
+
+.include "Makefile.nbsd_begin"
+NBSDHDRS = utmpx.h
+.include "Makefile.nbsd_end"
+INSTHDRS_AUTOPATCH += utmpx.h
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
// Directories
typedef enum {
- NSApplicationDirectory = 1, // supported applications (Applications)
- NSDemoApplicationDirectory, // unsupported applications, demonstration versions (Applications/GrabBag)
- NSDeveloperApplicationDirectory, // developer applications (Developer/Applications)
- NSAdminApplicationDirectory, // system and network administration applications (Applications/Utilities)
- NSLibraryDirectory, // various user-visible documentation, support, and configuration files, resources (Library)
- NSDeveloperDirectory, // developer resources (Developer)
- NSUserDirectory, // user home directories (Users)
- NSDocumentationDirectory, // documentation (Library/Documentation)
- NSDocumentDirectory, // documents (Documents)
- NSCoreServiceDirectory, // location of core services (System/Library/CoreServices)
- NSAllApplicationsDirectory = 100, // all directories where applications can occur (Applications, Applications/Utilities, Developer/Applications, Applications/GrabBag)
- NSAllLibrariesDirectory = 101 // all directories where resources can occur (Library, Developer)
+ NSApplicationDirectory = 1, // supported applications (Applications)
+ NSDemoApplicationDirectory = 2, // unsupported applications, demonstration versions (Applications/GrabBag)
+ NSDeveloperApplicationDirectory = 3, // developer applications (Developer/Applications)
+ NSAdminApplicationDirectory = 4, // system and network administration applications (Applications/Utilities)
+ NSLibraryDirectory = 5, // various user-visible documentation, support, and configuration files, resources (Library)
+ NSDeveloperDirectory = 6, // developer resources (Developer)
+ NSUserDirectory = 7, // user home directories (Users)
+ NSDocumentationDirectory = 8, // documentation (Library/Documentation)
+ NSDocumentDirectory = 9, // documents (Documents)
+ NSCoreServiceDirectory = 10, // location of core services (System/Library/CoreServices)
+ NSDesktopDirectory = 12, // location of user's Desktop (Desktop)
+ NSCachesDirectory = 13, // location of discardable cache files (Library/Caches)
+ NSApplicationSupportDirectory = 14, // location of application support files (plug-ins, etc) (Library/Application Support)
+ NSAllApplicationsDirectory = 100, // all directories where applications can occur (Applications, Applications/Utilities, Developer/Applications, ...)
+ NSAllLibrariesDirectory = 101 // all directories where resources can occur (Library, Developer)
} NSSearchPathDirectory;
// Domains
--- /dev/null
+/* $NetBSD: utmpx.h,v 1.11 2003/08/26 16:48:32 wiz Exp $ */
+
+/*-
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+#ifndef _UTMPX_H_
+#define _UTMPX_H_
+
+#include <sys/cdefs.h>
+#include <sys/featuretest.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+
+#define _PATH_UTMPX "/var/run/utmpx"
+#define _PATH_WTMPX "/var/log/wtmpx"
+#define _PATH_LASTLOGX "/var/log/lastlogx"
+#define _PATH_UTMP_UPDATE "/usr/libexec/utmp_update"
+
+#define _UTX_USERSIZE 32
+#define _UTX_LINESIZE 32
+#define _UTX_IDSIZE 4
+#define _UTX_HOSTSIZE 256
+
+#if defined(_NETBSD_SOURCE)
+#define UTX_USERSIZE _UTX_USERSIZE
+#define UTX_LINESIZE _UTX_LINESIZE
+#define UTX_IDSIZE _UTX_IDSIZE
+#define UTX_HOSTSIZE _UTX_HOSTSIZE
+#endif
+
+#define EMPTY 0
+#define RUN_LVL 1
+#define BOOT_TIME 2
+#define OLD_TIME 3
+#define NEW_TIME 4
+#define INIT_PROCESS 5
+#define LOGIN_PROCESS 6
+#define USER_PROCESS 7
+#define DEAD_PROCESS 8
+
+#if defined(_NETBSD_SOURCE)
+#define ACCOUNTING 9
+#define SIGNATURE 10
+#endif
+
+/*
+ * The following structure describes the fields of the utmpx entries
+ * stored in _PATH_UTMPX or _PATH_WTMPX. This is not the format the
+ * entries are stored in the files, and application should only access
+ * entries using routines described in getutxent(3).
+ */
+
+#define ut_user ut_name
+#define ut_xtime ut_tv.tv_sec
+
+struct utmpx {
+ char ut_name[_UTX_USERSIZE]; /* login name */
+ char ut_id[_UTX_IDSIZE]; /* inittab id */
+ char ut_line[_UTX_LINESIZE]; /* tty name */
+ char ut_host[_UTX_HOSTSIZE]; /* host name */
+ uint16_t ut_session; /* session id used for windowing */
+ uint16_t ut_type; /* type of this entry */
+ pid_t ut_pid; /* process id creating the entry */
+ struct {
+ uint16_t e_termination; /* process termination signal */
+ uint16_t e_exit; /* process exit status */
+ } ut_exit;
+ struct sockaddr_storage ut_ss; /* address where entry was made from */
+ struct timeval ut_tv; /* time entry was created */
+ uint32_t ut_pad[10]; /* reserved for future use */
+};
+
+#if defined(_NETBSD_SOURCE)
+struct lastlogx {
+ struct timeval ll_tv; /* time entry was created */
+ char ll_line[_UTX_LINESIZE]; /* tty name */
+ char ll_host[_UTX_HOSTSIZE]; /* host name */
+ struct sockaddr_storage ll_ss; /* address where entry was made from */
+};
+#endif /* !_XOPEN_SOURCE */
+
+__BEGIN_DECLS
+
+void setutxent __P((void));
+void endutxent __P((void));
+struct utmpx *getutxent __P((void));
+struct utmpx *getutxid __P((const struct utmpx *));
+struct utmpx *getutxline __P((const struct utmpx *));
+struct utmpx *pututxline __P((const struct utmpx *));
+
+#if defined(_NETBSD_SOURCE)
+int updwtmpx __P((const char *, const struct utmpx *));
+int lastlogxname __P((const char *));
+#ifdef __LIBC12_SOURCE__
+struct lastlogx *getlastlogx __P((uid_t, struct lastlogx *));
+struct lastlogx *__getlastlogx13 __P((const char *, uid_t, struct lastlogx *));
+#else
+struct lastlogx *getlastlogx __P((const char *, uid_t, struct lastlogx *))
+ __RENAME(__getlastlogx13);
+#endif
+int updlastlogx __P((const char *, uid_t, struct lastlogx *));
+struct utmp;
+void getutmp __P((const struct utmpx *, struct utmp *));
+void getutmpx __P((const struct utmp *, struct utmpx *));
+
+int utmpxname __P((const char *));
+
+#endif /* _NETBSD_SOURCE */
+
+__END_DECLS
+
+#endif /* !_UTMPX_H_ */
--- /dev/null
+--- utmpx.h.orig 2004-08-05 14:37:28.000000000 -0700
++++ utmpx.h 2004-08-05 15:42:48.000000000 -0700
+@@ -38,28 +38,26 @@
+ #ifndef _UTMPX_H_
+ #define _UTMPX_H_
+
+-#include <sys/cdefs.h>
+-#include <sys/featuretest.h>
+-#include <sys/socket.h>
++#include <_types.h>
+ #include <sys/time.h>
+
++#ifndef _PID_T
++#define _PID_T
++typedef __darwin_pid_t pid_t;
++#endif
++
+ #define _PATH_UTMPX "/var/run/utmpx"
+-#define _PATH_WTMPX "/var/log/wtmpx"
+-#define _PATH_LASTLOGX "/var/log/lastlogx"
+ #define _PATH_UTMP_UPDATE "/usr/libexec/utmp_update"
+
++#ifndef _POSIX_C_SOURCE
++#define UTMPX_FILE _PATH_UTMPX
++#endif /* _POSIX_C_SOURCE */
++
+ #define _UTX_USERSIZE 32
+ #define _UTX_LINESIZE 32
+ #define _UTX_IDSIZE 4
+ #define _UTX_HOSTSIZE 256
+
+-#if defined(_NETBSD_SOURCE)
+-#define UTX_USERSIZE _UTX_USERSIZE
+-#define UTX_LINESIZE _UTX_LINESIZE
+-#define UTX_IDSIZE _UTX_IDSIZE
+-#define UTX_HOSTSIZE _UTX_HOSTSIZE
+-#endif
+-
+ #define EMPTY 0
+ #define RUN_LVL 1
+ #define BOOT_TIME 2
+@@ -69,75 +67,35 @@
+ #define LOGIN_PROCESS 6
+ #define USER_PROCESS 7
+ #define DEAD_PROCESS 8
+-
+-#if defined(_NETBSD_SOURCE)
+ #define ACCOUNTING 9
+ #define SIGNATURE 10
+-#endif
+
+ /*
+ * The following structure describes the fields of the utmpx entries
+- * stored in _PATH_UTMPX or _PATH_WTMPX. This is not the format the
++ * stored in _PATH_UTMPX. This is not the format the
+ * entries are stored in the files, and application should only access
+ * entries using routines described in getutxent(3).
+ */
+
+-#define ut_user ut_name
+-#define ut_xtime ut_tv.tv_sec
+-
+ struct utmpx {
+- char ut_name[_UTX_USERSIZE]; /* login name */
+- char ut_id[_UTX_IDSIZE]; /* inittab id */
++ char ut_user[_UTX_USERSIZE]; /* login name */
++ char ut_id[_UTX_IDSIZE]; /* id */
+ char ut_line[_UTX_LINESIZE]; /* tty name */
+- char ut_host[_UTX_HOSTSIZE]; /* host name */
+- uint16_t ut_session; /* session id used for windowing */
+- uint16_t ut_type; /* type of this entry */
+ pid_t ut_pid; /* process id creating the entry */
+- struct {
+- uint16_t e_termination; /* process termination signal */
+- uint16_t e_exit; /* process exit status */
+- } ut_exit;
+- struct sockaddr_storage ut_ss; /* address where entry was made from */
++ short ut_type; /* type of this entry */
+ struct timeval ut_tv; /* time entry was created */
+- uint32_t ut_pad[10]; /* reserved for future use */
+-};
+-
+-#if defined(_NETBSD_SOURCE)
+-struct lastlogx {
+- struct timeval ll_tv; /* time entry was created */
+- char ll_line[_UTX_LINESIZE]; /* tty name */
+- char ll_host[_UTX_HOSTSIZE]; /* host name */
+- struct sockaddr_storage ll_ss; /* address where entry was made from */
++ char ut_host[_UTX_HOSTSIZE]; /* host name */
++ __uint32_t ut_pad[16]; /* reserved for future use */
+ };
+-#endif /* !_XOPEN_SOURCE */
+
+ __BEGIN_DECLS
+
+-void setutxent __P((void));
+-void endutxent __P((void));
+-struct utmpx *getutxent __P((void));
+-struct utmpx *getutxid __P((const struct utmpx *));
+-struct utmpx *getutxline __P((const struct utmpx *));
+-struct utmpx *pututxline __P((const struct utmpx *));
+-
+-#if defined(_NETBSD_SOURCE)
+-int updwtmpx __P((const char *, const struct utmpx *));
+-int lastlogxname __P((const char *));
+-#ifdef __LIBC12_SOURCE__
+-struct lastlogx *getlastlogx __P((uid_t, struct lastlogx *));
+-struct lastlogx *__getlastlogx13 __P((const char *, uid_t, struct lastlogx *));
+-#else
+-struct lastlogx *getlastlogx __P((const char *, uid_t, struct lastlogx *))
+- __RENAME(__getlastlogx13);
+-#endif
+-int updlastlogx __P((const char *, uid_t, struct lastlogx *));
+-struct utmp;
+-void getutmp __P((const struct utmpx *, struct utmp *));
+-void getutmpx __P((const struct utmp *, struct utmpx *));
+-
+-int utmpxname __P((const char *));
+-
+-#endif /* _NETBSD_SOURCE */
++void setutxent(void);
++void endutxent(void);
++struct utmpx *getutxent(void);
++struct utmpx *getutxid(const struct utmpx *);
++struct utmpx *getutxline(const struct utmpx *);
++struct utmpx *pututxline(const struct utmpx *);
+
+ __END_DECLS
+
--- /dev/null
+/*
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ *
+ * @(#)locale.h 8.1 (Berkeley) 6/2/93
+ * $FreeBSD: /repoman/r/ncvs/src/include/locale.h,v 1.7 2002/10/09 09:19:27 tjr Exp $
+ */
+
+#ifndef __LOCALE_H_
+#define __LOCALE_H_
+
+#include <sys/cdefs.h>
+#include <_types.h>
+
+struct lconv {
+ char *decimal_point;
+ char *thousands_sep;
+ char *grouping;
+ char *int_curr_symbol;
+ char *currency_symbol;
+ char *mon_decimal_point;
+ char *mon_thousands_sep;
+ char *mon_grouping;
+ char *positive_sign;
+ char *negative_sign;
+ char int_frac_digits;
+ char frac_digits;
+ char p_cs_precedes;
+ char p_sep_by_space;
+ char n_cs_precedes;
+ char n_sep_by_space;
+ char p_sign_posn;
+ char n_sign_posn;
+ char int_p_cs_precedes;
+ char int_n_cs_precedes;
+ char int_p_sep_by_space;
+ char int_n_sep_by_space;
+ char int_p_sign_posn;
+ char int_n_sign_posn;
+};
+
+#ifndef NULL
+#define NULL __DARWIN_NULL
+#endif /* ! NULL */
+
+__BEGIN_DECLS
+struct lconv *localeconv(void);
+__END_DECLS
+
+#endif /* __LOCALE_H_ */
/*
- * Copyright (c) 1999-2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#define __TYPES_H_
#include <sys/_types.h>
-#include <machine/ansi.h>
-
-/*
- * XXX - This block will eventually be relocated into sys/_types.h (or
- * into a header it calls. It is here temporarily to work can proceed
- * on the Libc part
- */
-#ifndef __OSX_NULL
-#ifdef __GNUG__
-#define __OSX_NULL __null
-#else /* ! __GNUG__ */
-#ifndef __cplusplus
-#define __OSX_NULL ((void *)0)
-#else /* __cplusplus */
-#define __OSX_NULL 0
-#endif /* ! __cplusplus */
-#endif /* __GNUG__ */
-
-// XXX - renaming from sys/_types.h
-typedef __mode_t __osx_mode_t;
-typedef __off_t __osx_off_t;
-typedef __size_t __osx_size_t;
-typedef __pid_t __osx_pid_t;
-typedef __gid_t __osx_gid_t;
-#endif /* XXX - ! __OSX_NULL */
-typedef _BSD_CT_RUNE_T_ __osx_ct_rune_t;
-typedef _BSD_MBSTATE_T_ __osx_mbstate_t;
-typedef int __osx_nl_item;
-#ifdef _BSD_PTRDIFF_T_
-typedef _BSD_PTRDIFF_T_ __osx_ptrdiff_t;
-#endif /* _BSD_PTRDIFF_T_ */
-typedef _BSD_RUNE_T_ __osx_rune_t;
-#ifdef __WCHAR_TYPE__
-typedef __WCHAR_TYPE__ __osx_wchar_t;
-#else /* ! __WCHAR_TYPE__ */
-typedef _BSD_WCHAR_T_ __osx_wchar_t;
-#endif /* __WCHAR_TYPE__ */
-typedef int __osx_wctrans_t;
-typedef unsigned long __osx_wctype_t;
-typedef _BSD_WINT_T_ __osx_wint_t;
+typedef int __darwin_nl_item;
+typedef int __darwin_wctrans_t;
+#ifdef __LP64__
+typedef __uint32_t __darwin_wctype_t;
+#else /* !__LP64__ */
+typedef unsigned long __darwin_wctype_t;
+#endif /* __LP64__ */
#ifdef __WCHAR_MAX__
-#define __OSX_WCHAR_MAX __WCHAR_MAX__
+#define __DARWIN_WCHAR_MAX __WCHAR_MAX__
#else /* ! __WCHAR_MAX__ */
-#define __OSX_WCHAR_MAX (sizeof(__osx_wchar_t) == 2 ? 0xffff : 0x7fffffff)
+#define __DARWIN_WCHAR_MAX 0x7fffffff
#endif /* __WCHAR_MAX__ */
-#define __OSX_WCHAR_MIN (sizeof(__osx_wchar_t) == 2 ? 0 : 0x80000000)
-#define __OSX_WEOF ((__osx_wint_t)-1)
+#if __DARWIN_WCHAR_MAX > 0xffffU
+#define __DARWIN_WCHAR_MIN (-0x7fffffff - 1)
+#else
+#define __DARWIN_WCHAR_MIN 0
+#endif
+#define __DARWIN_WEOF ((__darwin_wint_t)-1)
#endif /* __TYPES_H_ */
--- /dev/null
+/*-
+ * Copyright (c)1999 Citrus Project,
+ * 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.
+ *
+ */
+
+/*
+ * Common header for wctype.h and wchar.h
+ *
+ * Contains everything required by wctype.h except:
+ *
+ * typedef __darwin_wctrans_t wctrans_t;
+ * int iswblank(wint_t);
+ * wint_t towctrans(wint_t, wctrans_t);
+ * wctrans_t wctrans(const char *);
+ */
+
+#ifndef __WCTYPE_H_
+#define __WCTYPE_H_
+
+#include <sys/cdefs.h>
+#include <_types.h>
+
+#ifndef _WINT_T
+#define _WINT_T
+typedef __darwin_wint_t wint_t;
+#endif
+
+#ifndef _WCTYPE_T
+#define _WCTYPE_T
+typedef __darwin_wctype_t wctype_t;
+#endif
+
+#ifndef WEOF
+#define WEOF __DARWIN_WEOF
+#endif
+
+__BEGIN_DECLS
+int iswalnum(wint_t);
+int iswalpha(wint_t);
+int iswcntrl(wint_t);
+int iswctype(wint_t, wctype_t);
+int iswdigit(wint_t);
+int iswgraph(wint_t);
+int iswlower(wint_t);
+int iswprint(wint_t);
+int iswpunct(wint_t);
+int iswspace(wint_t);
+int iswupper(wint_t);
+int iswxdigit(wint_t);
+wint_t towlower(wint_t);
+wint_t towupper(wint_t);
+wctype_t
+ wctype(const char *);
+__END_DECLS
+
+#include <ctype.h>
+
+#define iswalnum(wc) __istype((wc), _CTYPE_A|_CTYPE_D)
+#define iswalpha(wc) __istype((wc), _CTYPE_A)
+#define iswcntrl(wc) __istype((wc), _CTYPE_C)
+#define iswctype(wc, charclass) __istype((wc), (charclass))
+#define iswdigit(wc) __istype((wc), _CTYPE_D)
+#define iswgraph(wc) __istype((wc), _CTYPE_G)
+#define iswlower(wc) __istype((wc), _CTYPE_L)
+#define iswprint(wc) __istype((wc), _CTYPE_R)
+#define iswpunct(wc) __istype((wc), _CTYPE_P)
+#define iswspace(wc) __istype((wc), _CTYPE_S)
+#define iswupper(wc) __istype((wc), _CTYPE_U)
+#define iswxdigit(wc) __istype((wc), _CTYPE_X)
+#define towlower(wc) __tolower(wc)
+#define towupper(wc) __toupper(wc)
+
+#ifdef _USE_EXTENDED_LOCALES_
+#include <xlocale/__wctype.h>
+#endif /* _USE_EXTENDED_LOCALES_ */
+
+#endif /* __WCTYPE_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef __XLOCALE_H_
+#define __XLOCALE_H_
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+int ___mb_cur_max(void);
+int ___mb_cur_max_l(locale_t);
+__END_DECLS
+
+#endif /* __XLOCALE_H_ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#define _ALLOCA_H_
#include <sys/cdefs.h>
-#include <machine/ansi.h>
+#include <_types.h>
-#ifndef _BSD_SIZE_T_DEFINED_
-#define _BSD_SIZE_T_DEFINED_
-typedef _BSD_SIZE_T_ size_t;
+#ifndef _SIZE_T
+#define _SIZE_T
+typedef __darwin_size_t size_t;
#endif
__BEGIN_DECLS
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * "Portions Copyright (c) 2004 Apple Computer, Inc. All Rights
+ * Reserved. This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License'). You may not use this file
+ * except in compliance with the License. Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef __ASL_H__
+#define __ASL_H__
+
+#include <stdint.h>
+#include <stdarg.h>
+#include <sys/cdefs.h>
+
+typedef struct __aslclient *aslclient;
+typedef struct __aslmsg *aslmsg;
+typedef struct __aslresponse *aslresponse;
+
+/*
+ * Log levels of the message
+ */
+#define ASL_LEVEL_EMERG 0
+#define ASL_LEVEL_ALERT 1
+#define ASL_LEVEL_CRIT 2
+#define ASL_LEVEL_ERR 3
+#define ASL_LEVEL_WARNING 4
+#define ASL_LEVEL_NOTICE 5
+#define ASL_LEVEL_INFO 6
+#define ASL_LEVEL_DEBUG 7
+
+/*
+ * Corresponding level strings
+ */
+#define ASL_STRING_EMERG "Emergency"
+#define ASL_STRING_ALERT "Alert"
+#define ASL_STRING_CRIT "Critical"
+#define ASL_STRING_ERR "Error"
+#define ASL_STRING_WARNING "Warning"
+#define ASL_STRING_NOTICE "Notice"
+#define ASL_STRING_INFO "Info"
+#define ASL_STRING_DEBUG "Debug"
+
+/*
+ * Attribute value comparison operations
+ */
+#define ASL_QUERY_OP_CASEFOLD 0x0010
+#define ASL_QUERY_OP_PREFIX 0x0020
+#define ASL_QUERY_OP_SUFFIX 0x0040
+#define ASL_QUERY_OP_SUBSTRING 0x0060
+#define ASL_QUERY_OP_NUMERIC 0x0080
+#define ASL_QUERY_OP_REGEX 0x0100
+
+#define ASL_QUERY_OP_EQUAL 0x0001
+#define ASL_QUERY_OP_GREATER 0x0002
+#define ASL_QUERY_OP_GREATER_EQUAL 0x0003
+#define ASL_QUERY_OP_LESS 0x0004
+#define ASL_QUERY_OP_LESS_EQUAL 0x0005
+#define ASL_QUERY_OP_NOT_EQUAL 0x0006
+#define ASL_QUERY_OP_TRUE 0x0007
+
+/*
+ * Attributes of all messages.
+ * The following attributes are attached to log messages,
+ * and are preserved in the order listed.
+ * Additional attributes may be added as desired, and are
+ * appended in the order that they are defined.
+ */
+#define ASL_KEY_TIME "Time" /* Timestamp (see ctime(3)). Set automatically */
+#define ASL_KEY_HOST "Host" /* Sender's address (set by the server) */
+#define ASL_KEY_SENDER "Sender" /* Sender's identification string. Default is process name */
+#define ASL_KEY_PID "PID" /* Sending process ID encoded as a string. Set automatically */
+#define ASL_KEY_UID "UID" /* UID that sent the log message (set by the server) */
+#define ASL_KEY_GID "GID" /* GID that sent the log message (set by the server) */
+#define ASL_KEY_LEVEL "Level" /* Log level number encoded as a string. See levels above */
+#define ASL_KEY_MSG "Message" /* Actual message that will be logged */
+
+/*
+ * Message Types
+ */
+#define ASL_TYPE_MSG 0
+#define ASL_TYPE_QUERY 1
+
+/* Macros to create bitmasks for filter settings - see asl_set_filter */
+#define ASL_FILTER_MASK(level) (1 << (level))
+#define ASL_FILTER_MASK_UPTO(level) ((1 << ((level) + 1)) - 1)
+
+/* Individual filter masks */
+#define ASL_FILTER_MASK_EMERG 0x01
+#define ASL_FILTER_MASK_ALERT 0x02
+#define ASL_FILTER_MASK_CRIT 0x04
+#define ASL_FILTER_MASK_ERR 0x08
+#define ASL_FILTER_MASK_WARNING 0x10
+#define ASL_FILTER_MASK_NOTICE 0x20
+#define ASL_FILTER_MASK_INFO 0x40
+#define ASL_FILTER_MASK_DEBUG 0x80
+
+/* Options to asl_open */
+#define ASL_OPT_STDERR 0x00000001
+#define ASL_OPT_NO_DELAY 0x00000002
+#define ASL_OPT_NO_REMOTE 0x00000004
+
+__BEGIN_DECLS
+
+/*
+ * asl_open: initialize a syslog connection
+ * This call is optional in most cases. The library will perform any
+ * necessary initializations on the fly. A call to asl_open() is required
+ * if optional settings must be made before messages are sent to the server.
+ * These include setting the client filter and managing additional output
+ * file descriptors. Note that the default setting of the client filter is
+ * ASL_FILTER_MASK_UPTO(ASL_LEVEL_NOTICE), so ASL_LEVEL_DEBUG and ASL_LEVEL_INFO
+ * messages are not sent to the server by default.
+ *
+ * Options (defined above) may be set using the opts parameter. They are:
+ * ASL_OPT_STDERR - adds stderr as an output file descriptor
+ * ASL_OPT_NO_DELAY - connects to the server immediately
+ * ASL_OPT_NO_REMOTE - disables the remote-control mechanism for adjusting
+ * filter levers for processes using e.g. syslog -c ...
+ */
+aslclient asl_open(const char *ident, const char *facility, uint32_t opts);
+
+/*
+ * Shuts down the current connection to the server.
+ */
+void asl_close(aslclient asl);
+
+/*
+ * asl_add_file: write log messages to the given file descriptor
+ * Log messages will be written to this file as well as to the server.
+ */
+int asl_add_log_file(aslclient asl, int fd);
+
+/*
+ * asl_remove_file: stop writing log messages to the given file descriptor
+ * The file descripter is not closed by this routine.
+ */
+int asl_remove_log_file(aslclient asl, int fd);
+
+/*
+ * Set a filter for messages being sent to the server
+ * The filter is a bitmask representing priorities. The ASL_FILTER_MASK
+ * macro may be used to convert a priority level into a bitmask for that
+ * level. The ASL_FILTER_MASK_UPTO macro creates a bitmask for all
+ * priorities up to and including a given priority.
+ * Messages with priority levels that do not have a corresponding bit
+ * set in the filter are not sent to the server, although they will be
+ * sent to any file descripters added with asl_add_log_file().
+ * The default setting is ASL_FILTER_MASK_UPTO(ASL_LEVEL_NOTICE).
+ */
+int asl_set_filter(aslclient asl, int f);
+
+/*
+ * asl_key: examine attribute keys
+ * returns the key of the nth attribute in a message (beginning at zero)
+ * returns NULL if the message has fewer attributes
+ */
+const char *asl_key(aslmsg msg, uint32_t n);
+
+/*
+ * asl_new: create a new log message.
+ */
+aslmsg asl_new(uint32_t type);
+
+/*
+ * asl_set: set attributes of a message
+ * msg: an aslmsg
+ * key: attribute key
+ * value: attribute value
+ * returns 0 for success, non-zero for failure
+ */
+int asl_set(aslmsg msg, const char *key, const char *value);
+
+/*
+ * asl_unset: remove attributes of a message
+ * msg: an aslmsg
+ * key: attribute key
+ * returns 0 for success, non-zero for failure
+ */
+int asl_unset(aslmsg msg, const char *key);
+
+/*
+ * asl_get: get attribute values from a message
+ * msg: an aslmsg
+ * key: attribute key
+ * returns the attribute value
+ * returns NULL if the message does not contain the key
+ */
+const char *asl_get(aslmsg msg, const char *key);
+
+/*
+ * asl_log: log a message with a particular log level
+ * msg: an aslmsg
+ * msg may be NULL, in which case a new message will be
+ * created and sent using default attributes.
+ * level: the log level
+ * format: A formating string followed by a list of arguments, like printf()
+ * returns 0 for success, non-zero for failure
+ */
+#ifdef __DARWIN_LDBL_COMPAT
+int asl_log(aslclient asl, aslmsg msg, int level, const char *format, ...) __DARWIN_LDBL_COMPAT(asl_log);
+#else
+int asl_log(aslclient asl, aslmsg msg, int level, const char *format, ...);
+#endif
+
+/*
+ * asl_vlog: Similar to asl_log, but taking a va_list instead of a list of
+ * arguments.
+ * msg: an aslmsg
+ * msg may be NULL, in which case a new message will be
+ * created and sent using default attributes.
+ * level: the log level of the associated message
+ * format: A formating string followed by a list of arguments, like vprintf()
+ * returns 0 for success, non-zero for failure
+ */
+#ifdef __DARWIN_LDBL_COMPAT
+int asl_vlog(aslclient asl, aslmsg msg, int level, const char *format, va_list ap) __DARWIN_LDBL_COMPAT(asl_vlog);
+#else
+int asl_vlog(aslclient asl, aslmsg msg, int level, const char *format, va_list ap);
+#endif
+
+/*
+ * asl_send: send a message
+ * This routine may be used instead of asl_log() or asl_vlog() if asl_set()
+ * has been used to set all of a message's attributes.
+ * msg: an aslmsg
+ * returns 0 for success, non-zero for failure
+ */
+int asl_send(aslclient asl, aslmsg msg);
+
+/*
+ * asl_free: free a message
+ * msg: an aslmsg to free
+ */
+void asl_free(aslmsg msg);
+
+/*
+ * asl_set_query: set arbitrary parameters of a query
+ * Similar to als_set, but allows richer query operations.
+ * See ASL_QUERY_OP_* above.
+ * msg: an aslmsg
+ * key: attribute key
+ * value: attribute value
+ * op: an operation from the set above.
+ * returns 0 for success, non-zero for failure
+ */
+int asl_set_query(aslmsg msg, const char *key, const char *value, uint32_t op);
+
+/*
+ * asl_search: Search for messages matching the criteria described
+ * by the aslmsg . The caller should set the attributes to match using
+ * asl_set_query() or asl_set(). The operatoin ASL_QUERY_OP_EQUAL is
+ * used for attributes set with asl_set().
+ * a: an aslmsg
+ * returns: a set of messages that can be iterated over using aslresp_next(),
+ * and the values can be retrieved using aslresp_get.
+ */
+aslresponse asl_search(aslclient asl, aslmsg msg);
+
+/*
+ * aslresponse_next: Iterate over responses returned from asl_search()
+ * a: a response returned from asl_search();
+ * returns: The next log message (an aslmsg) or NULL on failure
+ */
+aslmsg aslresponse_next(aslresponse r);
+
+/*
+ * aslresponse_free: Free a response returned from asl_search()
+ * a: a response returned from asl_search()
+ */
+void aslresponse_free(aslresponse a);
+
+__END_DECLS
+
+#endif /* __ASL_H__ */
--- /dev/null
+/*-
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ *
+ * @(#)assert.h 8.2 (Berkeley) 1/21/94
+ * $FreeBSD: src/include/assert.h,v 1.4 2002/03/23 17:24:53 imp Exp $
+ */
+
+#include <sys/cdefs.h>
+#ifdef __cplusplus
+#include <stdlib.h>
+#endif /* __cplusplus */
+
+/*
+ * Unlike other ANSI header files, <assert.h> may usefully be included
+ * multiple times, with and without NDEBUG defined.
+ */
+
+#undef assert
+#undef __assert
+
+#ifdef NDEBUG
+#define assert(e) ((void)0)
+#else
+
+#ifndef __GNUC__
+
+__BEGIN_DECLS
+#ifndef __cplusplus
+void abort(void) __dead2;
+#endif /* !__cplusplus */
+int printf(const char * __restrict, ...);
+__END_DECLS
+
+#define assert(e) \
+ ((void) ((e) ? 0 : __assert (#e, __FILE__, __LINE__)))
+#define __assert(e, file, line) \
+ (printf ("%s:%u: failed assertion `%s'\n", file, line, e), abort (), 0)
+
+#else /* __GNUC__ */
+
+__BEGIN_DECLS
+void __assert_rtn(const char *, const char *, int, const char *) __dead2;
+void __eprintf(const char *, const char *, unsigned, const char *) __dead2;
+__END_DECLS
+
+#define __assert(e, file, line) \
+ (__eprintf ("%s:%u: failed assertion `%s'\n", file, line, e), 0)
+
+#if __DARWIN_UNIX03
+#define assert(e) \
+ (__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __FILE__, __LINE__, #e) : (void)0)
+#else /* !__DARWIN_UNIX03 */
+#define assert(e) \
+ ((void) (__builtin_expect(!(e), 0) ? __assert (#e, __FILE__, __LINE__) : 0))
+#endif /* __DARWIN_UNIX03 */
+
+#endif /* __GNUC__ */
+#endif /* NDEBUG */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* @(#)ctype.h 8.4 (Berkeley) 1/21/94
*/
+//Begin-Libc
+#include "xlocale_private.h"
+//End-Libc
#ifndef _CTYPE_H_
#define _CTYPE_H_
#define _CTYPE_SW1 0x40000000L /* 1 width character */
#define _CTYPE_SW2 0x80000000L /* 2 width character */
#define _CTYPE_SW3 0xc0000000L /* 3 width character */
+#define _CTYPE_SWM 0xe0000000L /* Mask for screen width data */
+#define _CTYPE_SWS 30 /* Bits to shift to get width */
+#ifdef _NONSTD_SOURCE
/*
* Backward compatibility
*/
#define _SW1 _CTYPE_SW1 /* 1 width character */
#define _SW2 _CTYPE_SW2 /* 2 width character */
#define _SW3 _CTYPE_SW3 /* 3 width character */
+#endif /* _NONSTD_SOURCE */
__BEGIN_DECLS
int isalnum(int);
int isxdigit(int);
int tolower(int);
int toupper(int);
+int isascii(int);
+int toascii(int);
-#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE)
int _tolower(int);
int _toupper(int);
int digittoint(int);
-int isascii(int);
int ishexnumber(int);
int isideogram(int);
int isnumber(int);
int isphonogram(int);
int isrune(int);
int isspecial(int);
-int toascii(int);
#endif
__END_DECLS
#define tolower(c) __tolower(c)
#define toupper(c) __toupper(c)
-#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
#define _tolower(c) __tolower(c)
#define _toupper(c) __toupper(c)
+
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE)
#define digittoint(c) __maskrune((c), 0xFF)
#define isascii(c) (((c) & ~0x7F) == 0)
#define ishexnumber(c) __istype((c), _CTYPE_X)
#define toascii(c) ((c) & 0x7F)
#endif
-/* See comments in <machine/ansi.h> about _BSD_RUNE_T_. */
+/* See comments in <machine/_type.h> about __darwin_ct_rune_t. */
__BEGIN_DECLS
-unsigned long ___runetype(_BSD_CT_RUNE_T_);
-_BSD_CT_RUNE_T_ ___tolower(_BSD_CT_RUNE_T_);
-_BSD_CT_RUNE_T_ ___toupper(_BSD_CT_RUNE_T_);
+unsigned long ___runetype(__darwin_ct_rune_t);
+__darwin_ct_rune_t ___tolower(__darwin_ct_rune_t);
+__darwin_ct_rune_t ___toupper(__darwin_ct_rune_t);
__END_DECLS
/*
#if !defined(_DONT_USE_CTYPE_INLINE_) && \
(defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
+#ifdef USE_ASCII
static __inline int
-__maskrune(_BSD_CT_RUNE_T_ _c, unsigned long _f)
+__maskrune(__darwin_ct_rune_t _c, unsigned long _f)
+{
+ return _CurrentRuneLocale->__runetype[_c && 0xff] & _f;
+}
+//Begin-Libc
+#elif defined(__LIBC__)
+static __inline int
+__maskrune(__darwin_ct_rune_t _c, unsigned long _f)
{
-#ifdef USE_ASCII
- return _CurrentRuneLocale->runetype[_c && 0xff] & _f;
-#else /* USE_ASCII */
return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) :
- _CurrentRuneLocale->runetype[_c]) & _f;
-#endif /* USE_ASCII */
+ __current_locale()->__lc_ctype->_CurrentRuneLocale.__runetype[_c]) & _f;
}
+//End-Libc
+#else /* !USE_ASCII */
+__BEGIN_DECLS
+int __maskrune(__darwin_ct_rune_t, unsigned long);
+__END_DECLS
+#endif /* USE_ASCII */
static __inline int
-__istype(_BSD_CT_RUNE_T_ c, unsigned long f)
+__istype(__darwin_ct_rune_t _c, unsigned long _f)
{
- return !!(__maskrune(c, f));
+#ifdef USE_ASCII
+ return !!(__maskrune(_c, _f));
+#else /* USE_ASCII */
+ return !!(isascii(_c) ? (_DefaultRuneLocale.__runetype[_c] & _f)
+ : __maskrune(_c, _f));
+#endif /* USE_ASCII */
}
-static __inline _BSD_CT_RUNE_T_
-__isctype(_BSD_CT_RUNE_T_ _c, unsigned long _f)
+static __inline __darwin_ct_rune_t
+__isctype(__darwin_ct_rune_t _c, unsigned long _f)
{
#ifdef USE_ASCII
- return !!(_DefaultRuneLocale.runetype[_c & 0xff] & _f);
+ return !!(_DefaultRuneLocale.__runetype[_c & 0xff] & _f);
#else /* USE_ASCII */
return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
- !!(_DefaultRuneLocale.runetype[_c] & _f);
+ !!(_DefaultRuneLocale.__runetype[_c] & _f);
#endif /* USE_ASCII */
}
-static __inline _BSD_CT_RUNE_T_
-__toupper(_BSD_CT_RUNE_T_ _c)
-{
#ifdef USE_ASCII
- return _CurrentRuneLocale->mapupper[_c & 0xff];
-#else /* USE_ASCII */
+static __inline __darwin_ct_rune_t
+__toupper(__darwin_ct_rune_t _c)
+{
+ return _CurrentRuneLocale->__mapupper[_c & 0xff];
+}
+
+static __inline __darwin_ct_rune_t
+__tolower(__darwin_ct_rune_t _c)
+{
+ return _CurrentRuneLocale->__maplower[_c & 0xff];
+}
+//Begin-Libc
+#elif defined(__LIBC__)
+/*
+ * We can't do what we do for __toupper_l() (check for ASCII first, then call
+ * ___toupper_l() otherwise) because versions of ___toupper() before Tiger
+ * assume c >= _CACHED_RUNES. So we are stuck making __toupper() a routine
+ * to hide the extended locale details, outside of Libc.
+ */
+static __inline __darwin_ct_rune_t
+__toupper(__darwin_ct_rune_t _c)
+{
return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) :
- _CurrentRuneLocale->mapupper[_c];
-#endif /* USE_ASCII */
+ __current_locale()->__lc_ctype->_CurrentRuneLocale.__mapupper[_c];
}
-static __inline _BSD_CT_RUNE_T_
-__tolower(_BSD_CT_RUNE_T_ _c)
+static __inline __darwin_ct_rune_t
+__tolower(__darwin_ct_rune_t _c)
{
-#ifdef USE_ASCII
- return _CurrentRuneLocale->maplower[_c & 0xff];
-#else /* USE_ASCII */
return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :
- _CurrentRuneLocale->maplower[_c];
+ __current_locale()->__lc_ctype->_CurrentRuneLocale.__maplower[_c];
+}
+//End-Libc
+#else /* USE_ASCII */
+__BEGIN_DECLS
+__darwin_ct_rune_t __toupper(__darwin_ct_rune_t);
+__darwin_ct_rune_t __tolower(__darwin_ct_rune_t);
+__END_DECLS
#endif /* USE_ASCII */
+
+static __inline int
+__wcwidth(__darwin_ct_rune_t _c)
+{
+ unsigned int _x;
+
+ if (_c == 0)
+ return (0);
+ _x = (unsigned int)__maskrune(_c, _CTYPE_SWM|_CTYPE_R);
+ if ((_x & _CTYPE_SWM) != 0)
+ return ((_x & _CTYPE_SWM) >> _CTYPE_SWS);
+ return ((_x & _CTYPE_R) != 0 ? 1 : -1);
}
#else /* not using inlines */
__BEGIN_DECLS
-int __maskrune(_BSD_CT_RUNE_T_, unsigned long);
-int __istype (_BSD_CT_RUNE_T_, unsigned long);
-int __isctype(_BSD_CT_RUNE_T_, unsigned long);
-_BSD_CT_RUNE_T_ __toupper(_BSD_CT_RUNE_T_);
-_BSD_CT_RUNE_T_ __tolower(_BSD_CT_RUNE_T_);
+int __maskrune(__darwin_ct_rune_t, unsigned long);
+int __istype (__darwin_ct_rune_t, unsigned long);
+int __isctype(__darwin_ct_rune_t, unsigned long);
+__darwin_ct_rune_t __toupper(__darwin_ct_rune_t);
+__darwin_ct_rune_t __tolower(__darwin_ct_rune_t);
+int __wcwidth(__darwin_ct_rune_t);
__END_DECLS
#endif /* using inlines */
+#ifdef _USE_EXTENDED_LOCALES_
+#include <xlocale/_ctype.h>
+#endif /* _USE_EXTENDED_LOCALES_ */
+
#endif /* !_CTYPE_H_ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
typedef struct __db {
DBTYPE type; /* Underlying db type. */
int (*close)(struct __db *);
- int (*del)(const struct __db *, const DBT *, u_int);
- int (*get)(const struct __db *, const DBT *, DBT *, u_int);
- int (*put)(const struct __db *, DBT *, const DBT *, u_int);
- int (*seq)(const struct __db *, DBT *, DBT *, u_int);
- int (*sync)(const struct __db *, u_int);
+ int (*del)(const struct __db *, const DBT *, unsigned int);
+ int (*get)(const struct __db *, const DBT *, DBT *, unsigned int);
+ int (*put)(const struct __db *, DBT *, const DBT *, unsigned int);
+ int (*seq)(const struct __db *, DBT *, DBT *, unsigned int);
+ int (*sync)(const struct __db *, unsigned int);
void *internal; /* Access method private. */
int (*fd)(const struct __db *);
} DB;
/* Structure used to pass parameters to the btree routines. */
typedef struct {
#define R_DUP 0x01 /* duplicate keys */
- u_long flags;
- u_int cachesize; /* bytes to cache */
- int maxkeypage; /* maximum keys per page */
- int minkeypage; /* minimum keys per page */
- u_int psize; /* page size */
- int (*compare) /* comparison function */
- (const DBT *, const DBT *);
- size_t (*prefix) /* prefix function */
- (const DBT *, const DBT *);
- int lorder; /* byte order */
+ unsigned long flags;
+ unsigned int cachesize; /* bytes to cache */
+ int maxkeypage; /* maximum keys per page */
+ int minkeypage; /* minimum keys per page */
+ unsigned int psize; /* page size */
+ int (*compare) /* comparison function */
+ (const DBT *, const DBT *);
+ size_t (*prefix) /* prefix function */
+ (const DBT *, const DBT *);
+ int lorder; /* byte order */
} BTREEINFO;
#define HASHMAGIC 0x061561
/* Structure used to pass parameters to the hashing routines. */
typedef struct {
- u_int bsize; /* bucket size */
- u_int ffactor; /* fill factor */
- u_int nelem; /* number of elements */
- u_int cachesize; /* bytes to cache */
+ unsigned int bsize; /* bucket size */
+ unsigned int ffactor; /* fill factor */
+ unsigned int nelem; /* number of elements */
+ unsigned int cachesize; /* bytes to cache */
u_int32_t /* hash function */
(*hash)(const void *, size_t);
int lorder; /* byte order */
#define R_FIXEDLEN 0x01 /* fixed-length records */
#define R_NOKEY 0x02 /* key not required */
#define R_SNAPSHOT 0x04 /* snapshot the input */
- u_long flags;
- u_int cachesize; /* bytes to cache */
- u_int psize; /* page size */
- int lorder; /* byte order */
- size_t reclen; /* record length (fixed-length records) */
- u_char bval; /* delimiting byte (variable-length records */
+ unsigned long flags;
+ unsigned int cachesize; /* bytes to cache */
+ unsigned int psize; /* page size */
+ int lorder; /* byte order */
+ size_t reclen; /* record length (fixed-length records) */
+ unsigned char bval; /* delimiting byte (variable-length records */
char *bfname; /* btree file name */
} RECNOINFO;
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#include <_types.h>
#include <sys/dirent.h>
-#ifdef _POSIX_SOURCE
-typedef void * DIR;
-#else
-#include <sys/types.h>
-
-/* definitions for library routines operating on directories. */
-#define DIRBLKSIZ 1024
-
-struct _telldir; /* see telldir.h */
+struct _telldir; /* forward reference */
/* structure describing an open directory. */
-typedef struct _dirdesc {
+typedef struct {
int dd_fd; /* file descriptor associated with directory */
long dd_loc; /* offset in current buffer */
long dd_size; /* amount of data returned by getdirentries */
long dd_seek; /* magic cookie returned by getdirentries */
long dd_rewind; /* magic cookie for rewinding */
int dd_flags; /* flags for readdir */
- pthread_mutex_t dd_lock; /* for thread locking */
+ __darwin_pthread_mutex_t dd_lock; /* for thread locking */
struct _telldir *dd_td; /* telldir position recording */
} DIR;
+#ifndef _POSIX_C_SOURCE
+/* definitions for library routines operating on directories. */
+#define DIRBLKSIZ 1024
+
#define dirfd(dirp) ((dirp)->dd_fd)
/* flags for opendir2 */
#define DTF_REWIND 0x0004 /* rewind after reading union stack */
#define __DTF_READALL 0x0008 /* everything has been read */
-#ifndef NULL
-#define NULL __OSX_NULL
-#endif /* ! NULL */
-
-#endif /* ! _POSIX_SOURCE */
+#endif /* ! _POSIX_C_SOURCE */
#ifndef KERNEL
#include <sys/cdefs.h>
__BEGIN_DECLS
-#ifndef _POSIX_SOURCE
+#ifndef _POSIX_C_SOURCE
int alphasort(const void *, const void *);
#endif /* not POSIX */
-int closedir(DIR *);
-#ifndef _POSIX_SOURCE
+int closedir(DIR *) __DARWIN_ALIAS(closedir);
+#ifndef _POSIX_C_SOURCE
int getdirentries(int, char *, int, long *);
#endif /* not POSIX */
-DIR *opendir(const char *);
-#ifndef _POSIX_SOURCE
-DIR *__opendir2(const char *, int);
+DIR *opendir(const char *) __DARWIN_ALIAS(opendir);
+#ifndef _POSIX_C_SOURCE
+DIR *__opendir2(const char *, int) __DARWIN_ALIAS(__opendir2);
#endif /* not POSIX */
struct dirent *readdir(DIR *);
int readdir_r(DIR *, struct dirent *, struct dirent **);
-void rewinddir(DIR *);
-#ifndef _POSIX_SOURCE
+void rewinddir(DIR *) __DARWIN_ALIAS(rewinddir);
+#ifndef _POSIX_C_SOURCE
int scandir(const char *, struct dirent ***,
int (*)(struct dirent *), int (*)(const void *, const void *));
#endif /* not POSIX */
-void seekdir(DIR *, long);
-long telldir(DIR *);
+void seekdir(DIR *, long) __DARWIN_ALIAS(seekdir);
+long telldir(DIR *) __DARWIN_ALIAS(telldir);
__END_DECLS
#endif /* !KERNEL */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* places (<machine/varargs.h> and <machine/stdarg.h>), so if we include one
* of them here we may collide with the utility's includes. It's unreasonable
* for utilities to have to include one of them to include err.h, so we get
- * _BSD_VA_LIST_ from <machine/ansi.h> and use it.
+ * __darwin_va_list from <machine/_type.h> and use it.
*/
-#include <machine/ansi.h>
#include <sys/cdefs.h>
+#include <_types.h>
__BEGIN_DECLS
-void err(int, const char *, ...) __dead2;
-void verr(int, const char *, _BSD_VA_LIST_) __dead2;
-void errc(int, int, const char *, ...) __dead2;
-void verrc(int, int, const char *, _BSD_VA_LIST_) __dead2;
-void errx(int, const char *, ...) __dead2;
-void verrx(int, const char *, _BSD_VA_LIST_) __dead2;
-void warn(const char *, ...);
-void vwarn(const char *, _BSD_VA_LIST_);
-void warnc(int, const char *, ...);
-void vwarnc(int, const char *, _BSD_VA_LIST_);
-void warnx(const char *, ...);
-void vwarnx(const char *, _BSD_VA_LIST_);
+void err(int, const char *, ...) __DARWIN_LDBL_COMPAT(err) __dead2;
+void verr(int, const char *, __darwin_va_list) __DARWIN_LDBL_COMPAT(verr) __dead2;
+void errc(int, int, const char *, ...) __DARWIN_LDBL_COMPAT(errc) __dead2;
+void verrc(int, int, const char *, __darwin_va_list) __DARWIN_LDBL_COMPAT(verrc) __dead2;
+void errx(int, const char *, ...) __DARWIN_LDBL_COMPAT(errx) __dead2;
+void verrx(int, const char *, __darwin_va_list) __DARWIN_LDBL_COMPAT(verrx) __dead2;
+void warn(const char *, ...) __DARWIN_LDBL_COMPAT(warn);
+void vwarn(const char *, __darwin_va_list) __DARWIN_LDBL_COMPAT(vwarn);
+void warnc(int, const char *, ...) __DARWIN_LDBL_COMPAT(warnc);
+void vwarnc(int, const char *, __darwin_va_list) __DARWIN_LDBL_COMPAT(vwarnc);
+void warnx(const char *, ...) __DARWIN_LDBL_COMPAT(warnx);
+void vwarnx(const char *, __darwin_va_list) __DARWIN_LDBL_COMPAT(vwarnx);
void err_set_file(void *);
void err_set_exit(void (*)(int));
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+/* This file exists soley to keep Metrowerks' compilers happy. The version
+ used by GCC can be found in /usr/lib/gcc, although it's
+ not very informative. */
+
+#ifndef _FLOAT_H_
+
+#if defined(__GNUC__)
+#include_next <float.h>
+
+#elif defined(__MWERKS__)
+#define _FLOAT_H_
+
+/* APPLE LOCAL begin MW compatibility */
+/* Define various characteristics of floating-point types, if needed. */
+#ifndef __FLT_RADIX__
+#define __FLT_RADIX__ 2
+#endif
+#ifndef __FLT_MANT_DIG__
+#define __FLT_MANT_DIG__ 24
+#endif
+#ifndef __FLT_DIG__
+#define __FLT_DIG__ 6
+#endif
+#ifndef __FLT_EPSILON__
+#define __FLT_EPSILON__ 1.19209290e-07F
+#endif
+#ifndef __FLT_MIN__
+#define __FLT_MIN__ 1.17549435e-38F
+#endif
+#ifndef __FLT_MAX__
+#define __FLT_MAX__ 3.40282347e+38F
+#endif
+#ifndef __FLT_MIN_EXP__
+#define __FLT_MIN_EXP__ (-125)
+#endif
+#ifndef __FLT_MIN_10_EXP__
+#define __FLT_MIN_10_EXP__ (-37)
+#endif
+#ifndef __FLT_MAX_EXP__
+#define __FLT_MAX_EXP__ 128
+#endif
+#ifndef __FLT_MAX_10_EXP__
+#define __FLT_MAX_10_EXP__ 38
+#endif
+#ifndef __DBL_MANT_DIG__
+#define __DBL_MANT_DIG__ 53
+#endif
+#ifndef __DBL_DIG__
+#define __DBL_DIG__ 15
+#endif
+#ifndef __DBL_EPSILON__
+#define __DBL_EPSILON__ 2.2204460492503131e-16
+#endif
+#ifndef __DBL_MIN__
+#define __DBL_MIN__ 2.2250738585072014e-308
+#endif
+#ifndef __DBL_MAX__
+#define __DBL_MAX__ 1.7976931348623157e+308
+#endif
+#ifndef __DBL_MIN_EXP__
+#define __DBL_MIN_EXP__ (-1021)
+#endif
+#ifndef __DBL_MIN_10_EXP__
+#define __DBL_MIN_10_EXP__ (-307)
+#endif
+#ifndef __DBL_MAX_EXP__
+#define __DBL_MAX_EXP__ 1024
+#endif
+#ifndef __DBL_MAX_10_EXP__
+#define __DBL_MAX_10_EXP__ 308
+#endif
+#ifndef __LDBL_MANT_DIG__
+#define __LDBL_MANT_DIG__ 53
+#endif
+#ifndef __LDBL_DIG__
+#define __LDBL_DIG__ 15
+#endif
+#ifndef __LDBL_EPSILON__
+#define __LDBL_EPSILON__ 2.2204460492503131e-16
+#endif
+#ifndef __LDBL_MIN__
+#define __LDBL_MIN__ 2.2250738585072014e-308
+#endif
+#ifndef __LDBL_MAX__
+#define __LDBL_MAX__ 1.7976931348623157e+308
+#endif
+#ifndef __LDBL_MIN_EXP__
+#define __LDBL_MIN_EXP__ (-1021)
+#endif
+#ifndef __LDBL_MIN_10_EXP__
+#define __LDBL_MIN_10_EXP__ (-307)
+#endif
+#ifndef __LDBL_MAX_EXP__
+#define __LDBL_MAX_EXP__ 1024
+#endif
+#ifndef __LDBL_MAX_10_EXP__
+#define __LDBL_MAX_10_EXP__ 308
+#endif
+/* APPLE LOCAl end MW compatibility */
+
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU CC.
+
+GNU CC 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 2, or (at your option)
+any later version.
+
+GNU CC 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.
+
+You should have received a copy of the GNU General Public License
+along with GNU CC; see the file COPYING. If not, write to
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA. */
+
+/* As a special exception, if you include this header file into source
+ files compiled by GCC, this header file does not by itself cause
+ the resulting executable to be covered by the GNU General Public
+ License. This exception does not however invalidate any other
+ reasons why the executable file might be covered by the GNU General
+ Public License. */
+
+/*
+ * ISO C Standard: 5.2.4.2.2 Characteristics of floating types <float.h>
+ */
+
+
+/* Radix of exponent representation, b. */
+#undef FLT_RADIX
+#define FLT_RADIX __FLT_RADIX__
+
+/* Number of base-FLT_RADIX digits in the significand, p. */
+#undef FLT_MANT_DIG
+#undef DBL_MANT_DIG
+#undef LDBL_MANT_DIG
+#define FLT_MANT_DIG __FLT_MANT_DIG__
+#define DBL_MANT_DIG __DBL_MANT_DIG__
+#define LDBL_MANT_DIG __LDBL_MANT_DIG__
+
+/* Number of decimal digits, q, such that any floating-point number with q
+ decimal digits can be rounded into a floating-point number with p radix b
+ digits and back again without change to the q decimal digits,
+
+ p * log10(b) if b is a power of 10
+ floor((p - 1) * log10(b)) otherwise
+*/
+#undef FLT_DIG
+#undef DBL_DIG
+#undef LDBL_DIG
+#define FLT_DIG __FLT_DIG__
+#define DBL_DIG __DBL_DIG__
+#define LDBL_DIG __LDBL_DIG__
+
+/* Minimum int x such that FLT_RADIX**(x-1) is a normalized float, emin */
+#undef FLT_MIN_EXP
+#undef DBL_MIN_EXP
+#undef LDBL_MIN_EXP
+#define FLT_MIN_EXP __FLT_MIN_EXP__
+#define DBL_MIN_EXP __DBL_MIN_EXP__
+#define LDBL_MIN_EXP __LDBL_MIN_EXP__
+
+/* Minimum negative integer such that 10 raised to that power is in the
+ range of normalized floating-point numbers,
+
+ ceil(log10(b) * (emin - 1))
+*/
+#undef FLT_MIN_10_EXP
+#undef DBL_MIN_10_EXP
+#undef LDBL_MIN_10_EXP
+#define FLT_MIN_10_EXP __FLT_MIN_10_EXP__
+#define DBL_MIN_10_EXP __DBL_MIN_10_EXP__
+#define LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__
+
+/* Maximum int x such that FLT_RADIX**(x-1) is a representable float, emax. */
+#undef FLT_MAX_EXP
+#undef DBL_MAX_EXP
+#undef LDBL_MAX_EXP
+#define FLT_MAX_EXP __FLT_MAX_EXP__
+#define DBL_MAX_EXP __DBL_MAX_EXP__
+#define LDBL_MAX_EXP __LDBL_MAX_EXP__
+
+/* Maximum integer such that 10 raised to that power is in the range of
+ representable finite floating-point numbers,
+
+ floor(log10((1 - b**-p) * b**emax))
+*/
+#undef FLT_MAX_10_EXP
+#undef DBL_MAX_10_EXP
+#undef LDBL_MAX_10_EXP
+#define FLT_MAX_10_EXP __FLT_MAX_10_EXP__
+#define DBL_MAX_10_EXP __DBL_MAX_10_EXP__
+#define LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__
+
+/* Maximum representable finite floating-point number,
+
+ (1 - b**-p) * b**emax
+*/
+#undef FLT_MAX
+#undef DBL_MAX
+#undef LDBL_MAX
+#define FLT_MAX __FLT_MAX__
+#define DBL_MAX __DBL_MAX__
+#define LDBL_MAX __LDBL_MAX__
+
+/* The difference between 1 and the least value greater than 1 that is
+ representable in the given floating point type, b**1-p. */
+#undef FLT_EPSILON
+#undef DBL_EPSILON
+#undef LDBL_EPSILON
+#define FLT_EPSILON __FLT_EPSILON__
+#define DBL_EPSILON __DBL_EPSILON__
+#define LDBL_EPSILON __LDBL_EPSILON__
+
+/* Minimum normalized positive floating-point number, b**(emin - 1). */
+#undef FLT_MIN
+#undef DBL_MIN
+#undef LDBL_MIN
+#define FLT_MIN __FLT_MIN__
+#define DBL_MIN __DBL_MIN__
+#define LDBL_MIN __LDBL_MIN__
+
+/* Addition rounds to 0: zero, 1: nearest, 2: +inf, 3: -inf, -1: unknown. */
+/* ??? This is supposed to change with calls to fesetround in <fenv.h>. */
+#undef FLT_ROUNDS
+#define FLT_ROUNDS 1
+
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+/* The floating-point expression evaluation method.
+ -1 indeterminate
+ 0 evaluate all operations and constants just to the range and
+ precision of the type
+ 1 evaluate operations and constants of type float and double
+ to the range and precision of the double type, evaluate
+ long double operations and constants to the range and
+ precision of the long double type
+ 2 evaluate all operations and constants to the range and
+ precision of the long double type
+
+ ??? This ought to change with the setting of the fp control word;
+ the value provided by the compiler assumes the widest setting. */
+#undef FLT_EVAL_METHOD
+#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
+
+/* Number of decimal digits, n, such that any floating-point number in the
+ widest supported floating type with pmax radix b digits can be rounded
+ to a floating-point number with n decimal digits and back again without
+ change to the value,
+
+ pmax * log10(b) if b is a power of 10
+ ceil(1 + pmax * log10(b)) otherwise
+*/
+#undef DECIMAL_DIG
+#define DECIMAL_DIG __DECIMAL_DIG__
+
+#endif /* C99 */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern int __fegetfltrounds( void );
+#ifdef __cplusplus
+}
+#endif
+#undef FLT_ROUNDS
+#define FLT_ROUNDS (__fegetfltrounds ())
+/* End of GNU CC file */
+
+/* APPLE LOCAL begin CW compatibility */
+/* CodeWarrior defines the following on its own. */
+#undef DECIMAL_DIG
+/* APPLE LOCAL end CW compatibility */
+
+#else
+#error This file is only for Metrowerks compatibilty.
+#endif
+
+#endif /* _FLOAT_H_ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#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. */
-#define FNM_NOSYS (-1) /* Reserved */
+#define FNM_NOSYS (-1) /* Reserved. */
-#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
-#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
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE)
+#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
-#ifndef _POSIX_SOURCE
int fnmatch(const char *, const char *, int);
-#endif
__END_DECLS
#endif /* !_FNMATCH_H_ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
char *fts_path; /* root path */
int fts_errno; /* errno for this node */
int fts_symfd; /* fd for symlink */
- u_short fts_pathlen; /* strlen(fts_path) */
- u_short fts_namelen; /* strlen(fts_name) */
+ unsigned short fts_pathlen; /* strlen(fts_path) */
+ unsigned short fts_namelen; /* strlen(fts_name) */
ino_t fts_ino; /* inode */
dev_t fts_dev; /* device */
#define FTS_SL 12 /* symbolic link */
#define FTS_SLNONE 13 /* symbolic link without target */
#define FTS_W 14 /* whiteout object */
- u_short fts_info; /* user flags for FTSENT structure */
+ unsigned short fts_info; /* user flags for FTSENT structure */
#define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */
#define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */
#define FTS_ISW 0x04 /* this is a whiteout object */
- u_short fts_flags; /* private flags for FTSENT structure */
+ unsigned short fts_flags; /* private flags for FTSENT structure */
#define FTS_AGAIN 1 /* read node again */
#define FTS_FOLLOW 2 /* follow symbolic link */
#define FTS_NOINSTR 3 /* no instructions */
#define FTS_SKIP 4 /* discard node */
- u_short fts_instr; /* fts_set() instructions */
+ unsigned short fts_instr; /* fts_set() instructions */
struct stat *fts_statp; /* stat(2) information */
char fts_name[1]; /* file name */
#ifndef _FTW_H
#define _FTW_H
-#include <sys/types.h>
#include <sys/stat.h>
/*
};
__BEGIN_DECLS
-int ftw(const char *, int (*)(const char *, const struct stat *, int), int);
+int ftw(const char *, int (*)(const char *, const struct stat *, int), int)
+ __DARWIN_ALIAS(ftw);
int nftw(const char *, int (*)(const char *, const struct stat *, int,
- struct FTW *), int, int);
+ struct FTW *), int, int) __DARWIN_ALIAS(nftw);
__END_DECLS
#endif /* !_FTW_H */
+/* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */
+/* $FreeBSD: src/include/getopt.h,v 1.6 2004/02/24 08:09:20 ache Exp $ */
+
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
#include <unistd.h>
/*
- * Gnu like getopt_long() and BSD4.4 getsubopt()/optreset extensions
+ * GNU-like getopt_long()/getopt_long_only() with 4.4BSD optreset extension.
+ * getopt() is declared here too for GNU programs.
*/
-#if !defined(_POSIX_SOURCE) && !defined(_XOPEN_SOURCE)
#define no_argument 0
#define required_argument 1
#define optional_argument 2
};
__BEGIN_DECLS
-int getopt_long(int, char * const *, const char *, const struct option *, int *);
-__END_DECLS
+int getopt_long(int, char * const *, const char *,
+ const struct option *, int *);
+int getopt_long_only(int, char * const *, const char *,
+ const struct option *, int *);
+#ifndef _GETOPT
+#define _GETOPT
+int getopt(int, char * const [], const char *);
+
+extern char *optarg; /* getopt(3) external variables */
+extern int optind, opterr, optopt;
#endif
+#ifndef _OPTRESET
+#define _OPTRESET
+extern int optreset; /* getopt(3) external variable */
+#endif
+__END_DECLS
#endif /* !_GETOPT_H_ */
#include <sys/cdefs.h>
#include <_types.h>
-#ifndef _BSD_SIZE_T_DEFINED_
-#define _BSD_SIZE_T_DEFINED_
-typedef __osx_size_t size_t;
+#ifndef _SIZE_T
+#define _SIZE_T
+typedef __darwin_size_t size_t;
#endif
+#ifndef _POSIX_C_SOURCE
+struct dirent;
struct stat;
+#endif /* _POSIX_C_SOURCE */
typedef struct {
size_t gl_pathc; /* Count of total paths so far. */
int gl_matchc; /* Count of paths matching pattern. */
/* Copy of errfunc parameter to glob. */
int (*gl_errfunc)(const char *, int);
+#ifndef _POSIX_C_SOURCE
/*
* Alternate filesystem access methods for glob; replacement
* versions of closedir(3), readdir(3), opendir(3), stat(2)
void *(*gl_opendir)(const char *);
int (*gl_lstat)(const char *, struct stat *);
int (*gl_stat)(const char *, struct stat *);
+#else /* _POSIX_C_SOURCE */
+ void *_gl_reserved[5];
+#endif /* _POSIX_C_SOURCE */
} glob_t;
/* Believed to have been introduced in 1003.2-1992 */
#define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK was not set. */
#define GLOB_NOSYS (-4) /* Obsolete: source comptability only. */
-#ifndef _POSIX_SOURCE
#define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */
#define GLOB_BRACE 0x0080 /* Expand braces ala csh. */
#define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */
/* source compatibility, these are the old names */
#define GLOB_MAXPATH GLOB_LIMIT
#define GLOB_ABEND GLOB_ABORTED
-#endif /* ! _POSIX_SOURCE */
__BEGIN_DECLS
-int glob(const char * __restrict, int,
- int (* __restrict)(const char *, int), glob_t * __restrict);
+int glob(const char * __restrict, int, int (*)(const char *, int),
+ glob_t * __restrict);
void globfree(glob_t *);
__END_DECLS
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#ifndef _GRP_H_
#define _GRP_H_
-#include <sys/_types.h>
+#include <_types.h>
-#ifndef _GID_T_DECLARED
-typedef __gid_t gid_t; /* [XBD] */
-#define _GID_T_DECLARED
+#ifndef _GID_T
+typedef __darwin_gid_t gid_t; /* [XBD] */
+#define _GID_T
#endif
/*
* prototypes defined by [TSF] for the thread reentrant functions include
* it as a type for their 4th arguments, so we define it here.
*/
-#ifndef _BSD_SIZE_T_DEFINED_
-#define _BSD_SIZE_T_DEFINED_
-typedef __size_t size_t; /* [???] */
+#ifndef _SIZE_T
+#define _SIZE_T
+typedef __darwin_size_t size_t; /* [???] */
#endif
-#ifndef _POSIX_SOURCE
+#ifndef _POSIX_C_SOURCE
#define _PATH_GROUP "/etc/group"
#endif
int setgrent(void);
void endgrent(void);
-#ifndef _POSIX_SOURCE
+#ifndef _POSIX_C_SOURCE
#ifndef _XOPEN_SOURCE
char *group_from_gid(gid_t, int);
#endif
--- /dev/null
+/*
+ * Copyright (c) 2000, 2001, 2002, 2003, 2004 Apple Computer, Inc.
+ * All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * <inttypes.h> -- Standard C header, defined in ISO/IEC 9899:1999
+ * (aka "C99"), section 7.8. This defines format string conversion
+ * specifiers suitable for use within arguments to fprintf and fscanf
+ * and their ilk.
+ */
+
+#if !defined(_INTTYPES_H_)
+#define _INTTYPES_H_
+
+#include <sys/cdefs.h> /* For __BEGIN_DECLS and __END_DECLS */
+#include <_types.h> /* For __darwin_wchar_t */
+#include <stdint.h>
+
+#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)
+ /* Translator is not ISO/IEC 9899:1999-compliant. */
+# if !defined(restrict)
+# define restrict
+# define __RESTRICT_KEYWORD_DEFINED__
+# endif
+#endif
+
+/* "C++ implementations should define these macros only when
+ * __STDC_FORMAT_MACROS is defined before <inttypes.h> is included."
+ */
+#if (! defined(__cplusplus)) || defined(__STDC_FORMAT_MACROS)
+
+# undef __PRI_8_LENGTH_MODIFIER__
+# undef __PRI_64_LENGTH_MODIFIER__
+# undef __SCN_64_LENGTH_MODIFIER__
+
+/* These could be "hh", "ll", and "ll" respectively, but that doesn't work on
+ 10.2, and these do. Note that there's no way to use scanf to scan a
+ decimal into a 'char' argument on 10.2, so "hh" is used unconditionally
+ and programs that use it won't work on Jaguar. */
+# define __PRI_8_LENGTH_MODIFIER__ "" /* none */
+# define __PRI_64_LENGTH_MODIFIER__ "q"
+# define __SCN_64_LENGTH_MODIFIER__ "q"
+# define __PRI_MAX_LENGTH_MODIFIER__ "j"
+# define __SCN_MAX_LENGTH_MODIFIER__ "j"
+
+# define PRId8 __PRI_8_LENGTH_MODIFIER__ "d"
+# define PRIi8 __PRI_8_LENGTH_MODIFIER__ "i"
+# define PRIo8 __PRI_8_LENGTH_MODIFIER__ "o"
+# define PRIu8 __PRI_8_LENGTH_MODIFIER__ "u"
+# define PRIx8 __PRI_8_LENGTH_MODIFIER__ "x"
+# define PRIX8 __PRI_8_LENGTH_MODIFIER__ "X"
+
+# define PRId16 "hd"
+# define PRIi16 "hi"
+# define PRIo16 "ho"
+# define PRIu16 "hu"
+# define PRIx16 "hx"
+# define PRIX16 "hX"
+
+# define PRId32 "d"
+# define PRIi32 "i"
+# define PRIo32 "o"
+# define PRIu32 "u"
+# define PRIx32 "x"
+# define PRIX32 "X"
+
+# define PRId64 __PRI_64_LENGTH_MODIFIER__ "d"
+# define PRIi64 __PRI_64_LENGTH_MODIFIER__ "i"
+# define PRIo64 __PRI_64_LENGTH_MODIFIER__ "o"
+# define PRIu64 __PRI_64_LENGTH_MODIFIER__ "u"
+# define PRIx64 __PRI_64_LENGTH_MODIFIER__ "x"
+# define PRIX64 __PRI_64_LENGTH_MODIFIER__ "X"
+
+# define PRIdLEAST8 PRId8
+# define PRIiLEAST8 PRIi8
+# define PRIoLEAST8 PRIo8
+# define PRIuLEAST8 PRIu8
+# define PRIxLEAST8 PRIx8
+# define PRIXLEAST8 PRIX8
+
+# define PRIdLEAST16 PRId16
+# define PRIiLEAST16 PRIi16
+# define PRIoLEAST16 PRIo16
+# define PRIuLEAST16 PRIu16
+# define PRIxLEAST16 PRIx16
+# define PRIXLEAST16 PRIX16
+
+# define PRIdLEAST32 PRId32
+# define PRIiLEAST32 PRIi32
+# define PRIoLEAST32 PRIo32
+# define PRIuLEAST32 PRIu32
+# define PRIxLEAST32 PRIx32
+# define PRIXLEAST32 PRIX32
+
+# define PRIdLEAST64 PRId64
+# define PRIiLEAST64 PRIi64
+# define PRIoLEAST64 PRIo64
+# define PRIuLEAST64 PRIu64
+# define PRIxLEAST64 PRIx64
+# define PRIXLEAST64 PRIX64
+
+# define PRIdFAST8 PRId8
+# define PRIiFAST8 PRIi8
+# define PRIoFAST8 PRIo8
+# define PRIuFAST8 PRIu8
+# define PRIxFAST8 PRIx8
+# define PRIXFAST8 PRIX8
+
+# define PRIdFAST16 PRId16
+# define PRIiFAST16 PRIi16
+# define PRIoFAST16 PRIo16
+# define PRIuFAST16 PRIu16
+# define PRIxFAST16 PRIx16
+# define PRIXFAST16 PRIX16
+
+# define PRIdFAST32 PRId32
+# define PRIiFAST32 PRIi32
+# define PRIoFAST32 PRIo32
+# define PRIuFAST32 PRIu32
+# define PRIxFAST32 PRIx32
+# define PRIXFAST32 PRIX32
+
+# define PRIdFAST64 PRId64
+# define PRIiFAST64 PRIi64
+# define PRIoFAST64 PRIo64
+# define PRIuFAST64 PRIu64
+# define PRIxFAST64 PRIx64
+# define PRIXFAST64 PRIX64
+
+/* int32_t is 'int', but intptr_t is 'long'. */
+# define PRIdPTR "ld"
+# define PRIiPTR "li"
+# define PRIoPTR "lo"
+# define PRIuPTR "lu"
+# define PRIxPTR "lx"
+# define PRIXPTR "lX"
+
+# define PRIdMAX __PRI_MAX_LENGTH_MODIFIER__ "d"
+# define PRIiMAX __PRI_MAX_LENGTH_MODIFIER__ "i"
+# define PRIoMAX __PRI_MAX_LENGTH_MODIFIER__ "o"
+# define PRIuMAX __PRI_MAX_LENGTH_MODIFIER__ "u"
+# define PRIxMAX __PRI_MAX_LENGTH_MODIFIER__ "x"
+# define PRIXMAX __PRI_MAX_LENGTH_MODIFIER__ "X"
+
+# define SCNd8 "hhd"
+# define SCNi8 "hhi"
+# define SCNo8 "hho"
+# define SCNu8 "hhu"
+# define SCNx8 "hhx"
+
+# define SCNd16 "hd"
+# define SCNi16 "hi"
+# define SCNo16 "ho"
+# define SCNu16 "hu"
+# define SCNx16 "hx"
+
+# define SCNd32 "d"
+# define SCNi32 "i"
+# define SCNo32 "o"
+# define SCNu32 "u"
+# define SCNx32 "x"
+
+# define SCNd64 __SCN_64_LENGTH_MODIFIER__ "d"
+# define SCNi64 __SCN_64_LENGTH_MODIFIER__ "i"
+# define SCNo64 __SCN_64_LENGTH_MODIFIER__ "o"
+# define SCNu64 __SCN_64_LENGTH_MODIFIER__ "u"
+# define SCNx64 __SCN_64_LENGTH_MODIFIER__ "x"
+
+# define SCNdLEAST8 SCNd8
+# define SCNiLEAST8 SCNi8
+# define SCNoLEAST8 SCNo8
+# define SCNuLEAST8 SCNu8
+# define SCNxLEAST8 SCNx8
+
+# define SCNdLEAST16 SCNd16
+# define SCNiLEAST16 SCNi16
+# define SCNoLEAST16 SCNo16
+# define SCNuLEAST16 SCNu16
+# define SCNxLEAST16 SCNx16
+
+# define SCNdLEAST32 SCNd32
+# define SCNiLEAST32 SCNi32
+# define SCNoLEAST32 SCNo32
+# define SCNuLEAST32 SCNu32
+# define SCNxLEAST32 SCNx32
+
+# define SCNdLEAST64 SCNd64
+# define SCNiLEAST64 SCNi64
+# define SCNoLEAST64 SCNo64
+# define SCNuLEAST64 SCNu64
+# define SCNxLEAST64 SCNx64
+
+# define SCNdFAST8 SCNd8
+# define SCNiFAST8 SCNi8
+# define SCNoFAST8 SCNo8
+# define SCNuFAST8 SCNu8
+# define SCNxFAST8 SCNx8
+
+# define SCNdFAST16 SCNd16
+# define SCNiFAST16 SCNi16
+# define SCNoFAST16 SCNo16
+# define SCNuFAST16 SCNu16
+# define SCNxFAST16 SCNx16
+
+# define SCNdFAST32 SCNd32
+# define SCNiFAST32 SCNi32
+# define SCNoFAST32 SCNo32
+# define SCNuFAST32 SCNu32
+# define SCNxFAST32 SCNx32
+
+# define SCNdFAST64 SCNd64
+# define SCNiFAST64 SCNi64
+# define SCNoFAST64 SCNo64
+# define SCNuFAST64 SCNu64
+# define SCNxFAST64 SCNx64
+
+# define SCNdPTR "ld"
+# define SCNiPTR "li"
+# define SCNoPTR "lo"
+# define SCNuPTR "lu"
+# define SCNxPTR "lx"
+
+# define SCNdMAX __SCN_MAX_LENGTH_MODIFIER__ "d"
+# define SCNiMAX __SCN_MAX_LENGTH_MODIFIER__ "i"
+# define SCNoMAX __SCN_MAX_LENGTH_MODIFIER__ "o"
+# define SCNuMAX __SCN_MAX_LENGTH_MODIFIER__ "u"
+# define SCNxMAX __SCN_MAX_LENGTH_MODIFIER__ "x"
+
+#endif /* if C++, then __STDC_FORMAT_MACROS enables the above macros */
+
+__BEGIN_DECLS
+
+ /* 7.8.2.1 */
+ extern intmax_t imaxabs(intmax_t j);
+
+ /* 7.8.2.2 */
+ typedef struct {
+ intmax_t quot;
+ intmax_t rem;
+ } imaxdiv_t;
+
+ extern imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
+
+ /* 7.8.2.3 */
+ extern intmax_t strtoimax(const char * restrict nptr, char ** restrict endptr, int base);
+ extern uintmax_t strtoumax(const char * restrict nptr, char ** restrict endptr, int base);
+
+#ifndef __cplusplus /* wchar_t is a built-in type in C++ */
+# ifndef _WCHAR_T
+# define _WCHAR_T
+ typedef __darwin_wchar_t wchar_t;
+# endif /* _WCHAR_T */
+#endif /* __cplusplus */
+
+ /* 7.8.2.4 */
+ extern intmax_t wcstoimax(const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base);
+ extern uintmax_t wcstoumax(const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base);
+
+__END_DECLS
+
+#ifdef _USE_EXTENDED_LOCALES_
+#include <xlocale/_inttypes.h>
+#endif /* _USE_EXTENDED_LOCALES_ */
+
+/*
+ No need to #undef the __*_{8,64}_LENGTH_MODIFIER__ macros;
+ in fact, you can't #undef them, because later uses of any of
+ their dependents will *not* then do the intended substitution.
+ Expansion of a #define like this one:
+
+ #define x IDENT y
+
+ uses the cpp value of IDENT at the location where x is *expanded*,
+ not where it is #defined.
+*/
+
+#if defined(__RESTRICT_KEYWORD_DEFINED__)
+# undef restrict
+# undef __RESTRICT_KEYWORD_DEFINED__
+#endif
+
+#endif /* !_INTTYPES_H_ */
#ifndef _ISO646_H_
#define _ISO646_H_
+#ifndef _POSIX_C_SOURCE
+
#ifndef __cplusplus
#define and &&
#define and_eq &=
#define xor_eq ^=
#endif /* ! __cplusplus */
+#endif /* ! _POSIX_C_SOURCE */
+
#endif /* !_ISO646_H_ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#include <sys/cdefs.h>
#include <_types.h>
-#ifndef _NL_ITEM_DECLARED
-typedef __osx_nl_item nl_item;
-#define _NL_ITEM_DECLARED
+#ifndef _NL_ITEM
+typedef __darwin_nl_item nl_item;
+#define _NL_ITEM
#endif
#define CODESET 0 /* codeset name */
#define CRNCYSTR 56 /* currency symbol */
-#if !defined(_ANSI_SOURCE)
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE)
#define D_MD_ORDER 57 /* month/day order (local extension) */
#endif
char *nl_langinfo(nl_item);
__END_DECLS
+#ifdef _USE_EXTENDED_LOCALES_
+#include <xlocale/_langinfo.h>
+#endif /* _USE_EXTENDED_LOCALES_ */
+
#endif /* !_LANGINFO_H_ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* WARNING: all addresses passed to these functions must be "naturally aligned", ie
* int32_t's must be 32-bit aligned (low 2 bits of address zero), and int64_t's
* must be 64-bit aligned (low 3 bits of address zero.)
+ *
+ * Note that some versions of the atomic functions incorporate memory barriers,
+ * and some do not. Barriers strictly order memory access on a weakly-ordered
+ * architecture such as PPC. All loads and stores executed in sequential program
+ * order before the barrier will complete before any load or store executed after
+ * the barrier. On a uniprocessor, the barrier operation is typically a nop.
+ * On a multiprocessor, the barrier can be quite expensive.
+ *
+ * Most code will want to use the barrier functions to insure that memory shared
+ * between threads is properly synchronized. For example, if you want to initialize
+ * a shared data structure and then atomically increment a variable to indicate
+ * that the initialization is complete, then you MUST use OSAtomicIncrement32Barrier()
+ * to ensure that the stores to your data structure complete before the atomic add.
+ * Likewise, the consumer of that data structure MUST use OSAtomicDecrement32Barrier(),
+ * in order to ensure that their loads of the structure are not executed before
+ * the atomic decrement. On the other hand, if you are simply incrementing a global
+ * counter, then it is safe and potentially faster to use OSAtomicIncrement32().
+ *
+ * If you are unsure which version to use, prefer the barrier variants as they are
+ * safer.
+ *
+ * The spinlock and queue operations always incorporate a barrier.
*/
__BEGIN_DECLS
-/* Arithmetic functions. They do not incorporate memory barriers and thus cannot
- * be used by themselves to synchronize shared memory. They return the new value.
- * The "or", "and", and "xor" operations are layered on top of compare-and-swap.
+
+/* Arithmetic functions. They return the new value. All the "or", "and", and "xor"
+ * operations, and the barrier forms of add, are layered on top of compare-and-swap.
*/
int32_t OSAtomicAdd32( int32_t theAmount, int32_t *theValue );
+int32_t OSAtomicAdd32Barrier( int32_t theAmount, int32_t *theValue );
+
inline static
-int32_t OSAtomicIncrement32( int32_t *theValue ) { return OSAtomicAdd32( 1, theValue); }
+int32_t OSAtomicIncrement32( int32_t *theValue )
+ { return OSAtomicAdd32( 1, theValue); }
inline static
-int32_t OSAtomicDecrement32( int32_t *theValue ) { return OSAtomicAdd32( -1, theValue); }
+int32_t OSAtomicIncrement32Barrier( int32_t *theValue )
+ { return OSAtomicAdd32Barrier( 1, theValue); }
+
+inline static
+int32_t OSAtomicDecrement32( int32_t *theValue )
+ { return OSAtomicAdd32( -1, theValue); }
+inline static
+int32_t OSAtomicDecrement32Barrier( int32_t *theValue )
+ { return OSAtomicAdd32Barrier( -1, theValue); }
+
int32_t OSAtomicOr32( uint32_t theMask, uint32_t *theValue );
+int32_t OSAtomicOr32Barrier( uint32_t theMask, uint32_t *theValue );
+
int32_t OSAtomicAnd32( uint32_t theMask, uint32_t *theValue );
+int32_t OSAtomicAnd32Barrier( uint32_t theMask, uint32_t *theValue );
+
int32_t OSAtomicXor32( uint32_t theMask, uint32_t *theValue );
+int32_t OSAtomicXor32Barrier( uint32_t theMask, uint32_t *theValue );
+
#if defined(__ppc64__) || defined(__i386__)
+
int64_t OSAtomicAdd64( int64_t theAmount, int64_t *theValue );
+int64_t OSAtomicAdd64Barrier( int64_t theAmount, int64_t *theValue );
+
+inline static
+int64_t OSAtomicIncrement64( int64_t *theValue )
+ { return OSAtomicAdd64( 1, theValue); }
+inline static
+int64_t OSAtomicIncrement64Barrier( int64_t *theValue )
+ { return OSAtomicAdd64Barrier( 1, theValue); }
+
inline static
-int64_t OSAtomicIncrement64( int64_t *theValue ) { return OSAtomicAdd64( 1, theValue); }
+int64_t OSAtomicDecrement64( int64_t *theValue )
+ { return OSAtomicAdd64( -1, theValue); }
inline static
-int64_t OSAtomicDecrement64( int64_t *theValue ) { return OSAtomicAdd64( -1, theValue); }
+int64_t OSAtomicDecrement64Barrier( int64_t *theValue )
+ { return OSAtomicAdd64Barrier( -1, theValue); }
+
#endif /* defined(__ppc64__) || defined(__i386__) */
-/* Compare and swap. They do not incorporate memory barriers and thus cannot be used
- * by themselved to synchronize shared memory. They return true if the swap occured.
+
+/* Compare and swap. They return true if the swap occured.
*/
bool OSAtomicCompareAndSwap32( int32_t oldValue, int32_t newValue, int32_t *theValue );
+bool OSAtomicCompareAndSwap32Barrier( int32_t oldValue, int32_t newValue, int32_t *theValue );
+
#if defined(__ppc64__) || defined(__i386__)
+
bool OSAtomicCompareAndSwap64( int64_t oldValue, int64_t newValue, int64_t *theValue );
+bool OSAtomicCompareAndSwap64Barrier( int64_t oldValue, int64_t newValue, int64_t *theValue );
+
#endif /* defined(__ppc64__) || defined(__i386__) */
-/* Test and set. They do not incorporate memory barriers and thus cannot be used by
- * themselves to synchronize shared memory. They return the original value of the bit.
- * They operate on bit (0x80>>(n&7)) in byte ((char*)theAddress + (n>>3)). They are
- * layered on top of the compare-and-swap operation.
+
+/* Test and set. They return the original value of the bit, and operate on bit (0x80>>(n&7))
+ * in byte ((char*)theAddress + (n>>3)). They are layered on top of the compare-and-swap
+ * operation.
*/
bool OSAtomicTestAndSet( uint32_t n, void *theAddress );
+bool OSAtomicTestAndSetBarrier( uint32_t n, void *theAddress );
bool OSAtomicTestAndClear( uint32_t n, void *theAddress );
-
-/* FILO queue and dequeue. These use memory barriers as required to synchronize access to
- * the queued/dequeued structure. The "inOffset" field is the offset within the structure
- * of the link field. "inList" is the list head; it is not a struct. The queue is a singly
- * linked list with a zero terminator.
- */
-void * OSAtomicDequeue( void ** inList, size_t inOffset);
-void OSAtomicEnqueue( void ** inList, void * inNewLink, size_t inOffset);
-
+bool OSAtomicTestAndClearBarrier( uint32_t n, void *theAddress );
+
/* Spinlocks. These use memory barriers as required to synchronize access to shared
* memory protected by the lock. The lock operation spins, but employs various strategies
* to back off if the lock is held, making it immune to most priority-inversion livelocks.
void OSSpinLockLock( OSSpinLock *lock );
void OSSpinLockUnlock( OSSpinLock *lock );
-/* Memory barrier. This strictly orders memory accesses in a weakly ordered model such
- * as PPC. All loads and stores executed in sequential program order before the barrier
- * will complete with respect to the coherence mechanism, before any load or store
- * executed after the barrier. Used with an atomic operation, the barrier can be used to
- * create custom synchronization protocols, as an alternative to the spinlock or queue/
- * dequeue operations. Note that this barrier does not order uncached loads and stores.
- * On a uniprocessor, the barrier is typically a nop.
+
+/* Memory barrier. It is both a read and write barrier.
*/
void OSMemoryBarrier( void );
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#include <sys/syslimits.h>
#if !defined(_ANSI_SOURCE)
+#define _POSIX_AIO_LISTIO_MAX 16
+#define _POSIX_AIO_MAX 1
+#define _POSIX_DELAYTIMER_MAX 32
+#define _POSIX_HOST_NAME_MAX 255
+#define _POSIX_LOGIN_NAME_MAX 9
+#define _POSIX_MQ_OPEN_MAX 8
+#define _POSIX_MQ_PRIO_MAX 32
+
#define _POSIX_ARG_MAX 4096
-#define _POSIX_CHILD_MAX 6
+#define _POSIX_CHILD_MAX 25
#define _POSIX_LINK_MAX 8
#define _POSIX_MAX_CANON 255
#define _POSIX_MAX_INPUT 255
#define _POSIX_NAME_MAX 14
-#define _POSIX_NGROUPS_MAX 0
-#define _POSIX_OPEN_MAX 16
-#define _POSIX_PATH_MAX 255
+#define _POSIX_NGROUPS_MAX 8
+#define _POSIX_OPEN_MAX 20
+#define _POSIX_PATH_MAX 256
#define _POSIX_PIPE_BUF 512
#define _POSIX_SSIZE_MAX 32767
#define _POSIX_STREAM_MAX 8
-#define _POSIX_TZNAME_MAX 3
+#define _POSIX_TZNAME_MAX 6
+
+#define _POSIX_RTSIG_MAX 8
+#define _POSIX_SEM_NSEMS_MAX 256
+#define _POSIX_SEM_VALUE_MAX 32767
+#define _POSIX_SIGQUEUE_MAX 32
+#define _POSIX_SSIZE_MAX 32767
+#define _POSIX_STREAM_MAX 8
+#define _POSIX_SS_REPL_MAX 4
+#define _POSIX_SYMLINK_MAX 255
+#define _POSIX_SYMLOOP_MAX 8
+#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
+#define _POSIX_THREAD_KEYS_MAX 128
+#define _POSIX_THREAD_THREADS_MAX 64
+#define _POSIX_TIMER_MAX 32
+#define _POSIX_TRACE_EVENT_NAME_MAX 30
+#define _POSIX_TRACE_NAME_MAX 8
+#define _POSIX_TRACE_SYS_MAX 8
+#define _POSIX_TRACE_USER_EVENT_MAX 32
+#define _POSIX_TTY_NAME_MAX 9
#define _POSIX2_BC_BASE_MAX 99
#define _POSIX2_BC_DIM_MAX 2048
#define _POSIX2_BC_SCALE_MAX 99
#define _POSIX2_BC_STRING_MAX 1000
+#define _POSIX2_CHARCLASS_NAME_MAX 14
#define _POSIX2_COLL_WEIGHTS_MAX 2
#define _POSIX2_EQUIV_CLASS_MAX 2
#define _POSIX2_EXPR_NEST_MAX 32
#define PTHREAD_DESTRUCTOR_ITERATIONS 4
#define PTHREAD_KEYS_MAX 128
-#endif /* !_ANSI_SOURCE */
-
-#if ( !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) ) || defined(_XOPEN_SOURCE)
+#if !defined(_POSIX_C_SOURCE)
#define PASS_MAX 128
+#endif /* _POSIX_C_SOURCE */
#define NL_ARGMAX 9
#define NL_LANGMAX 14
#define NL_MSGMAX 32767
#define NL_NMAX 1
#define NL_SETMAX 255
-#define NL_TEXTMAX 255
-#endif
+#define NL_TEXTMAX 2048
+#define _XOPEN_IOV_MAX 16
+#define IOV_MAX 1024
+#define _XOPEN_NAME_MAX 255
+#define _XOPEN_PATH_MAX 1024
+
+#endif /* _ANSI_SOURCE */
+
+/* NZERO to be defined here. TBD. See also sys/param.h */
#endif /* !_LIMITS_H_ */
+
#ifndef _LOCALE_H_
#define _LOCALE_H_
-struct lconv {
- char *decimal_point;
- char *thousands_sep;
- char *grouping;
- char *int_curr_symbol;
- char *currency_symbol;
- char *mon_decimal_point;
- char *mon_thousands_sep;
- char *mon_grouping;
- char *positive_sign;
- char *negative_sign;
- char int_frac_digits;
- char frac_digits;
- char p_cs_precedes;
- char p_sep_by_space;
- char n_cs_precedes;
- char n_sep_by_space;
- char p_sign_posn;
- char n_sign_posn;
- char int_p_cs_precedes;
- char int_n_cs_precedes;
- char int_p_sep_by_space;
- char int_n_sep_by_space;
- char int_p_sign_posn;
- char int_n_sign_posn;
-};
-
-#ifndef NULL
-#ifdef __GNUG__
-#define NULL __null
-#else /* ! __GNUG__ */
-#ifndef __cplusplus
-#define NULL ((void *)0)
-#else /* __cplusplus */
-#define NULL 0
-#endif /* ! __cplusplus */
-#endif /* __GNUG__ */
-#endif /* ! NULL */
+#include <_locale.h>
#define LC_ALL 0
#define LC_COLLATE 1
#define _LC_LAST 7 /* marks end */
-#include <sys/cdefs.h>
-
__BEGIN_DECLS
-struct lconv *localeconv(void);
char *setlocale(int, const char *);
__END_DECLS
--- /dev/null
+MACHINE_INSTHDRS += limits.h
+MACHINE_INSTHDRS := ${MACHINE_INSTHDRS:S/^/${.CURDIR}\/include\/machine\//}
--- /dev/null
+/* This is the `system' limits.h, independent of any particular
+ compiler. GCC provides its own limits.h which can be found in
+ /usr/lib/gcc, although it is not very informative.
+ This file is public domain. */
+#if defined (__ppc__) || defined (__ppc64__)
+#include <ppc/limits.h>
+#elif defined (__i386__)
+#include <i386/limits.h>
+#else
+#error architecture not supported
+#endif
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#include <sys/cdefs.h>
#include <_types.h>
-#ifndef _BSD_SIZE_T_DEFINED_
-#define _BSD_SIZE_T_DEFINED_
-typedef __osx_size_t size_t;
+#ifndef _SIZE_T
+#define _SIZE_T
+typedef __darwin_size_t size_t;
#endif
-#ifndef _BSD_SSIZE_T_DEFINED_
-#define _BSD_SSIZE_T_DEFINED_
-typedef __osx_ssize_t ssize_t;
+#ifndef _SSIZE_T
+#define _SSIZE_T
+typedef __darwin_ssize_t ssize_t;
#endif
__BEGIN_DECLS
ssize_t strfmon(char *, size_t, const char *, ...);
__END_DECLS
+#ifdef _USE_EXTENDED_LOCALES_
+#include <xlocale/_monetary.h>
+#endif /* _USE_EXTENDED_LOCALES_ */
+
#endif /* !_MONETARY_H_ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
pgno_t curcache; /* current number of cached pages */
pgno_t maxcache; /* max number of cached pages */
pgno_t npages; /* number of pages in the file */
- u_long pagesize; /* file page size */
+ unsigned long pagesize; /* file page size */
int fd; /* file descriptor */
/* page in conversion routine */
void (*pgin)(void *, pgno_t, void *);
void (*pgout)(void *, pgno_t, void *);
void *pgcookie; /* cookie for page in/out routines */
#ifdef STATISTICS
- u_long cachehit;
- u_long cachemiss;
- u_long pagealloc;
- u_long pageflush;
- u_long pageget;
- u_long pagenew;
- u_long pageput;
- u_long pageread;
- u_long pagewrite;
+ unsigned long cachehit;
+ unsigned long cachemiss;
+ unsigned long pagealloc;
+ unsigned long pageflush;
+ unsigned long pageget;
+ unsigned long pagenew;
+ unsigned long pageput;
+ unsigned long pageread;
+ unsigned long pagewrite;
#endif
} MPOOL;
void mpool_filter(MPOOL *, void (*)(void *, pgno_t, void *),
void (*)(void *, pgno_t, void *), void *);
void *mpool_new(MPOOL *, pgno_t *);
-void *mpool_get(MPOOL *, pgno_t, u_int);
-int mpool_put(MPOOL *, void *, u_int);
+void *mpool_get(MPOOL *, pgno_t, unsigned int);
+int mpool_put(MPOOL *, void *, unsigned int);
int mpool_sync(MPOOL *);
int mpool_close(MPOOL *);
#ifdef STATISTICS
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#include <sys/cdefs.h>
#include <_types.h>
-#ifndef _MODE_T_DECLARED
-typedef __osx_mode_t mode_t;
-#define _MODE_T_DECLARED
+#ifndef _MODE_T
+typedef __darwin_mode_t mode_t;
+#define _MODE_T
#endif
-#ifndef _BSD_SIZE_T_DEFINED_
-#define _BSD_SIZE_T_DEFINED_
-typedef __osx_size_t size_t;
+#ifndef _SIZE_T
+#define _SIZE_T
+typedef __darwin_size_t size_t;
#endif
-#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE)
/* Map dbm interface onto db(3). */
#include <fcntl.h>
#define DBM_RDONLY O_RDONLY
#define DBM_INSERT 0
#define DBM_REPLACE 1
-#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE)
/*
* The db(3) support for ndbm(3) always appends this suffix to the
* file name to avoid overwriting the user's original database.
} datum;
typedef struct __db DBM;
-#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE)
#define dbm_pagfno(a) DBM_PAGFNO_NOT_AVAILABLE
#endif
int dbm_clearerr( DBM *);
void dbm_close(DBM *);
int dbm_delete(DBM *, datum);
-#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE)
int dbm_dirfno(DBM *);
#endif
int dbm_error( DBM *);
datum dbm_fetch(DBM *, datum);
datum dbm_firstkey(DBM *);
-#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE)
long dbm_forder(DBM *, datum);
#endif
datum dbm_nextkey(DBM *);
#define NL_SETD 0
#define NL_CAT_LOCALE 1
-#ifndef _NL_ITEM_DECLARED
-typedef __osx_nl_item nl_item;
-#define _NL_ITEM_DECLARED
+#ifndef _NL_ITEM
+typedef __darwin_nl_item nl_item;
+#define _NL_ITEM
#endif
typedef void *nl_catd;
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <sys/poll.h>
+
+
+
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
};
struct rip {
- u_char rip_cmd; /* request/response */
- u_char rip_vers; /* protocol version # */
- u_char rip_res1[2]; /* pad to 32-bit boundary */
+ unsigned char rip_cmd; /* request/response */
+ unsigned char rip_vers; /* protocol version # */
+ unsigned char rip_res1[2]; /* pad to 32-bit boundary */
union {
struct netinfo ru_nets[1]; /* variable length... */
char ru_tracefile[1]; /* ditto ... */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* Client->server request message format.
*/
typedef struct {
- u_char vers; /* protocol version */
- u_char type; /* request type, see below */
- u_char answer; /* not used */
- u_char pad;
- u_long id_num; /* message id */
- struct osockaddr addr; /* old (4.3) style */
- struct osockaddr ctl_addr; /* old (4.3) style */
- long pid; /* caller's process id */
+ unsigned char vers; /* protocol version */
+ unsigned char type; /* request type, see below */
+ unsigned char answer; /* not used */
+ unsigned char pad;
+ unsigned long id_num; /* message id */
+ struct osockaddr addr; /* old (4.3) style */
+ struct osockaddr ctl_addr; /* old (4.3) style */
+ long pid; /* caller's process id */
#define NAME_SIZE 12
- char l_name[NAME_SIZE];/* caller's name */
- char r_name[NAME_SIZE];/* callee's name */
+ char l_name[NAME_SIZE];/* caller's name */
+ char r_name[NAME_SIZE];/* callee's name */
#define TTY_SIZE 16
- char r_tty[TTY_SIZE];/* callee's tty name */
+ char r_tty[TTY_SIZE];/* callee's tty name */
} CTL_MSG;
/*
* Server->client response message format.
*/
typedef struct {
- u_char vers; /* protocol version */
- u_char type; /* type of request message, see below */
- u_char answer; /* respose to request message, see below */
- u_char pad;
- u_long id_num; /* message id */
- struct osockaddr addr; /* address for establishing conversation */
+ unsigned char vers; /* protocol version */
+ unsigned char type; /* type of request message, see below */
+ unsigned char answer; /* respose to request message, see below */
+ unsigned char pad;
+ unsigned long id_num; /* message id */
+ struct osockaddr addr; /* address for establishing conversation */
} CTL_RESPONSE;
#define TALK_VERSION 1 /* protocol version */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#define ANYADDR NULL
struct tsp {
- u_char tsp_type;
- u_char tsp_vers;
- u_short tsp_seq;
+ unsigned char tsp_type;
+ unsigned char tsp_vers;
+ unsigned short tsp_seq;
union {
struct timeval tspu_time;
char tspu_hopcnt;
} tsp_u;
- char tsp_name[MAXHOSTNAMELEN];
+ char tsp_name[MAXHOSTNAMELEN];
};
#define tsp_time tsp_u.tspu_time
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#include <_types.h>
-#ifndef _GID_T_DECLARED
-typedef __osx_gid_t gid_t;
-#define _GID_T_DECLARED
-#endif
-
-#ifndef _BSD_SIZE_T_DEFINED_
-#define _BSD_SIZE_T_DEFINED_
-typedef __osx_size_t size_t;
+#ifndef _GID_T
+typedef __darwin_gid_t gid_t;
+#define _GID_T
#endif
-#ifndef _BSD_TIME_T_DEFINED_
-#define _BSD_TIME_T_DEFINED_
-typedef __osx_time_t time_t;
+#ifndef _SIZE_T
+#define _SIZE_T
+typedef __darwin_size_t size_t;
#endif
-#ifndef _UID_T_DECLARED
-typedef __osx_uid_t uid_t;
-#define _UID_T_DECLARED
+#ifndef _UID_T
+typedef __darwin_uid_t uid_t;
+#define _UID_T
#endif
-#ifndef _POSIX_SOURCE
+#ifndef _POSIX_C_SOURCE
#define _PATH_PWD "/etc"
#define _PATH_PASSWD "/etc/passwd"
#define _PASSWD "passwd"
char *pw_passwd; /* encrypted password */
uid_t pw_uid; /* user uid */
gid_t pw_gid; /* user gid */
- time_t pw_change; /* password change time */
+ __darwin_time_t pw_change; /* password change time */
char *pw_class; /* user access class */
char *pw_gecos; /* Honeywell login info */
char *pw_dir; /* home directory */
char *pw_shell; /* default shell */
- time_t pw_expire; /* account expiration */
+ __darwin_time_t pw_expire; /* account expiration */
};
#include <sys/cdefs.h>
int getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **);
int getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **);
struct passwd *getpwent(void);
-#if !defined(_POSIX_SOURCE) && !defined(_XOPEN_SOURCE)
+#if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)
int setpassent(int);
char *user_from_uid(uid_t, int);
#endif
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#define _REGEX_H_
#include <sys/cdefs.h>
-#include <sys/_types.h>
+#include <_types.h>
/* types */
-typedef __off_t regoff_t;
+typedef __darwin_off_t regoff_t;
-#ifndef _BSD_SIZE_T_DEFINED_
-#define _BSD_SIZE_T_DEFINED_
-typedef __size_t size_t;
+#ifndef _SIZE_T
+#define _SIZE_T
+typedef __darwin_size_t size_t;
#endif
typedef struct {
} regmatch_t;
/* regcomp() flags */
-#ifndef _POSIX_SOURCE
+#ifndef _POSIX_C_SOURCE
#define REG_BASIC 0000
-#endif /* !_POSIX_SOURCE */
+#endif /* !_POSIX_C_SOURCE */
#define REG_EXTENDED 0001
#define REG_ICASE 0002
#define REG_NOSUB 0004
#define REG_NEWLINE 0010
-#ifndef _POSIX_SOURCE
+#ifndef _POSIX_C_SOURCE
#define REG_NOSPEC 0020
#define REG_PEND 0040
#define REG_DUMP 0200
-#endif /* !_POSIX_SOURCE */
+#endif /* !_POSIX_C_SOURCE */
/* regerror() flags */
#define REG_ENOSYS (-1) /* Reserved */
#define REG_ERANGE 11
#define REG_ESPACE 12
#define REG_BADRPT 13
-#ifndef _POSIX_SOURCE
+#ifndef _POSIX_C_SOURCE
#define REG_EMPTY 14
#define REG_ASSERT 15
#define REG_INVARG 16
+#define REG_ILLSEQ 17
#define REG_ATOI 255 /* convert name to number (!) */
#define REG_ITOA 0400 /* convert number to name (!) */
-#endif /* !_POSIX_SOURCE */
+#endif /* !_POSIX_C_SOURCE */
/* regexec() flags */
#define REG_NOTBOL 00001
#define REG_NOTEOL 00002
-#ifndef _POSIX_SOURCE
+#ifndef _POSIX_C_SOURCE
#define REG_STARTEND 00004
#define REG_TRACE 00400 /* tracing of execution */
#define REG_LARGE 01000 /* force large representation */
#define REG_BACKR 02000 /* force use of backref code */
-#endif /* !_POSIX_SOURCE */
+#endif /* !_POSIX_C_SOURCE */
__BEGIN_DECLS
-int regcomp(regex_t * __restrict, const char * __restrict, int);
+int regcomp(regex_t * __restrict, const char * __restrict, int) __DARWIN_ALIAS(regcomp);
size_t regerror(int, const regex_t * __restrict, char * __restrict, size_t);
+/* For meeting c99 stds, pass regmatch_t*, rather than the array */
int regexec(const regex_t * __restrict,
- const char * __restrict, size_t, regmatch_t [ __restrict], int);
+ const char * __restrict, size_t, regmatch_t * __restrict, int);
void regfree(regex_t *);
__END_DECLS
+++ /dev/null
-/*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-/*
- * Copyright (c) 1986 by University of Toronto.
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley
- * by Henry Spencer.
- *
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- *
- * @(#)regexp.h 8.1 (Berkeley) 6/2/93
- */
-
-#ifndef _REGEXP_H_
-#define _REGEXP_H_
-
-/*
- * Definitions etc. for regexp(3) routines.
- *
- * Caveat: this is V8 regexp(3) [actually, a reimplementation thereof],
- * not the System V one.
- */
-#define NSUBEXP 10
-typedef struct regexp {
- char *startp[NSUBEXP];
- char *endp[NSUBEXP];
- char regstart; /* Internal use only. */
- char reganch; /* Internal use only. */
- char *regmust; /* Internal use only. */
- int regmlen; /* Internal use only. */
- char program[1]; /* Unwarranted chumminess with compiler. */
-} regexp;
-
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-regexp *regcomp(const char *);
-int regexec(const regexp *, const char *);
-void regsub(const regexp *, const char *, char *);
-void regerror(const char *);
-__END_DECLS
-
-#endif /* !_REGEXP_H_ */
#include <runetype.h>
#include <stdio.h>
+#include <AvailabilityMacros.h>
+
+/*--------------------------- DEPRECIATED -------------------------------
+ * This interface is depreciated and will eventually be removed. The ISO C99
+ * extended multibyte and wide character facilities should be used instead.
+ * See multibyte(3) and related man pages for further details.
+ *--------------------------- DEPRECIATED -------------------------------*/
#define _PATH_LOCALE "/usr/share/locale"
-#define _INVALID_RUNE _CurrentRuneLocale->invalid_rune
+#define _INVALID_RUNE _CurrentRuneLocale->__invalid_rune
-#define __sgetrune _CurrentRuneLocale->sgetrune
-#define __sputrune _CurrentRuneLocale->sputrune
+#define __sgetrune _CurrentRuneLocale->__sgetrune
+#define __sputrune _CurrentRuneLocale->__sputrune
#define sgetrune(s, n, r) (*__sgetrune)((s), (n), (r))
#define sputrune(c, s, n, r) (*__sputrune)((c), (s), (n), (r))
__BEGIN_DECLS
-char *mbrune(const char *, rune_t);
-char *mbrrune(const char *, rune_t);
-char *mbmb(const char *, char *);
-long fgetrune(FILE *);
-int fputrune(rune_t, FILE *);
-int fungetrune(rune_t, FILE *);
-int setrunelocale(char *);
-void setinvalidrune(rune_t);
+char *mbrune(const char *, rune_t) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
+char *mbrrune(const char *, rune_t) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
+char *mbmb(const char *, char *) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
+long fgetrune(FILE *) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
+int fputrune(rune_t, FILE *) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
+int fungetrune(rune_t, FILE *) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
+int setrunelocale(char *) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
+void setinvalidrune(rune_t) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
__END_DECLS
#endif /*! _RUNE_H_ */
#include <sys/cdefs.h>
#include <_types.h>
-#ifndef _BSD_SIZE_T_DEFINED_
-#define _BSD_SIZE_T_DEFINED_
-typedef __osx_size_t size_t;
+#ifndef _POSIX_C_SOURCE
+
+#ifndef _SIZE_T
+#define _SIZE_T
+typedef __darwin_size_t size_t;
#endif
-#ifndef _BSD_CT_RUNE_T_DEFINED_
-#define _BSD_CT_RUNE_T_DEFINED_
-typedef __osx_ct_rune_t ct_rune_t;
+#ifndef _CT_RUNE_T
+#define _CT_RUNE_T
+typedef __darwin_ct_rune_t ct_rune_t;
#endif
-#ifndef _BSD_RUNE_T_DEFINED_
-#define _BSD_RUNE_T_DEFINED_
-typedef __osx_rune_t rune_t;
+#ifndef _RUNE_T
+#define _RUNE_T
+typedef __darwin_rune_t rune_t;
#endif
#ifndef __cplusplus
-#ifndef _BSD_WCHAR_T_DEFINED_
-#define _BSD_WCHAR_T_DEFINED_
-typedef __osx_wchar_t wchar_t;
-#endif /* _BSD_WCHAR_T_DEFINED_ */
+#ifndef _WCHAR_T
+#define _WCHAR_T
+typedef __darwin_wchar_t wchar_t;
+#endif /* _WCHAR_T */
#endif /* __cplusplus */
-#ifndef _BSD_WINT_T_DEFINED_
-#define _BSD_WINT_T_DEFINED_
-typedef __osx_wint_t wint_t;
+#ifndef _WINT_T
+#define _WINT_T
+typedef __darwin_wint_t wint_t;
#endif
+#endif /* !_POSIX_C_SOURCE */
+
#define _CACHED_RUNES (1 <<8 ) /* Must be a power of 2 */
#define _CRMASK (~(_CACHED_RUNES - 1))
* The lower 8 bits of runetype[] contain the digit value of the rune.
*/
typedef struct {
- rune_t min; /* First rune of the range */
- rune_t max; /* Last rune (inclusive) of the range */
- rune_t map; /* What first maps to in maps */
- unsigned long *types; /* Array of types in range */
+ __darwin_rune_t __min; /* First rune of the range */
+ __darwin_rune_t __max; /* Last rune (inclusive) of the range */
+ __darwin_rune_t __map; /* What first maps to in maps */
+ __uint32_t *__types; /* Array of types in range */
} _RuneEntry;
typedef struct {
- int nranges; /* Number of ranges stored */
- _RuneEntry *ranges; /* Pointer to the ranges */
+ int __nranges; /* Number of ranges stored */
+ _RuneEntry *__ranges; /* Pointer to the ranges */
} _RuneRange;
typedef struct {
- char magic[8]; /* Magic saying what version we are */
- char encoding[32]; /* ASCII name of this encoding */
+ char __magic[8]; /* Magic saying what version we are */
+ char __encoding[32]; /* ASCII name of this encoding */
- rune_t (*sgetrune)
- (const char *, size_t, char const **);
- int (*sputrune)
- (rune_t, char *, size_t, char **);
- rune_t invalid_rune;
+ __darwin_rune_t (*__sgetrune)(const char *, __darwin_size_t, char const **);
+ int (*__sputrune)(__darwin_rune_t, char *, __darwin_size_t, char **);
+ __darwin_rune_t __invalid_rune;
- unsigned long runetype[_CACHED_RUNES];
- rune_t maplower[_CACHED_RUNES];
- rune_t mapupper[_CACHED_RUNES];
+ __uint32_t __runetype[_CACHED_RUNES];
+ __darwin_rune_t __maplower[_CACHED_RUNES];
+ __darwin_rune_t __mapupper[_CACHED_RUNES];
/*
* The following are to deal with Runes larger than _CACHED_RUNES - 1.
* Their data is actually contiguous with this structure so as to make
* it easier to read/write from/to disk.
*/
- _RuneRange runetype_ext;
- _RuneRange maplower_ext;
- _RuneRange mapupper_ext;
+ _RuneRange __runetype_ext;
+ _RuneRange __maplower_ext;
+ _RuneRange __mapupper_ext;
- void *variable; /* Data which depends on the encoding */
- int variable_len; /* how long that data is */
+ void *__variable; /* Data which depends on the encoding */
+ int __variable_len; /* how long that data is */
} _RuneLocale;
#define _RUNE_MAGIC_1 "RuneMagi" /* Indicates version 0 of RuneLocale */
#include <sys/cdefs.h>
#include <_types.h>
-#ifndef _BSD_SIZE_T_DEFINED_
-#define _BSD_SIZE_T_DEFINED_
-typedef __osx_size_t size_t;
+#ifndef _SIZE_T
+#define _SIZE_T
+typedef __darwin_size_t size_t;
#endif
typedef struct entry {
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* @(#)sgtty.h 8.1 (Berkeley) 6/2/93
*/
+#ifndef _SGTTY_H_
+#define _SGTTY_H_
+
+#include <sys/cdefs.h>
+
#ifndef USE_OLD_TTY
#define USE_OLD_TTY
#endif
#include <sys/ioctl.h>
+
+__BEGIN_DECLS
+int gtty(int, struct sgttyb *);
+int stty(int, struct sgttyb *);
+__END_DECLS
+
+#define gtty(fd, buf) ioctl(fd, TIOCGETP, buf)
+#define stty(fd, buf) ioctl(fd, TIOCSETP, buf)
+
+#endif /* _SGTTY_H_ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#include <sys/cdefs.h>
#include <sys/signal.h>
-#ifndef _PTHREAD_T_DECLARED
-typedef __osx_pthread_t pthread_t;
-#define _PTHREAD_T_DECLARED
+#ifndef _PTHREAD_T
+typedef __darwin_pthread_t pthread_t;
+#define _PTHREAD_T
#endif
-#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE)
extern __const char *__const sys_signame[NSIG];
extern __const char *__const sys_siglist[NSIG];
#endif
int sigpending(sigset_t *);
int sigprocmask(int, const sigset_t * __restrict, sigset_t * __restrict);
int sigrelse(int);
+void (*sigset(int, void (*)(int)))(int);
int sigsuspend(const sigset_t *);
int sigwait(const sigset_t * __restrict, int * __restrict);
-#ifndef _POSIX_SOURCE
+#ifndef _POSIX_C_SOURCE
void psignal(unsigned int, const char *);
int sigblock(int);
int sigreturn(struct sigcontext *);
int sigsetmask(int);
int sigvec(int, struct sigvec *, struct sigvec *);
-#endif /* !_POSIX_SOURCE */
+#endif /* !_POSIX_C_SOURCE */
__END_DECLS
/* List definitions after function declarations, or Reiser cpp gets upset. */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#ifndef _STANDARDS_H
#define _STANDARDS_H
-#ifdef _POSIX_SOURCE
+#ifdef _POSIX_C_SOURCE
# ifndef __STRICT_ANSI__
# define __STRICT_ANSI__
# endif
# undef __STRICT_BSD__
-#endif /* _POSIX_SOURCE */
+#endif /* _POSIX_C_SOURCE */
#endif /* _STANDARDS_H */
--- /dev/null
+/* This file is public domain. */
+/* GCC uses its own copy of this header */
+#if defined(__GNUC__)
+#include_next <stdarg.h>
+#elif defined(__MWERKS__)
+#include "mw_stdarg.h"
+#else
+#error "This header only supports __MWERKS__."
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2000 Jeroen Ruigrok van der Werven <asmodai@FreeBSD.org>
+ * 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.
+ *
+ * $FreeBSD: src/include/stdbool.h,v 1.6 2002/08/16 07:33:14 alfred Exp $
+ */
+
+#ifndef _STDBOOL_H_
+#define _STDBOOL_H_
+
+#define __bool_true_false_are_defined 1
+
+#ifndef __cplusplus
+
+#define false 0
+#define true 1
+
+#define bool _Bool
+#if __STDC_VERSION__ < 199901L && __GNUC__ < 3
+typedef int _Bool;
+#endif
+
+#endif /* !__cplusplus */
+
+#endif /* !_STDBOOL_H_ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* @(#)stddef.h 5.5 (Berkeley) 4/3/91
*/
-#ifndef __STDDEF_H__
+#if !defined(__STDDEF_H__)
+
+#if !defined(__need_wchar_t) && !defined(__need_size_t) \
+ && !defined(__need_ptrdiff_t) && !defined(__need_NULL) \
+ && !defined(__need_wint_t)
#define __STDDEF_H__
+#endif /* none of __need_* defined */
#include <_types.h>
-#ifndef _PTRDIFF_T_DECLARED
-typedef __osx_ptrdiff_t ptrdiff_t;
-#define _PTRDIFF_T_DECLARED
-#endif
+#if defined(__STDDEF_H__) || defined(__need_ptrdiff_t)
+#ifndef _PTRDIFF_T
+#define _PTRDIFF_T
+typedef __darwin_ptrdiff_t ptrdiff_t;
+#endif /* _PTRDIFF_T */
+#endif /* __STDDEF_H__ || __need_ptrdiff_t */
-#ifndef _BSD_SIZE_T_DEFINED_
-#define _BSD_SIZE_T_DEFINED_
-typedef __osx_size_t size_t;
-#endif
+#if defined(__STDDEF_H__) || defined(__need_size_t)
+#ifndef _SIZE_T
+#define _SIZE_T
+/* DO NOT REMOVE THIS COMMENT: fixincludes needs to see:
+ * _GCC_SIZE_T */
+typedef __darwin_size_t size_t;
+#endif /* _SIZE_T */
+#endif /* __STDDEF_H__ || __need_size_t */
+#if defined(__STDDEF_H__) || defined(__need_wchar_t)
#ifndef __cplusplus
-#ifndef _BSD_WCHAR_T_DEFINED_
-#define _BSD_WCHAR_T_DEFINED_
-typedef __osx_wchar_t wchar_t;
-#endif /* _BSD_WCHAR_T_DEFINED_ */
+#ifndef _WCHAR_T
+#define _WCHAR_T
+typedef __darwin_wchar_t wchar_t;
+#endif /* _WCHAR_T */
#endif /* __cplusplus */
+#endif /* __STDDEF_H__ || __need_wchar_t */
+
+#if (defined(__STDDEF_H__) && !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE)) \
+ || defined(__need_wint_t)
+#ifndef _WINT_T
+#define _WINT_T
+typedef __darwin_wint_t wint_t;
+#endif /* _WINT_T */
+#endif /* __STDDEF_H__ && !_ANSI_SOURCE && !_POSIX_C_SOURCE || __need_wchar_t */
+#if defined(__STDDEF_H__) || defined(__need_NULL)
#ifndef NULL
-#define NULL __OSX_NULL
+#define NULL __DARWIN_NULL
#endif /* ! NULL */
+#endif /* __STDDEF_H__ || __need_NULL */
+#ifdef __STDDEF_H__
+#if defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 5 || __GNUC__ > 3)
+#ifndef __offsetof /* Deprecated: for source compatability only */
+#define __offsetof(type, field) __builtin_offsetof(type, field)
+#endif
+#define offsetof(type, field) __builtin_offsetof(type, field)
+#else /* ! (gcc >= 3.5) */
#ifndef __offsetof /* Deprecated: for source compatability only */
#define __offsetof(type, field) ((size_t)(&((type *)0)->field))
#endif
#define offsetof(type, field) ((size_t)(&((type *)0)->field))
+#endif /* (gcc >= 3.5) */
+#endif /* __STDDEF_H__ */
#endif /* __STDDEF_H__ */
+
+#undef __need_ptrdiff_t
+#undef __need_size_t
+#undef __need_wchar_t
+#undef __need_wint_t
+#undef __need_NULL
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#include <_types.h>
#include <sys/cdefs.h>
-#ifndef _POSIX_SOURCE
-#include <stdarg.h>
-#else /* _POSIX_SOURCE */
-/* set __need___va_list to only define __gnuc_va_list */
-#define __need___va_list
-#include <stdarg.h>
-#ifdef __GNUC_VA_LIST
-#ifndef _VA_LIST_DEFINED
-#define _VA_LIST_DEFINED
-typedef __gnuc_va_list va_list;
-#endif /* _VA_LIST_DEFINED */
-#endif /* __GNUC_VA_LIST */
-#endif /* _POSIX_SOURCE */
-
-#ifndef _BSD_SIZE_T_DEFINED_
-#define _BSD_SIZE_T_DEFINED_
-typedef __osx_size_t size_t;
+#ifndef _VA_LIST
+#define _VA_LIST
+/* DO NOT REMOVE THIS COMMENT: fixincludes needs to see:
+ * __gnuc_va_list and include <stdarg.h> */
+typedef __darwin_va_list va_list;
+#endif
+
+#ifndef _SIZE_T
+#define _SIZE_T
+typedef __darwin_size_t size_t;
#endif
#ifndef NULL
-#define NULL __OSX_NULL
+#define NULL __DARWIN_NULL
#endif /* ! NULL */
#if !defined(_ANSI_SOURCE) && !defined(__STRICT_ANSI__)
-typedef __osx_off_t fpos_t;
+typedef __darwin_off_t fpos_t;
#else
-typedef __int64_t fpos_t;
+typedef __int64_t fpos_t;
#endif
#define _FSTDIO /* Define for new stdio with functions. */
/* stdio buffers */
struct __sbuf {
- unsigned char *_base;
- int _size;
+ unsigned char *_base;
+ int _size;
};
/* hold a buncha junk that would grow the ABI */
} FILE;
__BEGIN_DECLS
+#if __DARWIN_UNIX03
+extern FILE *__stdinp;
+extern FILE *__stdoutp;
+extern FILE *__stderrp;
+#else /* !__DARWIN_UNIX03 */
extern FILE __sF[];
+#endif /* __DARWIN_UNIX03 */
__END_DECLS
#define __SLBF 0x0001 /* line buffered */
#define SEEK_END 2 /* set file offset to EOF plus offset */
#endif
+#if __DARWIN_UNIX03
+#define stdin __stdinp
+#define stdout __stdoutp
+#define stderr __stderrp
+#else /* !__DARWIN_UNIX03 */
#define stdin (&__sF[0])
#define stdout (&__sF[1])
#define stderr (&__sF[2])
+#endif /* __DARWIN_UNIX03 */
/*
* Functions defined in ANSI C standard.
int fgetpos(FILE * __restrict, fpos_t *);
char *fgets(char * __restrict, int, FILE *);
FILE *fopen(const char * __restrict, const char * __restrict);
-int fprintf(FILE * __restrict, const char * __restrict, ...);
+int fprintf(FILE * __restrict, const char * __restrict, ...) __DARWIN_LDBL_COMPAT(fprintf);
int fputc(int, FILE *);
int fputs(const char * __restrict, FILE * __restrict);
size_t fread(void * __restrict, size_t, size_t, FILE * __restrict);
FILE *freopen(const char * __restrict, const char * __restrict,
- FILE * __restrict);
-int fscanf(FILE * __restrict, const char * __restrict, ...);
+ FILE * __restrict) __DARWIN_ALIAS(freopen);
+int fscanf(FILE * __restrict, const char * __restrict, ...) __DARWIN_LDBL_COMPAT(fscanf);
int fseek(FILE *, long, int);
int fsetpos(FILE *, const fpos_t *);
long ftell(FILE *);
-size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict);
+size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict) __DARWIN_ALIAS(fwrite);
int getc(FILE *);
int getchar(void);
char *gets(char *);
-#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE)
extern __const int sys_nerr; /* perror(3) external variables */
extern __const char *__const sys_errlist[];
#endif
void perror(const char *);
-int printf(const char * __restrict, ...);
+int printf(const char * __restrict, ...) __DARWIN_LDBL_COMPAT(printf);
int putc(int, FILE *);
int putchar(int);
int puts(const char *);
int remove(const char *);
int rename (const char *, const char *);
void rewind(FILE *);
-int scanf(const char * __restrict, ...);
+int scanf(const char * __restrict, ...) __DARWIN_LDBL_COMPAT(scanf);
void setbuf(FILE * __restrict, char * __restrict);
int setvbuf(FILE * __restrict, char * __restrict, int, size_t);
-int sprintf(char * __restrict, const char * __restrict, ...);
-int sscanf(const char * __restrict, const char * __restrict, ...);
+int sprintf(char * __restrict, const char * __restrict, ...) __DARWIN_LDBL_COMPAT(sprintf);
+int sscanf(const char * __restrict, const char * __restrict, ...) __DARWIN_LDBL_COMPAT(sscanf);
FILE *tmpfile(void);
char *tmpnam(char *);
int ungetc(int, FILE *);
-int vfprintf(FILE * __restrict, const char * __restrict, va_list);
-int vprintf(const char * __restrict, va_list);
-int vsprintf(char * __restrict, const char * __restrict, va_list);
-#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
-int asprintf(char **, const char *, ...);
-int vasprintf(char **, const char *, va_list);
+int vfprintf(FILE * __restrict, const char * __restrict, va_list) __DARWIN_LDBL_COMPAT(vfprintf);
+int vprintf(const char * __restrict, va_list) __DARWIN_LDBL_COMPAT(vprintf);
+int vsprintf(char * __restrict, const char * __restrict, va_list) __DARWIN_LDBL_COMPAT(vsprintf);
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE)
+int asprintf(char **, const char *, ...) __DARWIN_LDBL_COMPAT(asprintf);
+int vasprintf(char **, const char *, va_list) __DARWIN_LDBL_COMPAT(vasprintf);
#endif
__END_DECLS
__BEGIN_DECLS
char *ctermid(char *);
-#ifndef _POSIX_SOURCE
+#ifndef _POSIX_C_SOURCE
char *ctermid_r(char *);
#endif /* not POSIX */
FILE *fdopen(int, const char *);
-#ifndef _POSIX_SOURCE
+#ifndef _POSIX_C_SOURCE
char *fgetln(FILE *, size_t *);
#endif /* not POSIX */
int fileno(FILE *);
void flockfile(FILE *);
-#ifndef _POSIX_SOURCE
+#ifndef _POSIX_C_SOURCE
__const char
*fmtcheck(const char *, const char *);
int fpurge(FILE *);
void funlockfile(FILE *);
int getc_unlocked(FILE *);
int getchar_unlocked(void);
-#ifndef _POSIX_SOURCE
+#ifndef _POSIX_C_SOURCE
int getw(FILE *);
#endif /* not POSIX */
int pclose(FILE *);
FILE *popen(const char *, const char *);
int putc_unlocked(int, FILE *);
int putchar_unlocked(int);
-#ifndef _POSIX_SOURCE
+#ifndef _POSIX_C_SOURCE
int putw(int, FILE *);
void setbuffer(FILE *, char *, int);
int setlinebuf(FILE *);
#endif /* not POSIX */
-int snprintf(char * __restrict, size_t, const char * __restrict, ...);
+int snprintf(char * __restrict, size_t, const char * __restrict, ...) __DARWIN_LDBL_COMPAT(snprintf);
char *tempnam(const char *, const char *);
-int vfscanf(FILE * __restrict, const char * __restrict, va_list);
-int vscanf(const char * __restrict, va_list);
-int vsnprintf(char * __restrict, size_t, const char * __restrict, va_list);
-int vsscanf(const char * __restrict, const char * __restrict, va_list);
-#ifndef _POSIX_SOURCE
+int vfscanf(FILE * __restrict, const char * __restrict, va_list) __DARWIN_LDBL_COMPAT(vfscanf);
+int vscanf(const char * __restrict, va_list) __DARWIN_LDBL_COMPAT(vscanf);
+int vsnprintf(char * __restrict, size_t, const char * __restrict, va_list) __DARWIN_LDBL_COMPAT(vsnprintf);
+int vsscanf(const char * __restrict, const char * __restrict, va_list) __DARWIN_LDBL_COMPAT(vsscanf);
+#ifndef _POSIX_C_SOURCE
FILE *zopen(const char *, const char *, int);
#endif /* not POSIX */
__END_DECLS
/*
* Stdio function-access interface.
*/
-#ifndef _POSIX_SOURCE
+#ifndef _POSIX_C_SOURCE
__BEGIN_DECLS
FILE *funopen(const void *,
int (*)(void *, char *, int),
*/
__BEGIN_DECLS
int __srget(FILE *);
-int __svfscanf(FILE *, const char *, va_list);
+int __svfscanf(FILE *, const char *, va_list) __DARWIN_LDBL_COMPAT(__svfscanf);
int __swbuf(int, FILE *);
__END_DECLS
#define __sfileno(p) ((p)->_file)
#ifndef _ANSI_SOURCE
-#ifndef _POSIX_SOURCE
+#ifndef _POSIX_C_SOURCE
#define feof_unlocked(p) __sfeof(p)
#define ferror_unlocked(p) __sferror(p)
#define clearerr_unlocked(p) __sclearerr(p)
#define putchar_unlocked(x) putc_unlocked(x, stdout)
#endif /* not ANSI */
+#ifdef _USE_EXTENDED_LOCALES_
+#include <xlocale/_stdio.h>
+#endif /* _USE_EXTENDED_LOCALES_ */
+
#endif /* _STDIO_H_ */
/*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000, 2005 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#ifndef _STDLIB_H_
#define _STDLIB_H_
-#include <machine/ansi.h>
-#include <machine/types.h>
-#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
+#include <sys/cdefs.h>
+#include <_types.h>
+#if !defined(_ANSI_SOURCE)
+#include <sys/wait.h>
+#if !defined(_POSIX_C_SOURCE)
#include <alloca.h>
-#endif
+#endif /* !_POSIX_C_SOURCE */
+#endif /* !_ANSI_SOURCE */
-#ifndef _BSD_SIZE_T_DEFINED_
-#define _BSD_SIZE_T_DEFINED_
-typedef _BSD_SIZE_T_ size_t;
+#ifndef _SIZE_T
+#define _SIZE_T
+/* DO NOT REMOVE THIS COMMENT: fixincludes needs to see:
+ * _GCC_SIZE_T */
+typedef __darwin_size_t size_t;
#endif
-#if !defined(_ANSI_SOURCE)
-#ifndef _BSD_CT_RUNE_T_DEFINED_
-#define _BSD_CT_RUNE_T_DEFINED_
-typedef _BSD_CT_RUNE_T_ ct_rune_t;
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE)
+#ifndef _CT_RUNE_T
+#define _CT_RUNE_T
+typedef __darwin_ct_rune_t ct_rune_t;
#endif
-#ifndef _BSD_RUNE_T_DEFINED_
-#define _BSD_RUNE_T_DEFINED_
-typedef _BSD_RUNE_T_ rune_t;
+#ifndef _RUNE_T
+#define _RUNE_T
+typedef __darwin_rune_t rune_t;
#endif
#endif
#ifndef __cplusplus
-#ifndef _BSD_WCHAR_T_DEFINED_
-#define _BSD_WCHAR_T_DEFINED_
-#ifdef __WCHAR_TYPE__
-typedef __WCHAR_TYPE__ wchar_t;
-#else /* ! __WCHAR_TYPE__ */
-typedef _BSD_WCHAR_T_ wchar_t;
-#endif /* __WCHAR_TYPE__ */
-#endif /* _BSD_WCHAR_T_DEFINED_ */
+#ifndef _WCHAR_T
+#define _WCHAR_T
+typedef __darwin_wchar_t wchar_t;
+#endif /* _WCHAR_T */
#endif /* __cplusplus */
-#ifndef _BSD_WINT_T_DEFINED_
-#define _BSD_WINT_T_DEFINED_
-typedef _BSD_WINT_T_ wint_t;
-#endif
-
typedef struct {
int quot; /* quotient */
int rem; /* remainder */
long rem; /* remainder */
} ldiv_t;
+#if !__DARWIN_NO_LONG_LONG
+typedef struct {
+ long long quot;
+ long long rem;
+} lldiv_t;
+#endif /* !__DARWIN_NO_LONG_LONG */
+
#ifndef NULL
-#ifdef __GNUG__
-#define NULL __null
-#else /* ! __GNUG__ */
-#ifndef __cplusplus
-#define NULL ((void *)0)
-#else /* __cplusplus */
-#define NULL 0
-#endif /* ! __cplusplus */
-#endif /* __GNUG__ */
+#define NULL __DARWIN_NULL
#endif /* ! NULL */
#define EXIT_FAILURE 1
#define RAND_MAX 0x7fffffff
+#ifdef _USE_EXTENDED_LOCALES_
+#include <_xlocale.h>
+#endif /* _USE_EXTENDED_LOCALES_ */
+
+#ifndef MB_CUR_MAX
+#ifdef _USE_EXTENDED_LOCALES_
+#define MB_CUR_MAX (___mb_cur_max())
+#ifndef MB_CUR_MAX_L
+#define MB_CUR_MAX_L(x) (___mb_cur_max_l(x))
+#endif /* !MB_CUR_MAX_L */
+#else /* !_USE_EXTENDED_LOCALES_ */
extern int __mb_cur_max;
#define MB_CUR_MAX __mb_cur_max
+#endif /* _USE_EXTENDED_LOCALES_ */
+#endif /* MB_CUR_MAX */
-#include <sys/cdefs.h>
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) \
+ && defined(_USE_EXTENDED_LOCALES_) && !defined(MB_CUR_MAX_L)
+#define MB_CUR_MAX_L(x) (___mb_cur_max_l(x))
+#endif
__BEGIN_DECLS
void abort(void) __dead2;
double atof(const char *);
int atoi(const char *);
long atol(const char *);
+#if !__DARWIN_NO_LONG_LONG
+long long
+ atoll(const char *);
+#endif /* !__DARWIN_NO_LONG_LONG */
void *bsearch(const void *, const void *, size_t,
size_t, int (*)(const void *, const void *));
void *calloc(size_t, size_t);
char *getenv(const char *);
long labs(long) __pure2;
ldiv_t ldiv(long, long) __pure2;
+#if !__DARWIN_NO_LONG_LONG
+long long
+ llabs(long long);
+lldiv_t lldiv(long long, long long);
+#endif /* !__DARWIN_NO_LONG_LONG */
void *malloc(size_t);
int mblen(const char *, size_t);
size_t mbstowcs(wchar_t * __restrict , const char * __restrict, size_t);
float strtof(const char *, char **);
long strtol(const char *, char **, int);
long double
- strtold(const char *, char **);
+ strtold(const char *, char **) __DARWIN_LDBL_COMPAT(strtold);
+#if !__DARWIN_NO_LONG_LONG
+long long
+ strtoll(const char *, char **, int);
+#endif /* !__DARWIN_NO_LONG_LONG */
unsigned long
strtoul(const char *, char **, int);
+#if !__DARWIN_NO_LONG_LONG
+unsigned long long
+ strtoull(const char *, char **, int);
+#endif /* !__DARWIN_NO_LONG_LONG */
int system(const char *);
-void *valloc(size_t);
-int wctomb(char *, wchar_t);
size_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t);
+int wctomb(char *, wchar_t);
#ifndef _ANSI_SOURCE
-int putenv(const char *);
-int setenv(const char *, const char *, int);
-#endif
-
-#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
-u_int32_t
- arc4random(void);
-void arc4random_addrandom(unsigned char *dat, int datlen);
-void arc4random_stir(void);
+void _Exit(int) __dead2;
+long a64l(const char *);
double drand48(void);
+char *ecvt(double, int, int *__restrict, int *__restrict); /* LEGACY */
double erand48(unsigned short[3]);
+char *fcvt(double, int, int *__restrict, int *__restrict); /* LEGACY */
+char *gcvt(double, int, char *); /* LEGACY */
+int getsubopt(char **, char * const *, char **);
+int grantpt(int);
+#if __DARWIN_UNIX03
+char *initstate(unsigned, char *, size_t); /* no __DARWIN_ALIAS needed */
+#else /* !__DARWIN_UNIX03 */
+char *initstate(unsigned long, char *, long);
+#endif /* __DARWIN_UNIX03 */
long jrand48(unsigned short[3]);
+char *l64a(long);
void lcong48(unsigned short[7]);
long lrand48(void);
+char *mktemp(char *);
+int mkstemp(char *);
long mrand48(void);
long nrand48(unsigned short[3]);
+int posix_openpt(int);
+char *ptsname(int);
+int putenv(char *) __DARWIN_ALIAS(putenv);
+long random(void);
+char *realpath(const char *, char *resolved_path);
unsigned short
*seed48(unsigned short[3]);
+int setenv(const char *, const char *, int) __DARWIN_ALIAS(setenv);
+#if __DARWIN_UNIX03
+void setkey(const char *) __DARWIN_ALIAS(setkey);
+#else /* !__DARWIN_UNIX03 */
+int setkey(const char *);
+#endif /* __DARWIN_UNIX03 */
+char *setstate(const char *);
void srand48(long);
+#if __DARWIN_UNIX03
+void srandom(unsigned);
+#else /* !__DARWIN_UNIX03 */
+void srandom(unsigned long);
+#endif /* __DARWIN_UNIX03 */
+int unlockpt(int);
+#if __DARWIN_UNIX03
+int unsetenv(const char *) __DARWIN_ALIAS(unsetenv);
+#else /* !__DARWIN_UNIX03 */
+void unsetenv(const char *);
+#endif /* __DARWIN_UNIX03 */
+#endif
+
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE)
+#include <machine/types.h>
+
+#ifndef _DEV_T
+typedef __darwin_dev_t dev_t;
+#define _DEV_T
+#endif
+
+#ifndef _MODE_T
+typedef __darwin_mode_t mode_t;
+#define _MODE_T
+#endif
+
+u_int32_t
+ arc4random(void);
+void arc4random_addrandom(unsigned char *dat, int datlen);
+void arc4random_stir(void);
/* getcap(3) functions */
char *cgetcap(char *, const char *, int);
int cgetustr(char *, const char *, char **);
int daemon(int, int);
-char *devname(int, int);
+char *devname(dev_t, mode_t);
+char *devname_r(dev_t, mode_t, char *buf, int len);
char *getbsize(int *, long *);
int getloadavg(double [], int);
const char
*getprogname(void);
-long a64l(const char *);
-char *l64a(long);
-
-/* int grantpt(int); */
int heapsort(void *, size_t, size_t,
int (*)(const void *, const void *));
-char *initstate(unsigned long, char *, long);
int mergesort(void *, size_t, size_t,
int (*)(const void *, const void *));
-/* int posix_openpt(int); */
-/* char *ptsname(int); */
void qsort_r(void *, size_t, size_t, void *,
int (*)(void *, const void *, const void *));
int radixsort(const unsigned char **, int, const unsigned char *,
void sranddev(void);
void srandomdev(void);
int rand_r(unsigned *);
-long random(void);
void *reallocf(void *, size_t);
-char *realpath(const char *, char resolved_path[]);
-char *setstate(char *);
-void srandom(unsigned long);
-/* int unlockpt(int); */
-#ifndef __STRICT_ANSI__
-typedef struct {
- long long quot;
- long long rem;
-} lldiv_t;
-
-long long
- atoll(const char *);
-long long
- llabs(long long);
-lldiv_t lldiv(long long, long long);
-long long
- strtoll(const char *, char **, int);
-unsigned long long
- strtoull(const char *, char **, int);
+#if !__DARWIN_NO_LONG_LONG
long long
strtoq(const char *, char **, int);
unsigned long long
strtouq(const char *, char **, int);
-#endif
-void unsetenv(const char *);
+#endif /* !__DARWIN_NO_LONG_LONG */
+extern char *suboptarg; /* getsubopt(3) external variable */
+void *valloc(size_t);
#endif
__END_DECLS
+#ifdef _USE_EXTENDED_LOCALES_
+#include <xlocale/_stdlib.h>
+#endif /* _USE_EXTENDED_LOCALES_ */
+
#endif /* _STDLIB_H_ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#ifndef _STRING_H_
#define _STRING_H_
-#include <machine/ansi.h>
+#include <_types.h>
+
+#ifndef _SIZE_T
+#define _SIZE_T
+typedef __darwin_size_t size_t;
+#endif
-#ifndef _BSD_SIZE_T_DEFINED_
-#define _BSD_SIZE_T_DEFINED_
-typedef _BSD_SIZE_T_ size_t;
+#ifndef _POSIX_C_SOURCE /* For swab */
+#ifndef _SSIZE_T
+#define _SSIZE_T
+typedef __darwin_ssize_t ssize_t;
#endif
+#endif /* ! _POSIX_C_SOURCE */
#ifndef NULL
-#ifdef __GNUG__
-#define NULL __null
-#else /* ! __GNUG__ */
-#ifndef __cplusplus
-#define NULL ((void *)0)
-#else /* __cplusplus */
-#define NULL 0
-#endif /* ! __cplusplus */
-#endif /* __GNUG__ */
+#define NULL __DARWIN_NULL
#endif /* ! NULL */
#include <sys/cdefs.h>
void *memcpy(void *, const void *, size_t);
void *memmove(void *, const void *, size_t);
void *memset(void *, int, size_t);
-#ifndef _POSIX_SOURCE
+#ifndef _POSIX_C_SOURCE
char *stpcpy(char *, const char *);
char *strcasestr(const char *, const char *);
-#endif /* !_POSIX_SOURCE */
+#endif /* !_POSIX_C_SOURCE */
char *strcat(char *, const char *);
char *strchr(const char *, int);
int strcmp(const char *, const char *);
char *strncat(char *, const char *, size_t);
int strncmp(const char *, const char *, size_t);
char *strncpy(char *, const char *, size_t);
-#ifndef _POSIX_SOURCE
+#ifndef _POSIX_C_SOURCE
char *strnstr(const char *, const char *, size_t);
-#endif /* !_POSIX_SOURCE */
+#endif /* !_POSIX_C_SOURCE */
char *strpbrk(const char *, const char *);
char *strrchr(const char *, int);
size_t strspn(const char *, const char *);
void *memccpy(void *, const void *, int, size_t);
char *strtok_r(char *, const char *, char **);
char *strdup(const char *);
-#ifndef _POSIX_SOURCE
+#ifndef _POSIX_C_SOURCE
int bcmp(const void *, const void *, size_t);
void bcopy(const void *, void *, size_t);
void bzero(void *, size_t);
int strncasecmp(const char *, const char *, size_t);
char *strsep(char **, const char *);
char *strsignal(int sig);
-void swab(const void *, void *, size_t);
-#endif /* !_POSIX_SOURCE */
+void swab(const void * __restrict, void * __restrict, ssize_t);
+#endif /* !_POSIX_C_SOURCE */
#endif /* !_ANSI_SOURCE */
__END_DECLS
+#ifdef _USE_EXTENDED_LOCALES_
+#include <xlocale/_string.h>
+#endif /* _USE_EXTENDED_LOCALES_ */
+
#endif /* _STRING_H_ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* @(#)strings.h 8.1 (Berkeley) 6/2/93
*/
+#if !defined(_XOPEN_SOURCE) && !defined(_POSIX_C_SOURCE)
+
#include <string.h>
+
+#else
+
+#include <_types.h>
+
+#ifndef _SIZE_T
+#define _SIZE_T
+typedef __darwin_size_t size_t;
+#endif
+
+int bcmp(const void *, const void *, size_t);
+void bcopy(const void *, void *, size_t);
+void bzero(void *, size_t);
+int ffs(int);
+char *index(const char *, int);
+char *rindex(const char *, int);
+int strcasecmp(const char *, const char *);
+int strncasecmp(const char *, const char *, size_t);
+
+#endif /* _POSIX_C_SOURCE */
+
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
-SYS_INSTHDRS += statvfs.h
+SYS_INSTHDRS += acl.h statvfs.h
SYS_INSTHDRS := ${SYS_INSTHDRS:S/^/${.CURDIR}\/include\/sys\//}
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef _SYS_ACL_H
+#define _SYS_ACL_H
+
+#include <sys/kauth.h>
+
+/*
+ * Implementation constants.
+ *
+ * The ACL_TYPE_EXTENDED binary format permits 169 entries plus
+ * the ACL header in a page. Give ourselves some room to grow;
+ * this limit is arbitrary.
+ */
+#define ACL_MAX_ENTRIES 128
+
+/* 23.2.2 Individual object access permissions - nonstandard */
+typedef enum {
+ ACL_READ_DATA = KAUTH_VNODE_READ_DATA,
+ ACL_LIST_DIRECTORY = KAUTH_VNODE_LIST_DIRECTORY,
+ ACL_WRITE_DATA = KAUTH_VNODE_WRITE_DATA,
+ ACL_ADD_FILE = KAUTH_VNODE_ADD_FILE,
+ ACL_EXECUTE = KAUTH_VNODE_EXECUTE,
+ ACL_SEARCH = KAUTH_VNODE_SEARCH,
+ ACL_DELETE = KAUTH_VNODE_DELETE,
+ ACL_APPEND_DATA = KAUTH_VNODE_APPEND_DATA,
+ ACL_ADD_SUBDIRECTORY = KAUTH_VNODE_ADD_SUBDIRECTORY,
+ ACL_DELETE_CHILD = KAUTH_VNODE_DELETE_CHILD,
+ ACL_READ_ATTRIBUTES = KAUTH_VNODE_READ_ATTRIBUTES,
+ ACL_WRITE_ATTRIBUTES = KAUTH_VNODE_WRITE_ATTRIBUTES,
+ ACL_READ_EXTATTRIBUTES = KAUTH_VNODE_READ_EXTATTRIBUTES,
+ ACL_WRITE_EXTATTRIBUTES = KAUTH_VNODE_WRITE_EXTATTRIBUTES,
+ ACL_READ_SECURITY = KAUTH_VNODE_READ_SECURITY,
+ ACL_WRITE_SECURITY = KAUTH_VNODE_WRITE_SECURITY,
+ ACL_CHANGE_OWNER = KAUTH_VNODE_CHANGE_OWNER
+} acl_perm_t;
+
+/* 23.2.5 ACL entry tag type bits - nonstandard */
+typedef enum {
+ ACL_UNDEFINED_TAG = 0,
+ ACL_EXTENDED_ALLOW = KAUTH_ACE_PERMIT,
+ ACL_EXTENDED_DENY = KAUTH_ACE_DENY
+} acl_tag_t;
+
+/* 23.2.6 Individual ACL types */
+typedef enum {
+ ACL_TYPE_EXTENDED = 0x00000100,
+/* Posix 1003.1e types - not supported */
+ ACL_TYPE_ACCESS = 0x00000000,
+ ACL_TYPE_DEFAULT = 0x00000001,
+/* The following types are defined on FreeBSD/Linux - not supported */
+ ACL_TYPE_AFS = 0x00000002,
+ ACL_TYPE_CODA = 0x00000003,
+ ACL_TYPE_NTFS = 0x00000004,
+ ACL_TYPE_NWFS = 0x00000005
+} acl_type_t;
+
+/* 23.2.7 ACL qualifier constants */
+
+#define ACL_UNDEFINED_ID NULL /* XXX ? */
+
+/* 23.2.8 ACL Entry Constants */
+typedef enum {
+ ACL_FIRST_ENTRY = 0,
+ ACL_NEXT_ENTRY = -1,
+ ACL_LAST_ENTRY = -2
+} acl_entry_id_t;
+
+/* nonstandard ACL / entry flags */
+typedef enum {
+ ACL_FLAG_DEFER_INHERIT = (1 << 0), /* tentative */
+ ACL_ENTRY_INHERITED = KAUTH_ACE_INHERITED,
+ ACL_ENTRY_FILE_INHERIT = KAUTH_ACE_FILE_INHERIT,
+ ACL_ENTRY_DIRECTORY_INHERIT = KAUTH_ACE_DIRECTORY_INHERIT,
+ ACL_ENTRY_LIMIT_INHERIT = KAUTH_ACE_LIMIT_INHERIT,
+ ACL_ENTRY_ONLY_INHERIT = KAUTH_ACE_ONLY_INHERIT
+} acl_flag_t;
+
+/* "External" ACL types */
+
+struct _acl;
+struct _acl_entry;
+struct _acl_permset;
+struct _acl_flagset;
+
+typedef struct _acl *acl_t;
+typedef struct _acl_entry *acl_entry_t;
+typedef struct _acl_permset *acl_permset_t;
+typedef struct _acl_flagset *acl_flagset_t;
+
+__BEGIN_DECLS
+/* 23.1.6.1 ACL Storage Management */
+extern acl_t acl_dup(acl_t acl);
+extern int acl_free(void *obj_p);
+extern acl_t acl_init(int count);
+
+/* 23.1.6.2 (1) ACL Entry manipulation */
+extern int acl_copy_entry(acl_entry_t dest_d, acl_entry_t src_d);
+extern int acl_create_entry(acl_t *acl_p, acl_entry_t *entry_p);
+extern int acl_create_entry_np(acl_t *acl_p, acl_entry_t *entry_p, int entry_index);
+extern int acl_delete_entry(acl_t acl, acl_entry_t entry_d);
+extern int acl_get_entry(acl_t acl, int entry_id, acl_entry_t *entry_p);
+extern int acl_valid(acl_t acl);
+extern int acl_valid_fd_np(int fd, acl_type_t type, acl_t acl);
+extern int acl_valid_file_np(const char *path, acl_type_t type, acl_t acl);
+extern int acl_valid_link_np(const char *path, acl_type_t type, acl_t acl);
+
+/* 23.1.6.2 (2) Manipulate permissions within an ACL entry */
+extern int acl_add_perm(acl_permset_t permset_d, acl_perm_t perm);
+extern int acl_calc_mask(acl_t *acl_p); /* not supported */
+extern int acl_clear_perms(acl_permset_t permset_d);
+extern int acl_delete_perm(acl_permset_t permset_d, acl_perm_t perm);
+extern int acl_get_perm_np(acl_permset_t permset_d, acl_perm_t perm);
+extern int acl_get_permset(acl_entry_t entry_d, acl_permset_t *permset_p);
+extern int acl_set_permset(acl_entry_t entry_d, acl_permset_t permset_d);
+
+/* nonstandard - manipulate flags on ACLs and entries */
+extern int acl_add_flag_np(acl_flagset_t flagset_d, acl_flag_t flag);
+extern int acl_clear_flags_np(acl_flagset_t flagset_d);
+extern int acl_delete_flag_np(acl_flagset_t flagset_d, acl_flag_t flag);
+extern int acl_get_flag_np(acl_flagset_t flagset_d, acl_flag_t flag);
+extern int acl_get_flagset_np(void *obj_p, acl_flagset_t *flagset_p);
+extern int acl_set_flagset_np(void *obj_p, acl_flagset_t flagset_d);
+
+/* 23.1.6.2 (3) Manipulate ACL entry tag type and qualifier */
+extern void *acl_get_qualifier(acl_entry_t entry_d);
+extern int acl_get_tag_type(acl_entry_t entry_d, acl_tag_t *tag_type_p);
+extern int acl_set_qualifier(acl_entry_t entry_d, const void *tag_qualifier_p);
+extern int acl_set_tag_type(acl_entry_t entry_d, acl_tag_t tag_type);
+
+/* 23.1.6.3 ACL manipulation on an Object */
+extern int acl_delete_def_file(const char *path_p); /* not supported */
+extern acl_t acl_get_fd(int fd);
+extern acl_t acl_get_fd_np(int fd, acl_type_t type);
+extern acl_t acl_get_file(const char *path_p, acl_type_t type);
+extern acl_t acl_get_link_np(const char *path_p, acl_type_t type);
+extern int acl_set_fd(int fd, acl_t acl);
+extern int acl_set_fd_np(int fd, acl_t acl, acl_type_t acl_type);
+extern int acl_set_file(const char *path_p, acl_type_t type, acl_t acl);
+extern int acl_set_link(const char *path_p, acl_type_t type, acl_t acl);
+
+/* 23.1.6.4 ACL Format translation */
+extern ssize_t acl_copy_ext(void *buf_p, acl_t acl, ssize_t size);
+extern acl_t acl_copy_int(const void *buf_p);
+extern acl_t acl_from_text(const char *buf_p);
+extern ssize_t acl_size(acl_t acl);
+extern char *acl_to_text(acl_t acl, ssize_t *len_p);
+__END_DECLS
+
+#endif _SYS_ACL_H
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#ifndef _SYS_STATVFS_H_
#define _SYS_STATVFS_H_
+#include <sys/_types.h>
#include <sys/cdefs.h>
-/* Following types need to be defined in <sys/types.h> as well */
-typedef unsigned int fsblkcnt_t;
-typedef unsigned int fsfilcnt_t;
+#ifndef _FSBLKCNT_T
+#define _FSBLKCNT_T
+typedef __darwin_fsblkcnt_t fsblkcnt_t;
+#endif
+
+#ifndef _FSFILCNT_T
+#define _FSFILCNT_T
+typedef __darwin_fsfilcnt_t fsfilcnt_t;
+#endif
/* Following structure is used as a statvfs/fstatvfs function parameter */
struct statvfs {
unsigned long f_bsize; /* File system block size */
unsigned long f_frsize; /* Fundamental file system block size */
- fsblkcnt_t f_blocks; /* Blocks on FS in units of f_frsize*/
+ fsblkcnt_t f_blocks; /* Blocks on FS in units of f_frsize */
fsblkcnt_t f_bfree; /* Free blocks */
fsblkcnt_t f_bavail; /* Blocks available to non-root */
fsfilcnt_t f_files; /* Total inodes */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#include <sys/termios.h>
#include <_types.h>
-#ifndef _PID_T_DECLARED
-typedef __osx_pid_t pid_t;
-#define _PID_T_DECLARED
+#ifndef _PID_T
+typedef __darwin_pid_t pid_t;
+#define _PID_T
#endif
__BEGIN_DECLS
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#ifndef _TIME_H_
#define _TIME_H_
-#include <machine/ansi.h>
+#include <_types.h>
#ifndef NULL
-#ifdef __GNUG__
-#define NULL __null
-#else /* ! __GNUG__ */
-#ifndef __cplusplus
-#define NULL ((void *)0)
-#else /* __cplusplus */
-#define NULL 0
-#endif /* ! __cplusplus */
-#endif /* __GNUG__ */
+#define NULL __DARWIN_NULL
#endif /* ! NULL */
-#ifndef _BSD_CLOCK_T_DEFINED_
-#define _BSD_CLOCK_T_DEFINED_
-typedef _BSD_CLOCK_T_ clock_t;
+#ifndef _CLOCK_T
+#define _CLOCK_T
+typedef __darwin_clock_t clock_t;
#endif
-#ifndef _BSD_TIME_T_DEFINED_
-#define _BSD_TIME_T_DEFINED_
-typedef _BSD_TIME_T_ time_t;
+#ifndef _SIZE_T
+#define _SIZE_T
+typedef __darwin_size_t size_t;
#endif
-#ifndef _BSD_SIZE_T_DEFINED_
-#define _BSD_SIZE_T_DEFINED_
-typedef _BSD_SIZE_T_ size_t;
+#ifndef _TIME_T
+#define _TIME_T
+typedef __darwin_time_t time_t;
#endif
-#ifndef _TIMESPEC_DECLARED
-#define _TIMESPEC_DECLARED
+#ifndef _TIMESPEC
+#define _TIMESPEC
struct timespec {
time_t tv_sec; /* seconds */
long tv_nsec; /* and nanoseconds */
char *tm_zone; /* timezone abbreviation */
};
-#include <machine/limits.h> /* Include file containing CLK_TCK. */
+#include <machine/_limits.h> /* Include file containing CLK_TCK. */
-#define CLOCKS_PER_SEC (CLK_TCK)
+#define CLOCKS_PER_SEC (__DARWIN_CLK_TCK)
#include <sys/cdefs.h>
extern char *tzname[];
#endif
+extern int getdate_err;
+#if __DARWIN_UNIX03
+extern long timezone __DARWIN_ALIAS(timezone);
+#endif /* __DARWIN_UNIX03 */
+extern int daylight;
+
__BEGIN_DECLS
char *asctime(const struct tm *);
clock_t clock(void);
char *ctime(const time_t *);
double difftime(time_t, time_t);
+struct tm *getdate(const char *);
struct tm *gmtime(const time_t *);
struct tm *localtime(const time_t *);
time_t mktime(struct tm *);
-size_t strftime(char *, size_t, const char *, const struct tm *);
+size_t strftime(char * __restrict, size_t, const char * __restrict, const struct tm * __restrict) __DARWIN_ALIAS(strftime);
+char *strptime(const char * __restrict, const char * __restrict, struct tm * __restrict);
time_t time(time_t *);
#ifndef _ANSI_SOURCE
void tzset(void);
#endif /* not ANSI */
-#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE)
char *asctime_r(const struct tm *, char *);
char *ctime_r(const time_t *, char *);
struct tm *gmtime_r(const time_t *, struct tm *);
struct tm *localtime_r(const time_t *, struct tm *);
time_t posix2time(time_t);
-char *strptime(const char *, const char *, struct tm *);
+#if !__DARWIN_UNIX03
char *timezone(int, int);
+#endif /* !__DARWIN_UNIX03 */
void tzsetwall(void);
time_t time2posix(time_t);
time_t timelocal(struct tm * const);
#endif /* neither ANSI nor POSIX */
#if !defined(_ANSI_SOURCE)
-int nanosleep(const struct timespec *, struct timespec *);
+int nanosleep(const struct timespec *, struct timespec *) __DARWIN_ALIAS(nanosleep);
#endif
__END_DECLS
+#ifdef _USE_EXTENDED_LOCALES_
+#include <xlocale/_time.h>
+#endif /* _USE_EXTENDED_LOCALES_ */
+
#endif /* !_TIME_H_ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
+++ /dev/null
-/*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-/*
- * Copyright (c) 1988, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Arthur David Olson of the National Cancer Institute.
- *
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- *
- * @(#)tzfile.h 8.1 (Berkeley) 6/2/93
- */
-
-#ifndef _TZFILE_H_
-#define _TZFILE_H_
-
-/*
- * Information about time zone files.
- */
- /* Time zone object file directory */
-#define TZDIR "/usr/share/zoneinfo"
-#define TZDEFAULT "/etc/localtime"
-#define TZDEFRULES "posixrules"
-
-/*
-** Each file begins with. . .
-*/
-
-struct tzhead {
- char tzh_reserved[24]; /* reserved for future use */
- char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */
- char tzh_leapcnt[4]; /* coded number of leap seconds */
- char tzh_timecnt[4]; /* coded number of transition times */
- char tzh_typecnt[4]; /* coded number of local time types */
- char tzh_charcnt[4]; /* coded number of abbr. chars */
-};
-
-/*
-** . . .followed by. . .
-**
-** tzh_timecnt (char [4])s coded transition times a la time(2)
-** tzh_timecnt (unsigned char)s types of local time starting at above
-** tzh_typecnt repetitions of
-** one (char [4]) coded GMT offset in seconds
-** one (unsigned char) used to set tm_isdst
-** one (unsigned char) that's an abbreviation list index
-** tzh_charcnt (char)s '\0'-terminated zone abbreviations
-** tzh_leapcnt repetitions of
-** one (char [4]) coded leap second transition times
-** one (char [4]) total correction after above
-** tzh_ttisstdcnt (char)s indexed by type; if TRUE, transition
-** time is standard time, if FALSE,
-** transition time is wall clock time
-** if absent, transition times are
-** assumed to be wall clock time
-*/
-
-/*
-** In the current implementation, "tzset()" refuses to deal with files that
-** exceed any of the limits below.
-*/
-
-/*
-** The TZ_MAX_TIMES value below is enough to handle a bit more than a
-** year's worth of solar time (corrected daily to the nearest second) or
-** 138 years of Pacific Presidential Election time
-** (where there are three time zone transitions every fourth year).
-*/
-#define TZ_MAX_TIMES 370
-
-#define NOSOLAR /* 4BSD doesn't currently handle solar time */
-
-#ifndef NOSOLAR
-#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */
-#else
-#define TZ_MAX_TYPES 20 /* Maximum number of local time types */
-#endif
-
-#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */
-
-#define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */
-
-#define SECSPERMIN 60
-#define MINSPERHOUR 60
-#define HOURSPERDAY 24
-#define DAYSPERWEEK 7
-#define DAYSPERNYEAR 365
-#define DAYSPERLYEAR 366
-#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
-#define SECSPERDAY ((long) SECSPERHOUR * HOURSPERDAY)
-#define MONSPERYEAR 12
-
-#define TM_SUNDAY 0
-#define TM_MONDAY 1
-#define TM_TUESDAY 2
-#define TM_WEDNESDAY 3
-#define TM_THURSDAY 4
-#define TM_FRIDAY 5
-#define TM_SATURDAY 6
-
-#define TM_JANUARY 0
-#define TM_FEBRUARY 1
-#define TM_MARCH 2
-#define TM_APRIL 3
-#define TM_MAY 4
-#define TM_JUNE 5
-#define TM_JULY 6
-#define TM_AUGUST 7
-#define TM_SEPTEMBER 8
-#define TM_OCTOBER 9
-#define TM_NOVEMBER 10
-#define TM_DECEMBER 11
-
-#define TM_YEAR_BASE 1900
-
-#define EPOCH_YEAR 1970
-#define EPOCH_WDAY TM_THURSDAY
-
-/*
-** Accurate only for the past couple of centuries;
-** that will probably do.
-*/
-
-#define isleap(y) (((y) % 4) == 0 && ((y) % 100) != 0 || ((y) % 400) == 0)
-
-#endif /* !_TZFILE_H_ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#ifndef _UNISTD_H_
#define _UNISTD_H_
+#include <_types.h>
+
#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <sys/unistd.h> /* XXX needs to go away */
+#include <sys/unistd.h>
+#ifndef _GID_T
+#define _GID_T
+typedef __darwin_gid_t gid_t;
+#endif
-#define STDIN_FILENO 0 /* standard input file descriptor */
-#define STDOUT_FILENO 1 /* standard output file descriptor */
-#define STDERR_FILENO 2 /* standard error file descriptor */
+#ifndef _INTPTR_T
+#define _INTPTR_T
+typedef __darwin_intptr_t intptr_t;
+#endif
-#ifndef NULL
-#ifdef __GNUG__
-#define NULL __null
-#else /* ! __GNUG__ */
-#ifndef __cplusplus
-#define NULL ((void *)0)
-#else /* __cplusplus */
-#define NULL 0
-#endif /* ! __cplusplus */
-#endif /* __GNUG__ */
-#endif /* ! NULL */
+#ifndef _OFF_T
+#define _OFF_T
+typedef __darwin_off_t off_t;
+#endif
-#ifdef _POSIX_VERSION /* XXX <sys/unistd.h> */
-#undef _POSIX_VERSION
+#ifndef _PID_T
+#define _PID_T
+typedef __darwin_pid_t pid_t;
#endif
-#ifdef _POSIX2_VERSION /* XXX <sys/unistd.h> */
-#undef _POSIX2_VERSION
+
+#ifndef _SIZE_T
+#define _SIZE_T
+/* DO NOT REMOVE THIS COMMENT: fixincludes needs to see:
+ * _GCC_SIZE_T */
+typedef __darwin_size_t size_t;
#endif
-#ifdef _POSIX_CHOWN_RESTRICTED /* XXX <sys/unistd.h> */
-#undef _POSIX_CHOWN_RESTRICTED
+
+#ifndef _SSIZE_T
+#define _SSIZE_T
+typedef __darwin_ssize_t ssize_t;
#endif
-#ifdef _POSIX_NO_TRUNC /* XXX <sys/unistd.h> */
-#undef _POSIX_NO_TRUNC
+
+#ifndef _UID_T
+#define _UID_T
+typedef __darwin_uid_t uid_t; /* user id */
#endif
-/* Version test macros */
-#define _POSIX_VERSION 200112L
-#define _POSIX2_VERSION 200112L
+#ifndef _USECONDS_T
+#define _USECONDS_T
+typedef __darwin_useconds_t useconds_t;
+#endif
+#ifndef _POSIX_C_SOURCE
+#ifndef _UUID_T
+#define _UUID_T
+typedef __darwin_uuid_t uuid_t;
+#endif /* _UUID_T */
+#endif /* _POSIX_C_SOURCE */
+
+#define STDIN_FILENO 0 /* standard input file descriptor */
+#define STDOUT_FILENO 1 /* standard output file descriptor */
+#define STDERR_FILENO 2 /* standard error file descriptor */
+
+#ifndef NULL
+#define NULL __DARWIN_NULL
+#endif /* ! NULL */
+
+/* Version test macros */
+/* _POSIX_VERSION and _POSIX2_VERSION from sys/unistd.h */
#define _XOPEN_VERSION 600 /* [XSI] */
#define _XOPEN_XCU_VERSION 4 /* Older standard */
/* Please keep this list in the same order as the applicable standard */
#define _POSIX_ADVISORY_INFO (-1) /* [ADV] */
-#define _POSIX_ASYNCHRONOUS_IO 200112L /* [AIO] */
+#define _POSIX_ASYNCHRONOUS_IO (-1) /* [AIO] */
#define _POSIX_BARRIERS (-1) /* [BAR] */
#define _POSIX_CHOWN_RESTRICTED 200112L
#define _POSIX_CLOCK_SELECTION (-1) /* [CS] */
#define _POSIX_CPUTIME (-1) /* [CPT] */
-#define _POSIX_FSYNC 200112L /* [FSC] */
+#define _POSIX_FSYNC (-1) /* [FSC] */
#define _POSIX_IPV6 200112L
#define _POSIX_JOB_CONTROL 200112L
#define _POSIX_MAPPED_FILES 200112L /* [MF] */
-#define _POSIX_MEMLOCK 200112L /* [ML] */
-#define _POSIX_MEMLOCK_RANGE 200112L /* [MR] */
+#define _POSIX_MEMLOCK (-1) /* [ML] */
+#define _POSIX_MEMLOCK_RANGE (-1) /* [MR] */
#define _POSIX_MEMORY_PROTECTION 200112L /* [MPR] */
#define _POSIX_MESSAGE_PASSING (-1) /* [MSG] */
#define _POSIX_MONOTONIC_CLOCK (-1) /* [MON] */
#define _POSIX_NO_TRUNC 200112L
#define _POSIX_PRIORITIZED_IO (-1) /* [PIO] */
#define _POSIX_PRIORITY_SCHEDULING (-1) /* [PS] */
-#define _POSIX_RAW_SOCKETS 200112L /* [RS] */
+#define _POSIX_RAW_SOCKETS (-1) /* [RS] */
#define _POSIX_READER_WRITER_LOCKS 200112L /* [THR] */
#define _POSIX_REALTIME_SIGNALS (-1) /* [RTS] */
#define _POSIX_REGEXP 200112L
-#define _POSIX_SAVED_IDS (-1) /* XXX required */
-#define _POSIX_SEMAPHORES 200112L /* [SEM] */
-#define _POSIX_SHARED_MEMORY_OBJECTS 200112L /* [SHM] */
+#define _POSIX_SAVED_IDS 200112L /* XXX required */
+#define _POSIX_SEMAPHORES (-1) /* [SEM] */
+#define _POSIX_SHARED_MEMORY_OBJECTS (-1) /* [SHM] */
#define _POSIX_SHELL 200112L
#define _POSIX_SPAWN (-1) /* [SPN] */
#define _POSIX_SPIN_LOCKS (-1) /* [SPI] */
#define _POSIX_SPORADIC_SERVER (-1) /* [SS] */
-#define _POSIX_SYNCHRONIZED_IO 200112L /* [SIO] */
+#define _POSIX_SYNCHRONIZED_IO (-1) /* [SIO] */
#define _POSIX_THREAD_ATTR_STACKADDR 200112L /* [TSA] */
#define _POSIX_THREAD_ATTR_STACKSIZE 200112L /* [TSS] */
#define _POSIX_THREAD_CPUTIME (-1) /* [TCT] */
#define _POSIX_THREAD_PRIO_INHERIT (-1) /* [TPI] */
#define _POSIX_THREAD_PRIO_PROTECT (-1) /* [TPP] */
#define _POSIX_THREAD_PRIORITY_SCHEDULING (-1) /* [TPS] */
-#define _POSIX_THREAD_PROCESS_SHARED 200112L /* [TSH] */
+#define _POSIX_THREAD_PROCESS_SHARED (-1) /* [TSH] */
#define _POSIX_THREAD_SAFE_FUNCTIONS 200112L /* [TSF] */
#define _POSIX_THREAD_SPORADIC_SERVER (-1) /* [TSP] */
#define _POSIX_THREADS 200112L /* [THR] */
#endif /* _POSIX_VDISABLE */
#define _POSIX2_C_BIND 200112L
-#define _POSIX2_C_DEV (-1) /* c99 command */
+#define _POSIX2_C_DEV 200112L /* c99 command */
#define _POSIX2_CHAR_TERM 200112L
#define _POSIX2_FORT_DEV (-1) /* fort77 command */
#define _POSIX2_FORT_RUN 200112L
-#define _POSIX2_LOCALEDEF (-1) /* localedef command */
+#define _POSIX2_LOCALEDEF 200112L /* localedef command */
#define _POSIX2_PBS (-1)
#define _POSIX2_PBS_ACCOUNTING (-1)
#define _POSIX2_PBS_CHECKPOINT (-1)
#define _POSIX2_UPE 200112L /* XXXX no fc, newgrp, tabs */
#define _V6_ILP32_OFF32 (-1)
-#define _V6_ILP32_OFFBIG 0
-#define _V6_LP64_OFF64 0
-#define _V6_LPBIG_OFFBIG (-1)
+#define _V6_ILP32_OFFBIG (1)
+#define _V6_LP64_OFF64 (1)
+#define _V6_LPBIG_OFFBIG (1)
#define _XBS5_ILP32_OFF32 _V6_ILP32_OFF32 /* legacy */
#define _XBS5_ILP32_OFFBIG _V6_ILP32_OFFBIG /* legacy */
#define _XOPEN_UNIX (1)
-#ifndef _POSIX_SOURCE
#define F_ULOCK 0 /* unlock locked section */
#define F_LOCK 1 /* lock a section for exclusive use */
#define F_TLOCK 2 /* test and lock a section for exclusive use */
#define F_TEST 3 /* test a section for locks by other procs */
-#endif
/* configurable system variables */
#define _SC_ARG_MAX 1
#define _SC_XOPEN_REALTIME 111
#define _SC_XOPEN_REALTIME_THREADS 112
#define _SC_XOPEN_SHM 113
-#define _SC_XOPEN_STREAMS (-1) /* 114 - Not supported */
+#define _SC_XOPEN_STREAMS 114
#define _SC_XOPEN_UNIX 115
#define _SC_XOPEN_VERSION 116
#define _SC_XOPEN_XCU_VERSION 121
#define _CS_XBS5_LPBIG_OFFBIG_LIBS 34
#define _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS 35
-
__BEGIN_DECLS
-void _Exit(int) __dead2;
void _exit(int) __dead2;
int access(const char *, int);
-unsigned int alarm(unsigned int);
+unsigned int
+ alarm(unsigned int);
int chdir(const char *);
int chown(const char *, uid_t, gid_t);
int close(int);
size_t confstr(int, char *, size_t);
+char *crypt(const char *, const char *);
+char *ctermid(char *);
int dup(int);
int dup2(int, int);
int execl(const char *, const char *, ...);
int execv(const char *, char * const *);
int execve(const char *, char * const *, char * const *);
int execvp(const char *, char * const *);
+int fchown(int, uid_t, gid_t);
+int fchdir(int);
pid_t fork(void);
long fpathconf(int, int);
+int ftruncate(int, off_t);
char *getcwd(char *, size_t);
-int getdomainname(char *, int);
gid_t getegid(void);
uid_t geteuid(void);
gid_t getgid(void);
int getgroups(int, gid_t []);
+long gethostid(void);
+int gethostname(char *, size_t);
char *getlogin(void);
-int getlogin_r(char *, int);
+int getlogin_r(char *, size_t);
+int getopt(int, char * const [], const char *);
+pid_t getpgid(pid_t);
pid_t getpgrp(void);
pid_t getpid(void);
pid_t getppid(void);
+pid_t getsid(pid_t);
uid_t getuid(void);
+char *getwd(char *); /* obsoleted by getcwd() */
int isatty(int);
-int lchown(const char *, uid_t, gid_t);
+int lchown(const char *, uid_t, gid_t) __DARWIN_ALIAS(lchown);
int link(const char *, const char *);
+int lockf(int, int, off_t);
off_t lseek(int, off_t, int);
+int nice(int);
long pathconf(const char *, int);
int pause(void);
-int pipe(int *);
+int pipe(int [2]);
+ssize_t pread(int, void *, size_t, off_t);
+ssize_t pwrite(int, const void *, size_t, off_t);
ssize_t read(int, void *, size_t);
+ssize_t readlink(const char * __restrict, char * __restrict, size_t);
int rmdir(const char *);
-int setdomainname(const char *, int);
+int setegid(gid_t);
+int seteuid(uid_t);
int setgid(gid_t);
int setpgid(pid_t, pid_t);
+#if __DARWIN_UNIX03
+pid_t setpgrp(void) __DARWIN_ALIAS(setpgrp);
+#else /* !__DARWIN_UNIX03 */
+int setpgrp(pid_t pid, pid_t pgrp); /* obsoleted by setpgid() */
+#endif /* __DARWIN_UNIX03 */
+int setregid(gid_t, gid_t);
+int setreuid(uid_t, uid_t);
pid_t setsid(void);
int setuid(uid_t);
-unsigned int sleep(unsigned int);
+unsigned int
+ sleep(unsigned int);
+void swab(const void * __restrict, void * __restrict, ssize_t);
+int symlink(const char *, const char *);
+void sync(void);
long sysconf(int);
pid_t tcgetpgrp(int);
int tcsetpgrp(int, pid_t);
+int truncate(const char *, off_t);
char *ttyname(int);
+#if __DARWIN_UNIX03
+int ttyname_r(int, char *, size_t) __DARWIN_ALIAS(ttyname_r);
+#else /* !__DARWIN_UNIX03 */
char *ttyname_r(int, char *, size_t);
+#endif /* __DARWIN_UNIX03 */
+useconds_t
+ ualarm(useconds_t, useconds_t);
int unlink(const char *);
+int usleep(useconds_t);
+pid_t vfork(void);
ssize_t write(int, const void *, size_t);
extern char *optarg; /* getopt(3) external variables */
-extern int optind, opterr, optopt, optreset;
-int getopt(int, char * const [], const char *);
+extern int optind, opterr, optopt;
-#ifndef _POSIX_SOURCE
-#ifdef __STDC__
-struct timespec; /* pselect(3) */
-struct timeval; /* select(2) */
-#endif
+#ifndef _POSIX_C_SOURCE
+#include <sys/select.h>
+
+void _Exit(int) __dead2;
+int accessx_np(const struct accessx_descriptor *, size_t, int *, uid_t);
int acct(const char *);
+int add_profil(char *, size_t, unsigned long, unsigned int);
int async_daemon(void);
-char *brk(const char *);
+void *brk(const void *);
int chroot(const char *);
-char *crypt(const char *, const char *);
-void encrypt(char *, int);
+#if __DARWIN_UNIX03
+void encrypt(char *, int) __DARWIN_ALIAS(encrypt);
+#else /* !__DARWIN_UNIX03 */
+int encrypt(char *, int);
+#endif /* __DARWIN_UNIX03 */
void endusershell(void);
-int fchdir(int);
-int fchown(int, int, int);
-char *fflagstostr(u_long);
+int execvP(const char *, const char *, char * const *);
+char *fflagstostr(unsigned long);
int fsync(int);
-int ftruncate(int, off_t);
int getdtablesize(void);
+int getdomainname(char *, int);
int getgrouplist(const char *, int, int *, int *);
-long gethostid(void);
-int gethostname(char *, int);
mode_t getmode(const void *, mode_t);
int getpagesize(void) __pure2;
char *getpass(const char *);
int getpeereid(int, uid_t *, gid_t *);
int getpgid(pid_t _pid);
+int getsgroups_np(int *, uuid_t);
int getsid(pid_t _pid);
char *getusershell(void);
-char *getwd(char *); /* obsoleted by getcwd() */
-int lockf(int, int, off_t);
+int getwgroups_np(int *, uuid_t);
int initgroups(const char *, int);
int iruserok(unsigned long, int, const char *, const char *);
int issetugid(void);
int mkstemps(char *, int);
char *mktemp(char *);
int nfssvc(int, void *);
-int nice(int);
-ssize_t pread(int, void *, size_t, off_t);
-#if 0
-void psignal(unsigned int, const char *);
-extern __const char *__const sys_siglist[];
-#else
-#include <signal.h>
-#endif
-int profil(char *, int, int, int);
-#ifndef __MWERKS__
-int pselect(int, fd_set *, fd_set *, fd_set *,
- const struct timespec *, const sigset_t *);
-#endif /* ! __MWERKS__ */
-ssize_t pwrite(int, const void *, size_t, off_t);
+int profil(char *, size_t, unsigned long, unsigned int);
+int pthread_setugid_np(uid_t, gid_t);
+int pthread_getugid_np( uid_t *, gid_t *);
int rcmd(char **, int, const char *, const char *, const char *, int *);
-int readlink(const char *, char *, int);
int reboot(int);
int revoke(const char *);
int rresvport(int *);
int rresvport_af(int *, int);
int ruserok(const char *, int, const char *, const char *);
-char *sbrk(int);
-int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
-int setegid(gid_t);
-int seteuid(uid_t);
+void *sbrk(int);
+int setdomainname(const char *, int);
int setgroups(int, const gid_t *);
void sethostid(long);
int sethostname(const char *, int);
-void setkey(const char *);
+#if __DARWIN_UNIX03
+void setkey(const char *) __DARWIN_ALIAS(setkey);
+#else /* !__DARWIN_UNIX03 */
+int setkey(const char *);
+#endif /* __DARWIN_UNIX03 */
int setlogin(const char *);
void *setmode(const char *);
-int setpgrp(pid_t pid, pid_t pgrp); /* obsoleted by setpgid() */
-int setregid(gid_t, gid_t);
-int setreuid(uid_t, uid_t);
int setrgid(gid_t);
int setruid(uid_t);
+int setsgroups_np(int, const uuid_t);
void setusershell(void);
-int strtofflags(char **, u_long *, u_long *);
+int setwgroups_np(int, const uuid_t);
+int strtofflags(char **, unsigned long *, unsigned long *);
int swapon(const char *);
-int symlink(const char *, const char *);
-void sync(void);
int syscall(int, ...);
-int truncate(const char *, off_t);
int ttyslot(void);
-unsigned int ualarm(unsigned int, unsigned int);
int undelete(const char *);
int unwhiteout(const char *);
-int usleep(unsigned int);
void *valloc(size_t);
-pid_t vfork(void);
extern char *suboptarg; /* getsubopt(3) external variable */
int getsubopt(char **, char * const *, char **);
/* HFS & HFS Plus semantics system calls go here */
#ifdef __LP64__
-int getattrlist(const char*,void*,void*,size_t,unsigned int);
-int setattrlist(const char*,void*,void*,size_t,unsigned int);
+int getattrlist(const char*,void*,void*,size_t,unsigned int) __DARWIN_ALIAS(getattrlist);
+int setattrlist(const char*,void*,void*,size_t,unsigned int) __DARWIN_ALIAS(setattrlist);
int exchangedata(const char*,const char*,unsigned int);
int checkuseraccess(const char*,uid_t,gid_t*,int,int,unsigned int);
int getdirentriesattr(int,void*,void*,size_t,unsigned int*,unsigned int*,unsigned int*,unsigned int);
int fsctl(const char *,unsigned int,void*,unsigned int);
#else /* __LP64__ */
-int getattrlist(const char*,void*,void*,size_t,unsigned long);
-int setattrlist(const char*,void*,void*,size_t,unsigned long);
+int getattrlist(const char*,void*,void*,size_t,unsigned long) __DARWIN_ALIAS(getattrlist);
+int setattrlist(const char*,void*,void*,size_t,unsigned long) __DARWIN_ALIAS(setattrlist);
int exchangedata(const char*,const char*,unsigned long);
int checkuseraccess(const char*,uid_t,gid_t*,int,int,unsigned long);
int getdirentriesattr(int,void*,void*,size_t,unsigned long*,unsigned long*,unsigned long*,unsigned long);
int fsctl(const char *,unsigned long,void*,unsigned long);
#endif /* __LP64__ */
-#endif /* !_POSIX_SOURCE */
+extern int optreset;
+
+#endif /* !_POSIX_C_SOURCE */
__END_DECLS
#endif /* !_UNISTD_H_ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#ifndef _UTIME_H_
#define _UTIME_H_
+#include <_types.h>
+
+#ifndef _TIME_T
+#define _TIME_T
+typedef __darwin_time_t time_t;
+#endif /* _TIME_T */
+
struct utimbuf {
time_t actime; /* Access time */
time_t modtime; /* Modification time */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+/* This file is public domain. */
+/* GCC uses its own copy of this header */
+#if defined(__GNUC__)
+#include_next <varargs.h>
+#elif defined(__MWERKS__)
+#include "mw_varargs.h"
+#else
+#error "This header only supports __MWERKS__."
+#endif
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#ifndef _VIS_H_
#define _VIS_H_
+#include <_types.h>
+
+#ifndef _SIZE_T
+#define _SIZE_T
+typedef __darwin_size_t size_t;
+#endif
+
/*
* to select alternate encoding format
*/
#define VIS_OCTAL 0x01 /* use octal \ddd format */
-#define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropiate */
+#define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropriate */
/*
* to alter set of characters encoded (default is to encode all
*/
#define VIS_NOSLASH 0x40 /* inhibit printing '\' */
#define VIS_HTTPSTYLE 0x80 /* http-style escape % HEX HEX */
+#define VIS_GLOB 0x100 /* encode glob(3) magics */
/*
* unvis return codes
#include <sys/cdefs.h>
#include <_types.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <time.h>
#ifndef NULL
-#define NULL __OSX_NULL
+#define NULL __DARWIN_NULL
#endif /* ! NULL */
-#ifndef _BSD_SIZE_T_DEFINED_
-#define _BSD_SIZE_T_DEFINED_
-typedef __osx_size_t size_t;
+#ifndef _SIZE_T
+#define _SIZE_T
+typedef __darwin_size_t size_t;
#endif
-#ifndef _BSD_MBSTATE_T_DEFINED_
-#define _BSD_MBSTATE_T_DEFINED_
-typedef __osx_mbstate_t mbstate_t;
+#ifndef _MBSTATE_T
+#define _MBSTATE_T
+typedef __darwin_mbstate_t mbstate_t;
#endif
-#ifndef _BSD_CT_RUNE_T_DEFINED_
-#define _BSD_CT_RUNE_T_DEFINED_
-typedef __osx_ct_rune_t ct_rune_t;
+#ifndef _CT_RUNE_T
+#define _CT_RUNE_T
+typedef __darwin_ct_rune_t ct_rune_t;
#endif
-#ifndef _BSD_RUNE_T_DEFINED_
-#define _BSD_RUNE_T_DEFINED_
-typedef __osx_rune_t rune_t;
+#ifndef _RUNE_T
+#define _RUNE_T
+typedef __darwin_rune_t rune_t;
#endif
#ifndef __cplusplus
-#ifndef _BSD_WCHAR_T_DEFINED_
-#define _BSD_WCHAR_T_DEFINED_
-typedef __osx_wchar_t wchar_t;
-#endif /* _BSD_WCHAR_T_DEFINED_ */
+#ifndef _WCHAR_T
+#define _WCHAR_T
+typedef __darwin_wchar_t wchar_t;
+#endif /* _WCHAR_T */
#endif /* __cplusplus */
-#ifndef _WCTYPE_T_DEFINED_
-#define _WCTYPE_T_DEFINED_
-typedef __osx_wctype_t wctype_t;
-#endif
-
-#ifndef _BSD_WINT_T_DEFINED_
-#define _BSD_WINT_T_DEFINED_
-typedef __osx_wint_t wint_t;
-#endif
-
-#ifndef WEOF
-#define WEOF __OSX_WEOF
-#endif
-
#ifndef WCHAR_MIN
-#define WCHAR_MIN __OSX_WCHAR_MIN
+#define WCHAR_MIN __DARWIN_WCHAR_MIN
#endif
#ifndef WCHAR_MAX
-#define WCHAR_MAX __OSX_WCHAR_MAX
+#define WCHAR_MAX __DARWIN_WCHAR_MAX
#endif
+#include <stdarg.h>
+#include <stdio.h>
+#include <time.h>
+#include <_wctype.h>
+
__BEGIN_DECLS
wint_t btowc(int);
wint_t fgetwc(FILE *);
wint_t fputwc(wchar_t, FILE *);
int fputws(const wchar_t * __restrict, FILE * __restrict);
int fwide(FILE *, int);
-int fwprintf(FILE * __restrict, const wchar_t * __restrict, ...);
-int fwscanf(FILE * __restrict, const wchar_t * __restrict, ...);
+int fwprintf(FILE * __restrict, const wchar_t * __restrict, ...) __DARWIN_LDBL_COMPAT(fwprintf);
+int fwscanf(FILE * __restrict, const wchar_t * __restrict, ...) __DARWIN_LDBL_COMPAT(fwscanf);
wint_t getwc(FILE *);
wint_t getwchar(void);
-int iswalnum(wint_t);
-int iswalpha(wint_t);
-int iswcntrl(wint_t);
-int iswctype(wint_t, wctype_t);
-int iswdigit(wint_t);
-int iswgraph(wint_t);
-int iswlower(wint_t);
-int iswprint(wint_t);
-int iswpunct(wint_t);
-int iswspace(wint_t);
-int iswupper(wint_t);
-int iswxdigit(wint_t);
size_t mbrlen(const char * __restrict, size_t, mbstate_t * __restrict);
size_t mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
mbstate_t * __restrict);
wint_t putwc(wchar_t, FILE *);
wint_t putwchar(wchar_t);
int swprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict,
- ...);
-int swscanf(const wchar_t * __restrict, const wchar_t * __restrict, ...);
-wint_t towlower(wint_t);
-wint_t towupper(wint_t);
+ ...) __DARWIN_LDBL_COMPAT(swprintf);
+int swscanf(const wchar_t * __restrict, const wchar_t * __restrict, ...) __DARWIN_LDBL_COMPAT(swscanf);
wint_t ungetwc(wint_t, FILE *);
int vfwprintf(FILE * __restrict, const wchar_t * __restrict,
- _BSD_VA_LIST_);
+ __darwin_va_list) __DARWIN_LDBL_COMPAT(vfwprintf);
int vswprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict,
- _BSD_VA_LIST_);
-int vwprintf(const wchar_t * __restrict, _BSD_VA_LIST_);
+ __darwin_va_list) __DARWIN_LDBL_COMPAT(vswprintf);
+int vwprintf(const wchar_t * __restrict, __darwin_va_list) __DARWIN_LDBL_COMPAT(vwprintf);
size_t wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
wchar_t *wcscat(wchar_t * __restrict, const wchar_t * __restrict);
wchar_t *wcschr(const wchar_t *, wchar_t);
long wcstol(const wchar_t * __restrict, wchar_t ** __restrict, int);
unsigned long
wcstoul(const wchar_t * __restrict, wchar_t ** __restrict, int);
-wctype_t
- wctype(const char *);
wchar_t *wmemchr(const wchar_t *, wchar_t, size_t);
int wmemcmp(const wchar_t *, const wchar_t *, size_t);
wchar_t *wmemcpy(wchar_t * __restrict, const wchar_t * __restrict, size_t);
wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t);
wchar_t *wmemset(wchar_t *, wchar_t, size_t);
-int wprintf(const wchar_t * __restrict, ...);
-int wscanf(const wchar_t * __restrict, ...);
+int wprintf(const wchar_t * __restrict, ...) __DARWIN_LDBL_COMPAT(wprintf);
+int wscanf(const wchar_t * __restrict, ...) __DARWIN_LDBL_COMPAT(wscanf);
#if !defined(_ANSI_SOURCE)
int vfwscanf(FILE * __restrict, const wchar_t * __restrict,
- _BSD_VA_LIST_);
+ __darwin_va_list) __DARWIN_LDBL_COMPAT(vfwscanf);
int vswscanf(const wchar_t * __restrict, const wchar_t * __restrict,
- _BSD_VA_LIST_);
-int vwscanf(const wchar_t * __restrict, _BSD_VA_LIST_);
+ __darwin_va_list) __DARWIN_LDBL_COMPAT(vswscanf);
+int vwscanf(const wchar_t * __restrict, __darwin_va_list) __DARWIN_LDBL_COMPAT(vwscanf);
float wcstof(const wchar_t * __restrict, wchar_t ** __restrict);
long double
- wcstold(const wchar_t * __restrict, wchar_t ** __restrict);
+ wcstold(const wchar_t * __restrict, wchar_t ** __restrict) __DARWIN_LDBL_COMPAT(wcstold);
+#if !__DARWIN_NO_LONG_LONG
long long
wcstoll(const wchar_t * __restrict, wchar_t ** __restrict, int);
unsigned long long
wcstoull(const wchar_t * __restrict, wchar_t ** __restrict, int);
+#endif /* !__DARWIN_NO_LONG_LONG */
int wcswidth(const wchar_t *, size_t);
int wcwidth(wchar_t);
+#endif /* !defined(_ANSI_SOURCE) */
+
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE)
+size_t mbsnrtowcs(wchar_t * __restrict, const char ** __restrict, size_t,
+ size_t, mbstate_t * __restrict);
size_t wcslcat(wchar_t *, const wchar_t *, size_t);
size_t wcslcpy(wchar_t *, const wchar_t *, size_t);
-#endif /* !defined(_ANSI_SOURCE) */
+size_t wcsnrtombs(char * __restrict, const wchar_t ** __restrict, size_t,
+ size_t, mbstate_t * __restrict);
+#endif /* !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) */
__END_DECLS
+#ifdef _USE_EXTENDED_LOCALES_
+#include <xlocale/_wchar.h>
+#endif /* _USE_EXTENDED_LOCALES_ */
+
#endif /* !_WCHAR_H_ */
#include <sys/cdefs.h>
#include <_types.h>
-#include <ctype.h>
-
-#ifndef _BSD_CT_RUNE_T_DEFINED_
-#define _BSD_CT_RUNE_T_DEFINED_
-typedef __osx_ct_rune_t ct_rune_t;
-#endif
-
-#ifndef _BSD_RUNE_T_DEFINED_
-#define _BSD_RUNE_T_DEFINED_
-typedef __osx_rune_t rune_t;
-#endif
-
-#ifndef __cplusplus
-#ifndef _BSD_WCHAR_T_DEFINED_
-#define _BSD_WCHAR_T_DEFINED_
-typedef __osx_wchar_t wchar_t;
-#endif /* _BSD_WCHAR_T_DEFINED_ */
-#endif /* __cplusplus */
-
-#ifndef _BSD_WINT_T_DEFINED_
-#define _BSD_WINT_T_DEFINED_
-typedef __osx_wint_t wint_t;
-#endif
-#ifndef _WCTRANS_T_DEFINED_
-#define _WCTRANS_T_DEFINED_
-typedef __osx_wctrans_t wctrans_t;
+#ifndef _WCTRANS_T
+#define _WCTRANS_T
+typedef __darwin_wctrans_t wctrans_t;
#endif
-#ifndef _WCTYPE_T_DEFINED_
-#define _WCTYPE_T_DEFINED_
-typedef __osx_wctype_t wctype_t;
-#endif
-
-#ifndef WEOF
-#define WEOF __OSX_WEOF
-#endif
+#include <_wctype.h>
+#include <ctype.h>
__BEGIN_DECLS
-int iswalnum(wint_t);
-int iswalpha(wint_t);
int iswblank(wint_t);
-int iswcntrl(wint_t);
-int iswctype(wint_t, wctype_t);
-int iswdigit(wint_t);
-int iswgraph(wint_t);
-int iswlower(wint_t);
-int iswprint(wint_t);
-int iswpunct(wint_t);
-int iswspace(wint_t);
-int iswupper(wint_t);
-int iswxdigit(wint_t);
wint_t towctrans(wint_t, wctrans_t);
-wint_t towlower(wint_t);
-wint_t towupper(wint_t);
wctrans_t
wctrans(const char *);
-wctype_t
- wctype(const char *);
#if !defined(_ANSI_SOURCE)
wint_t iswascii(wint_t);
wint_t iswrune(wint_t);
wint_t iswspecial(wint_t);
#endif
+
+#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE)
+wint_t nextwctype(wint_t, wctype_t);
+#endif
__END_DECLS
-#define iswalnum(wc) __istype((wc), _CTYPE_A|_CTYPE_D)
-#define iswalpha(wc) __istype((wc), _CTYPE_A)
#define iswblank(wc) __istype((wc), _CTYPE_B)
-#define iswcntrl(wc) __istype((wc), _CTYPE_C)
-#define iswctype(wc, charclass) __istype((wc), (charclass))
-#define iswdigit(wc) __istype((wc), _CTYPE_D)
-#define iswgraph(wc) __istype((wc), _CTYPE_G)
-#define iswlower(wc) __istype((wc), _CTYPE_L)
-#define iswprint(wc) __istype((wc), _CTYPE_R)
-#define iswpunct(wc) __istype((wc), _CTYPE_P)
-#define iswspace(wc) __istype((wc), _CTYPE_S)
-#define iswupper(wc) __istype((wc), _CTYPE_U)
-#define iswxdigit(wc) __istype((wc), _CTYPE_X)
-#define towlower(wc) __tolower(wc)
-#define towupper(wc) __toupper(wc)
#if !defined(_ANSI_SOURCE)
#define iswascii(wc) (((wc) & ~0x7F) == 0)
#define iswspecial(wc) __istype((wc), _CTYPE_T)
#endif
+#ifdef _USE_EXTENDED_LOCALES_
+#include <xlocale/_wctype.h>
+#endif /* _USE_EXTENDED_LOCALES_ */
+
#endif /* _WCTYPE_H_ */
*
*/
-/* $Id: wordexp.h,v 1.2 2004/04/15 23:35:49 emoy Exp $ */
+/* $Id: wordexp.h,v 1.4 2004/11/25 19:38:10 emoy Exp $ */
#ifndef _WORDEXP_H
#define _WORDEXP_H
#include <sys/cdefs.h>
-#include <sys/_types.h>
+#include <_types.h>
-#ifndef _BSD_SIZE_T_DEFINED_
-#define _BSD_SIZE_T_DEFINED_
-typedef __size_t size_t;
+#ifndef _SIZE_T
+#define _SIZE_T
+typedef __darwin_size_t size_t;
#endif
typedef struct {
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef _XLOCALE_H_
+#define _XLOCALE_H_
+
+#include <sys/cdefs.h>
+
+#ifndef _USE_EXTENDED_LOCALES_
+#define _USE_EXTENDED_LOCALES_
+#endif /* _USE_EXTENDED_LOCALES_ */
+
+struct _xlocale; /* forward reference */
+typedef struct _xlocale * locale_t;
+
+#include <_locale.h>
+#include <_xlocale.h>
+
+#define LC_ALL_MASK ( LC_COLLATE_MASK \
+ | LC_CTYPE_MASK \
+ | LC_MESSAGES_MASK \
+ | LC_MONETARY_MASK \
+ | LC_NUMERIC_MASK \
+ | LC_TIME_MASK )
+#define LC_COLLATE_MASK (1 << 0)
+#define LC_CTYPE_MASK (1 << 1)
+#define LC_MESSAGES_MASK (1 << 2)
+#define LC_MONETARY_MASK (1 << 3)
+#define LC_NUMERIC_MASK (1 << 4)
+#define LC_TIME_MASK (1 << 5)
+
+#define _LC_LAST_MASK (1 << (6 - 1))
+
+#define LC_GLOBAL_LOCALE ((locale_t)-1)
+
+#ifdef MB_CUR_MAX
+#undef MB_CUR_MAX
+#define MB_CUR_MAX (___mb_cur_max())
+#ifndef MB_CUR_MAX_L
+#define MB_CUR_MAX_L(x) (___mb_cur_max_l(x))
+#endif /* !MB_CUR_MAX_L */
+#endif /* MB_CUR_MAX */
+
+__BEGIN_DECLS
+extern const locale_t _c_locale;
+
+locale_t duplocale(locale_t);
+int freelocale(locale_t);
+struct lconv * localeconv_l(locale_t);
+locale_t newlocale(int, __const char *, locale_t);
+__const char * querylocale(int, locale_t);
+locale_t uselocale(locale_t);
+__END_DECLS
+
+#ifdef __WCTYPE_H_
+#include <xlocale/__wctype.h>
+#endif /* __WCTYPE_H_ */
+#ifdef _CTYPE_H_
+#include <xlocale/_ctype.h>
+#endif /* _CTYPE_H_ */
+#ifdef _INTTYPES_H_
+#include <xlocale/_inttypes.h>
+#endif /* _INTTYPES_H_ */
+#ifdef _LANGINFO_H_
+#include <xlocale/_langinfo.h>
+#endif /* _LANGINFO_H_ */
+#ifdef _MONETARY_H_
+#include <xlocale/_monetary.h>
+#endif /* _MONETARY_H_ */
+#ifdef _STDIO_H_
+#include <xlocale/_stdio.h>
+#endif /* _STDIO_H_ */
+#ifdef _STDLIB_H_
+#include <xlocale/_stdlib.h>
+#endif /* _STDLIB_H_ */
+#ifdef _STRING_H_
+#include <xlocale/_string.h>
+#endif /*STRING_CTYPE_H_ */
+#ifdef _TIME_H_
+#include <xlocale/_time.h>
+#endif /* _TIME_H_ */
+#ifdef _WCHAR_H_
+#include <xlocale/_wchar.h>
+#endif /*WCHAR_CTYPE_H_ */
+#ifdef _WCTYPE_H_
+#include <xlocale/_wctype.h>
+#endif /* _WCTYPE_H_ */
+
+#endif /* _XLOCALE_H_ */
--- /dev/null
+INCXLOCALE_INSTHDRS += __wctype.h _ctype.h _inttypes.h _langinfo.h \
+ _monetary.h _stdlib.h _stdio.h _string.h \
+ _time.h _wchar.h _wctype.h
+
+INCXLOCALE_INSTHDRS := ${INCXLOCALE_INSTHDRS:S/^/${.CURDIR}\/include\/xlocale\//}
+XLOCALE_INSTHDRS += ${INCXLOCALE_INSTHDRS}
+
+STRIP_HDRS += xlocale/_ctype.h
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef _XLOCALE___WCTYPE_H_
+#define _XLOCALE___WCTYPE_H_
+
+__BEGIN_DECLS
+int iswalnum_l(wint_t, locale_t);
+int iswalpha_l(wint_t, locale_t);
+int iswcntrl_l(wint_t, locale_t);
+int iswctype_l(wint_t, wctype_t, locale_t);
+int iswdigit_l(wint_t, locale_t);
+int iswgraph_l(wint_t, locale_t);
+int iswlower_l(wint_t, locale_t);
+int iswprint_l(wint_t, locale_t);
+int iswpunct_l(wint_t, locale_t);
+int iswspace_l(wint_t, locale_t);
+int iswupper_l(wint_t, locale_t);
+int iswxdigit_l(wint_t, locale_t);
+wint_t towlower_l(wint_t, locale_t);
+wint_t towupper_l(wint_t, locale_t);
+wctype_t
+ wctype_l(const char *, locale_t);
+__END_DECLS
+
+#define iswalnum_l(wc, l) __istype_l((wc), _CTYPE_A|_CTYPE_D, (l))
+#define iswalpha_l(wc, l) __istype_l((wc), _CTYPE_A, (l))
+#define iswcntrl_l(wc, l) __istype_l((wc), _CTYPE_C, (l))
+#define iswctype_l(wc, charclass, l) __istype_l((wc), (charclass), (l))
+#define iswdigit_l(wc, l) __istype_l((wc), _CTYPE_D, (l))
+#define iswgraph_l(wc, l) __istype_l((wc), _CTYPE_G, (l))
+#define iswlower_l(wc, l) __istype_l((wc), _CTYPE_L, (l))
+#define iswprint_l(wc, l) __istype_l((wc), _CTYPE_R, (l))
+#define iswpunct_l(wc, l) __istype_l((wc), _CTYPE_P, (l))
+#define iswspace_l(wc, l) __istype_l((wc), _CTYPE_S, (l))
+#define iswupper_l(wc, l) __istype_l((wc), _CTYPE_U, (l))
+#define iswxdigit_l(wc, l) __istype_l((wc), _CTYPE_X, (l))
+#define towlower_l(wc, l) __tolower_l((wc), (l))
+#define towupper_l(wc, l) __toupper_l((wc), (l))
+
+#endif /* _XLOCALE___WCTYPE_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef _XLOCALE__CTYPE_H_
+#define _XLOCALE__CTYPE_H_
+
+__BEGIN_DECLS
+int digittoint_l(int, locale_t);
+int isalnum_l(int, locale_t);
+int isalpha_l(int, locale_t);
+int isblank_l(int, locale_t);
+int iscntrl_l(int, locale_t);
+int isdigit_l(int, locale_t);
+int isgraph_l(int, locale_t);
+int ishexnumber_l(int, locale_t);
+int isideogram_l(int, locale_t);
+int islower_l(int, locale_t);
+int isnumber_l(int, locale_t);
+int isphonogram_l(int, locale_t);
+int isprint_l(int, locale_t);
+int ispunct_l(int, locale_t);
+int isrune_l(int, locale_t);
+int isspace_l(int, locale_t);
+int isspecial_l(int, locale_t);
+int isupper_l(int, locale_t);
+int isxdigit_l(int, locale_t);
+int tolower_l(int, locale_t);
+int toupper_l(int, locale_t);
+__END_DECLS
+
+#define digittoint_l(c, l) __maskrune_l((c), 0xFF, (l))
+#define ishexnumber_l(c, l) __istype_l((c), _CTYPE_X, (l))
+#define isideogram_l(c, l) __istype_l((c), _CTYPE_I, (l))
+#define isnumber_l(c, l) __istype_l((c), _CTYPE_D, (l))
+#define isphonogram_l(c, l) __istype_l((c), _CTYPE_Q, (l))
+#define isrune_l(c, l) __istype_l((c), 0xFFFFFF00L, (l))
+#define isspecial_l(c, l) __istype_l((c), _CTYPE_T, (l))
+#define isalnum_l(c, l) __istype_l((c), (_CTYPE_A|_CTYPE_D), (l))
+#define isalpha_l(c, l) __istype_l((c), _CTYPE_A, (l))
+#define isblank_l(c, l) __istype_l((c), _CTYPE_B, (l))
+#define iscntrl_l(c, l) __istype_l((c), _CTYPE_C, (l))
+#define isdigit_l(c, l) __istype_l((c), _CTYPE_D, (l))
+#define isgraph_l(c, l) __istype_l((c), _CTYPE_G, (l))
+#define islower_l(c, l) __istype_l((c), _CTYPE_L, (l))
+#define isprint_l(c, l) __istype_l((c), _CTYPE_R, (l))
+#define ispunct_l(c, l) __istype_l((c), _CTYPE_P, (l))
+#define isspace_l(c, l) __istype_l((c), _CTYPE_S, (l))
+#define isupper_l(c, l) __istype_l((c), _CTYPE_U, (l))
+#define isxdigit_l(c, l) __istype_l((c), _CTYPE_X, (l))
+#define tolower_l(c, l) __tolower_l(c, (l))
+#define toupper_l(c, l) __toupper_l(c, (l))
+
+/* See comments in <machine/_type.h> about __darwin_ct_rune_t. */
+__BEGIN_DECLS
+unsigned long ___runetype_l(__darwin_ct_rune_t, locale_t);
+__darwin_ct_rune_t ___tolower_l(__darwin_ct_rune_t, locale_t);
+__darwin_ct_rune_t ___toupper_l(__darwin_ct_rune_t, locale_t);
+__END_DECLS
+
+/*
+ * Use inline functions if we are allowed to and the compiler supports them.
+ */
+#if !defined(_DONT_USE_CTYPE_INLINE_) && \
+ (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
+
+//Begin-Libc
+#ifdef __LIBC__
+static __inline int
+__maskrune_l(__darwin_ct_rune_t _c, unsigned long _f, locale_t _l)
+{
+ return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype_l(_c, _l) :
+ __locale_ptr(_l)->__lc_ctype->_CurrentRuneLocale.__runetype[_c]) & _f;
+}
+#else /* !__LIBC__ */
+//End-Libc
+__BEGIN_DECLS
+int __maskrune_l(__darwin_ct_rune_t, unsigned long, locale_t);
+__END_DECLS
+//Begin-Libc
+#endif /* __LIBC__ */
+//End-Libc
+
+static __inline int
+__istype_l(__darwin_ct_rune_t _c, unsigned long _f, locale_t _l)
+{
+ return !!(isascii(_c) ? (_DefaultRuneLocale.__runetype[_c] & _f)
+ : __maskrune_l(_c, _f, _l));
+}
+
+static __inline __darwin_ct_rune_t
+__toupper_l(__darwin_ct_rune_t _c, locale_t _l)
+{
+ return isascii(_c) ? _DefaultRuneLocale.__mapupper[_c]
+ : ___toupper_l(_c, _l);
+}
+
+static __inline __darwin_ct_rune_t
+__tolower_l(__darwin_ct_rune_t _c, locale_t _l)
+{
+ return isascii(_c) ? _DefaultRuneLocale.__maplower[_c]
+ : ___tolower_l(_c, _l);
+}
+
+static __inline int
+__wcwidth_l(__darwin_ct_rune_t _c, locale_t _l)
+{
+ unsigned int _x;
+
+ if (_c == 0)
+ return (0);
+ _x = (unsigned int)__maskrune_l(_c, _CTYPE_SWM|_CTYPE_R, _l);
+ if ((_x & _CTYPE_SWM) != 0)
+ return ((_x & _CTYPE_SWM) >> _CTYPE_SWS);
+ return ((_x & _CTYPE_R) != 0 ? 1 : -1);
+}
+
+#else /* not using inlines */
+
+__BEGIN_DECLS
+int __maskrune_l(__darwin_ct_rune_t, unsigned long, locale_t);
+int __istype_l(__darwin_ct_rune_t, unsigned long, locale_t);
+__darwin_ct_rune_t __toupper_l(__darwin_ct_rune_t, locale_t);
+__darwin_ct_rune_t __tolower_l(__darwin_ct_rune_t, locale_t);
+int __wcwidth_l(__darwin_ct_rune_t, locale_t);
+__END_DECLS
+#endif /* using inlines */
+
+#endif /* _XLOCALE__CTYPE_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef _XLOCALE__INTTYPES_H_
+#define _XLOCALE__INTTYPES_H_
+
+__BEGIN_DECLS
+intmax_t strtoimax_l(const char * __restrict nptr, char ** __restrict endptr,
+ int base, locale_t);
+uintmax_t strtoumax_l(const char * __restrict nptr, char ** __restrict endptr,
+ int base, locale_t);
+intmax_t wcstoimax_l(const wchar_t * __restrict nptr,
+ wchar_t ** __restrict endptr, int base, locale_t);
+uintmax_t wcstoumax_l(const wchar_t * __restrict nptr,
+ wchar_t ** __restrict endptr, int base, locale_t);
+__END_DECLS
+
+#endif /* _XLOCALE__INTTYPES_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef _XLOCALE__LANGINFO_H_
+#define _XLOCALE__LANGINFO_H_
+
+__BEGIN_DECLS
+char *nl_langinfo_l(nl_item, locale_t);
+__END_DECLS
+
+#endif /* _XLOCALE__LANGINFO_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef _XLOCALE__MONETARY_H_
+#define _XLOCALE__MONETARY_H_
+
+__BEGIN_DECLS
+ssize_t strfmon_l(char *, size_t, locale_t, const char *, ...);
+__END_DECLS
+
+#endif /* _XLOCALE__MONETARY_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef _XLOCALE__STDIO_H_
+#define _XLOCALE__STDIO_H_
+
+__BEGIN_DECLS
+int asprintf_l(char **, locale_t, const char *, ...)
+ __DARWIN_LDBL_COMPAT2(asprintf_l);
+int fprintf_l(FILE * __restrict, locale_t, const char * __restrict, ...)
+ __DARWIN_LDBL_COMPAT2(fprintf_l);
+int fscanf_l(FILE * __restrict, locale_t, const char * __restrict, ...)
+ __DARWIN_LDBL_COMPAT2(fscanf_l);
+int printf_l(locale_t, const char * __restrict, ...)
+ __DARWIN_LDBL_COMPAT2(printf_l);
+int scanf_l(locale_t, const char * __restrict, ...)
+ __DARWIN_LDBL_COMPAT2(scanf_l);
+int snprintf_l(char * __restrict, size_t, locale_t,
+ const char * __restrict, ...) __DARWIN_LDBL_COMPAT2(snprintf_l);
+int sprintf_l(char * __restrict, locale_t, const char * __restrict, ...)
+ __DARWIN_LDBL_COMPAT2(sprintf_l);
+int sscanf_l(const char * __restrict, locale_t, const char * __restrict,
+ ...) __DARWIN_LDBL_COMPAT2(sscanf_l);
+int vasprintf_l(char **, locale_t, const char *, va_list)
+ __DARWIN_LDBL_COMPAT2(vasprintf_l);
+int vfprintf_l(FILE * __restrict, locale_t, const char * __restrict,
+ va_list) __DARWIN_LDBL_COMPAT2(vfprintf_l);
+int vfscanf_l(FILE * __restrict, locale_t, const char * __restrict,
+ va_list) __DARWIN_LDBL_COMPAT2(vfscanf_l);
+int vprintf_l(locale_t, const char * __restrict, va_list)
+ __DARWIN_LDBL_COMPAT2(vprintf_l);
+int vscanf_l(locale_t, const char * __restrict, va_list)
+ __DARWIN_LDBL_COMPAT2(vscanf_l);
+int vsnprintf_l(char * __restrict, size_t, locale_t,
+ const char * __restrict, va_list)
+ __DARWIN_LDBL_COMPAT2(vsnprintf_l);
+int vsprintf_l(char * __restrict, locale_t, const char * __restrict,
+ va_list) __DARWIN_LDBL_COMPAT2(vsprintf_l);
+int vsscanf_l(const char * __restrict, locale_t, const char * __restrict,
+ va_list) __DARWIN_LDBL_COMPAT2(vsscanf_l);
+__END_DECLS
+
+#endif /* _XLOCALE__STDIO_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef _XLOCALE__STDLIB_H_
+#define _XLOCALE__STDLIB_H_
+
+__BEGIN_DECLS
+double atof_l(const char *, locale_t);
+int atoi_l(const char *, locale_t);
+long atol_l(const char *, locale_t);
+#if !__DARWIN_NO_LONG_LONG
+long long
+ atoll_l(const char *, locale_t);
+#endif /* !__DARWIN_NO_LONG_LONG */
+int mblen_l(const char *, size_t, locale_t);
+size_t mbstowcs_l(wchar_t * __restrict , const char * __restrict, size_t,
+ locale_t);
+int mbtowc_l(wchar_t * __restrict, const char * __restrict, size_t,
+ locale_t);
+double strtod_l(const char *, char **, locale_t);
+float strtof_l(const char *, char **, locale_t);
+long strtol_l(const char *, char **, int, locale_t);
+long double
+ strtold_l(const char *, char **, locale_t)
+ __DARWIN_LDBL_COMPAT2(strtold_l);
+long long
+ strtoll_l(const char *, char **, int, locale_t);
+#if !__DARWIN_NO_LONG_LONG
+long long
+ strtoq_l(const char *, char **, int, locale_t);
+#endif /* !__DARWIN_NO_LONG_LONG */
+unsigned long
+ strtoul_l(const char *, char **, int, locale_t);
+unsigned long long
+ strtoull_l(const char *, char **, int, locale_t);
+#if !__DARWIN_NO_LONG_LONG
+unsigned long long
+ strtouq_l(const char *, char **, int, locale_t);
+#endif /* !__DARWIN_NO_LONG_LONG */
+size_t wcstombs_l(char * __restrict, const wchar_t * __restrict, size_t,
+ locale_t);
+int wctomb_l(char *, wchar_t, locale_t);
+__END_DECLS
+
+#endif /* _XLOCALE__STDLIB_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef _XLOCALE__STRING_H_
+#define _XLOCALE__STRING_H_
+
+__BEGIN_DECLS
+int strcoll_l(const char *, const char *, locale_t);
+size_t strxfrm_l(char *, const char *, size_t, locale_t);
+int strcasecmp_l(const char *, const char *, locale_t);
+char *strcasestr_l(const char *, const char *, locale_t);
+int strncasecmp_l(const char *, const char *, size_t, locale_t);
+__END_DECLS
+
+#endif /* _XLOCALE__STRING_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef _XLOCALE__TIME_H_
+#define _XLOCALE__TIME_H_
+
+__BEGIN_DECLS
+size_t strftime_l(char * __restrict, size_t, const char * __restrict,
+ const struct tm * __restrict, locale_t)
+ __DARWIN_ALIAS(strftime_l);
+char *strptime_l(const char * __restrict, const char * __restrict,
+ struct tm * __restrict, locale_t);
+__END_DECLS
+
+#endif /* _XLOCALE__TIME_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef _XLOCALE__WCHAR_H_
+#define _XLOCALE__WCHAR_H_
+
+__BEGIN_DECLS
+wint_t btowc_l(int, locale_t);
+wint_t fgetwc_l(FILE *, locale_t);
+wchar_t *fgetws_l(wchar_t * __restrict, int, FILE * __restrict, locale_t);
+wint_t fputwc_l(wchar_t, FILE *, locale_t);
+int fputws_l(const wchar_t * __restrict, FILE * __restrict, locale_t);
+int fwprintf_l(FILE * __restrict, locale_t, const wchar_t * __restrict, ...)
+ __DARWIN_LDBL_COMPAT2(fwprintf_l);
+int fwscanf_l(FILE * __restrict, locale_t, const wchar_t * __restrict, ...)
+ __DARWIN_LDBL_COMPAT2(fwscanf_l);
+wint_t getwc_l(FILE *, locale_t);
+wint_t getwchar_l(locale_t);
+size_t mbrlen_l(const char * __restrict, size_t, mbstate_t * __restrict,
+ locale_t);
+size_t mbrtowc_l(wchar_t * __restrict, const char * __restrict, size_t,
+ mbstate_t * __restrict, locale_t);
+int mbsinit_l(const mbstate_t *, locale_t);
+size_t mbsnrtowcs_l(wchar_t * __restrict, const char ** __restrict, size_t,
+ size_t, mbstate_t * __restrict, locale_t);
+size_t mbsrtowcs_l(wchar_t * __restrict, const char ** __restrict, size_t,
+ mbstate_t * __restrict, locale_t);
+wint_t putwc_l(wchar_t, FILE *, locale_t);
+wint_t putwchar_l(wchar_t, locale_t);
+int swprintf_l(wchar_t * __restrict, size_t n, locale_t,
+ const wchar_t * __restrict, ...)
+ __DARWIN_LDBL_COMPAT2(swprintf_l);
+int swscanf_l(const wchar_t * __restrict, locale_t,
+ const wchar_t * __restrict, ...)
+ __DARWIN_LDBL_COMPAT2(swscanf_l);
+wint_t ungetwc_l(wint_t, FILE *, locale_t);
+int vfwprintf_l(FILE * __restrict, locale_t, const wchar_t * __restrict,
+ __darwin_va_list) __DARWIN_LDBL_COMPAT2(vfwprintf_l);
+int vfwscanf_l(FILE * __restrict, locale_t, const wchar_t * __restrict,
+ __darwin_va_list) __DARWIN_LDBL_COMPAT2(vfwscanf_l);
+int vswprintf_l(wchar_t * __restrict, size_t n, locale_t,
+ const wchar_t * __restrict, __darwin_va_list)
+ __DARWIN_LDBL_COMPAT2(vswprintf_l);
+int vswscanf_l(const wchar_t * __restrict, locale_t,
+ const wchar_t * __restrict, __darwin_va_list)
+ __DARWIN_LDBL_COMPAT2(vswscanf_l);
+int vwprintf_l(locale_t, const wchar_t * __restrict, __darwin_va_list)
+ __DARWIN_LDBL_COMPAT2(vwprintf_l);
+int vwscanf_l(locale_t, const wchar_t * __restrict, __darwin_va_list)
+ __DARWIN_LDBL_COMPAT2(vwscanf_l);
+size_t wcrtomb_l(char * __restrict, wchar_t, mbstate_t * __restrict,
+ locale_t);
+int wcscoll_l(const wchar_t *, const wchar_t *, locale_t);
+size_t wcsftime_l(wchar_t * __restrict, size_t, const wchar_t * __restrict,
+ const struct tm * __restrict, locale_t);
+size_t wcsnrtombs_l(char * __restrict, const wchar_t ** __restrict, size_t,
+ size_t, mbstate_t * __restrict, locale_t);
+size_t wcsrtombs_l(char * __restrict, const wchar_t ** __restrict, size_t,
+ mbstate_t * __restrict, locale_t);
+double wcstod_l(const wchar_t * __restrict, wchar_t ** __restrict, locale_t);
+float wcstof_l(const wchar_t * __restrict, wchar_t ** __restrict, locale_t);
+long wcstol_l(const wchar_t * __restrict, wchar_t ** __restrict, int,
+ locale_t);
+long double
+ wcstold_l(const wchar_t * __restrict, wchar_t ** __restrict, locale_t)
+ __DARWIN_LDBL_COMPAT2(wcstold_l);
+long long
+ wcstoll_l(const wchar_t * __restrict, wchar_t ** __restrict, int,
+ locale_t);
+unsigned long
+ wcstoul_l(const wchar_t * __restrict, wchar_t ** __restrict, int,
+ locale_t);
+unsigned long long
+ wcstoull_l(const wchar_t * __restrict, wchar_t ** __restrict, int,
+ locale_t);
+int wcswidth_l(const wchar_t *, size_t, locale_t);
+size_t wcsxfrm_l(wchar_t * __restrict, const wchar_t * __restrict, size_t,
+ locale_t);
+int wctob_l(wint_t, locale_t);
+int wcwidth_l(wchar_t, locale_t);
+int wprintf_l(locale_t, const wchar_t * __restrict, ...)
+ __DARWIN_LDBL_COMPAT2(wprintf_l);
+int wscanf_l(locale_t, const wchar_t * __restrict, ...)
+ __DARWIN_LDBL_COMPAT2(wscanf_l);
+__END_DECLS
+
+#endif /* _XLOCALE__WCHAR_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef _XLOCALE__WCTYPE_H_
+#define _XLOCALE__WCTYPE_H_
+
+__BEGIN_DECLS
+int iswblank_l(wint_t, locale_t);
+wint_t iswhexnumber_l(wint_t, locale_t);
+wint_t iswideogram_l(wint_t, locale_t);
+wint_t iswnumber_l(wint_t, locale_t);
+wint_t iswphonogram_l(wint_t, locale_t);
+wint_t iswrune_l(wint_t, locale_t);
+wint_t iswspecial_l(wint_t, locale_t);
+wint_t nextwctype_l(wint_t, wctype_t, locale_t);
+wint_t towctrans_l(wint_t, wctrans_t, locale_t);
+wctrans_t
+ wctrans_l(const char *, locale_t);
+__END_DECLS
+
+#define iswblank_l(wc, l) __istype_l((wc), _CTYPE_B, (l))
+#define iswhexnumber_l(wc, l) __istype_l((wc), _CTYPE_X, (l))
+#define iswideogram_l(wc, l) __istype_l((wc), _CTYPE_I, (l))
+#define iswnumber_l(wc, l) __istype_l((wc), _CTYPE_D, (l))
+#define iswphonogram_l(wc, l) __istype_l((wc), _CTYPE_Q, (l))
+#define iswrune_l(wc, l) __istype_l((wc), 0xFFFFFF00L, (l))
+#define iswspecial_l(wc, l) __istype_l((wc), _CTYPE_T, (l))
+
+#endif /* _XLOCALE__WCTYPE_H_ */
+
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
const unsigned int _NX_CTypeTable_[1 + 256] = {
/* One extra char in table: */ 0,
-/* 0 .notdef */ _C,
-/* 1 .notdef */ _C,
-/* 2 .notdef */ _C,
-/* 3 .notdef */ _C,
-/* 4 .notdef */ _C,
-/* 5 .notdef */ _C,
-/* 6 .notdef */ _C,
-/* 7 .notdef */ _C,
-
-/* 8 .notdef */ _C,
-/* 9 .notdef */ _C|_S,
-/* 10 .notdef */ _C|_S,
-/* 11 .notdef */ _C|_S,
-/* 12 .notdef */ _C|_S,
-/* 13 .notdef */ _C|_S,
-/* 14 .notdef */ _C,
-/* 15 .notdef */ _C,
-
-/* 16 .notdef */ _C,
-/* 17 .notdef */ _C,
-/* 18 .notdef */ _C,
-/* 19 .notdef */ _C,
-/* 20 .notdef */ _C,
-/* 21 .notdef */ _C,
-/* 22 .notdef */ _C,
-/* 23 .notdef */ _C,
-
-/* 24 .notdef */ _C,
-/* 25 .notdef */ _C,
-/* 26 .notdef */ _C,
-/* 27 .notdef */ _C,
-/* 28 .notdef */ _C,
-/* 29 .notdef */ _C,
-/* 30 .notdef */ _C,
-/* 31 .notdef */ _C,
-
-/* 32 space */ _S|_B,
-/* 33 exclam */ _P,
-/* 34 quotedbl */ _P,
-/* 35 numbersign */ _P,
-/* 36 dollar */ _P,
-/* 37 percent */ _P,
-/* 38 ampersand */ _P,
-/* 39 quoteright */ _P,
-
-/* 40 parenleft */ _P,
-/* 41 parenright */ _P,
-/* 42 asterisk */ _P,
-/* 43 plus */ _P,
-/* 44 comma */ _P,
-/* 45 hyphen */ _P,
-/* 46 period */ _P,
-/* 47 slash */ _P,
-
-/* 48 zero */ _D,
-/* 49 one */ _D,
-/* 50 two */ _D,
-/* 51 three */ _D,
-/* 52 four */ _D,
-/* 53 five */ _D,
-/* 54 six */ _D,
-/* 55 seven */ _D,
-
-/* 56 eight */ _D,
-/* 57 nine */ _D,
-/* 58 colon */ _P,
-/* 59 semicolon */ _P,
-/* 60 less */ _P,
-/* 61 equal */ _P,
-/* 62 greater */ _P,
-/* 63 question */ _P,
-
-/* 64 at */ _P,
-/* 65 A */ _U|_X,
-/* 66 B */ _U|_X,
-/* 67 C */ _U|_X,
-/* 68 D */ _U|_X,
-/* 69 E */ _U|_X,
-/* 70 F */ _U|_X,
-/* 71 G */ _U,
-
-/* 72 H */ _U,
-/* 73 I */ _U,
-/* 74 J */ _U,
-/* 75 K */ _U,
-/* 76 L */ _U,
-/* 77 M */ _U,
-/* 78 N */ _U,
-/* 79 O */ _U,
-
-/* 80 P */ _U,
-/* 81 Q */ _U,
-/* 82 R */ _U,
-/* 83 S */ _U,
-/* 84 T */ _U,
-/* 85 U */ _U,
-/* 86 V */ _U,
-/* 87 W */ _U,
-
-/* 88 X */ _U,
-/* 89 Y */ _U,
-/* 90 Z */ _U,
-/* 91 bracketleft */ _P,
-/* 92 backslash */ _P,
-/* 93 bracketright */ _P,
-/* 94 asciicircum */ _P,
-/* 95 underscore */ _P,
-
-/* 96 quoteleft */ _P,
-/* 97 a */ _L|_X,
-/* 98 b */ _L|_X,
-/* 99 c */ _L|_X,
-/* 100 d */ _L|_X,
-/* 101 e */ _L|_X,
-/* 102 f */ _L|_X,
-/* 103 g */ _L,
-
-/* 104 h */ _L,
-/* 105 i */ _L,
-/* 106 j */ _L,
-/* 107 k */ _L,
-/* 108 l */ _L,
-/* 109 m */ _L,
-/* 110 n */ _L,
-/* 111 o */ _L,
-
-/* 112 p */ _L,
-/* 113 q */ _L,
-/* 114 r */ _L,
-/* 115 s */ _L,
-/* 116 t */ _L,
-/* 117 u */ _L,
-/* 118 v */ _L,
-/* 119 w */ _L,
-
-/* 120 x */ _L,
-/* 121 y */ _L,
-/* 122 z */ _L,
-/* 123 braceleft */ _P,
-/* 124 bar */ _P,
-/* 125 braceright */ _P,
-/* 126 asciitilde */ _P,
-/* 127 .notdef */ _C,
-
-/* 128 .notdef */ _C,
-/* 129 Agrave */ _U,
-/* 130 Aacute */ _U,
-/* 131 Acircumflex */ _U,
-/* 132 Atilde */ _U,
-/* 133 Adieresis */ _U,
-/* 134 Aring */ _U,
-/* 135 Ccedilla */ _U,
-
-/* 136 Egrave */ _U,
-/* 137 Eacute */ _U,
-/* 138 Ecircumflex */ _U,
-/* 139 Edieresis */ _U,
-/* 140 Igrave */ _U,
-/* 141 Iacute */ _U,
-/* 142 Icircumflex */ _U,
-/* 143 Idieresis */ _U,
-
-/* 144 Eth */ _U,
-/* 145 Ntilde */ _U,
-/* 146 Ograve */ _U,
-/* 147 Oacute */ _U,
-/* 148 Ocircumflex */ _U,
-/* 149 Otilde */ _U,
-/* 150 Odieresis */ _U,
-/* 151 Ugrave */ _U,
-
-/* 152 Uacute */ _U,
-/* 153 Ucircumflex */ _U,
-/* 154 Udieresis */ _U,
-/* 155 Yacute */ _U,
-/* 156 Thorn */ _U,
-/* 157 mu */ _P,
-/* 158 multiply */ _P,
-/* 159 divide */ _P,
-
-/* 160 copyright */ _P,
-/* 161 exclamdown */ _P,
-/* 162 cent */ _P,
-/* 163 sterling */ _P,
-/* 164 fraction */ _P,
-/* 165 yen */ _P,
-/* 166 florin */ _P,
-/* 167 section */ _P,
-
-/* 168 currency */ _P,
-/* 169 quotesingle */ _P,
-/* 170 quotedblleft */ _P,
-/* 171 guillemotleft */ _P,
-/* 172 guilsinglleft */ _P,
-/* 173 guilsinglright */ _P,
-/* 174 fi */ _L,
-/* 175 fl */ _L,
-
-/* 176 registered */ _P,
-/* 177 endash */ _P,
-/* 178 dagger */ _P,
-/* 179 daggerdbl */ _P,
-/* 180 periodcentered */ _P,
-/* 181 brokenbar */ _P,
-/* 182 paragraph */ _P,
-/* 183 bullet */ _P,
-
-/* 184 quotesinglbase */ _P,
-/* 185 quotedblbase */ _P,
-/* 186 quotedblright */ _P,
-/* 187 guillemotright */ _P,
-/* 188 ellipsis */ _P,
-/* 189 perthousand */ _P,
-/* 190 logicalnot */ _P,
-/* 191 questiondown */ _P,
-
-/* 192 onesuperior */ _P,
-/* 193 grave */ _P,
-/* 194 acute */ _P,
-/* 195 circumflex */ _P,
-/* 196 tilde */ _P,
-/* 197 macron */ _P,
-/* 198 breve */ _P,
-/* 199 dotaccent */ _P,
-
-/* 200 dieresis */ _P,
-/* 201 twosuperior */ _P,
-/* 202 ring */ _P,
-/* 203 cedilla */ _P,
-/* 204 threesuperior */ _P,
-/* 205 hungarumlaut */ _P,
-/* 206 ogonek */ _P,
-/* 207 caron */ _P,
-
-/* 208 emdash */ _P,
-/* 209 plusminus */ _P,
-/* 210 onequarter */ _P,
-/* 211 onehalf */ _P,
-/* 212 threequarters */ _P,
-/* 213 agrave */ _L,
-/* 214 aacute */ _L,
-/* 215 acircumflex */ _L,
-
-/* 216 atilde */ _L,
-/* 217 adieresis */ _L,
-/* 218 aring */ _L,
-/* 219 ccedilla */ _L,
-/* 220 egrave */ _L,
-/* 221 eacute */ _L,
-/* 222 ecircumflex */ _L,
-/* 223 edieresis */ _L,
-
-/* 224 igrave */ _L,
-/* 225 AE */ _U,
-/* 226 iacute */ _L,
-/* 227 ordfeminine */ _P,
-/* 228 icircumflex */ _L,
-/* 229 idieresis */ _L,
-/* 230 eth */ _L,
-/* 231 ntilde */ _L,
-
-/* 232 Lslash */ _U,
-/* 233 Oslash */ _U,
-/* 234 OE */ _U,
-/* 235 ordmasculine */ _P,
-/* 236 ograve */ _L,
-/* 237 oacute */ _L,
-/* 238 ocircumflex */ _L,
-/* 239 otilde */ _L,
-
-/* 240 odieresis */ _L,
-/* 241 ae */ _L,
-/* 242 ugrave */ _L,
-/* 243 uacute */ _L,
-/* 244 ucircumflex */ _L,
-/* 245 dotlessi */ _L,
-/* 246 udieresis */ _L,
-/* 247 yacute */ _L,
-
-/* 248 lslash */ _L,
-/* 249 oslash */ _L,
-/* 250 oe */ _L,
-/* 251 germandbls */ _L,
-/* 252 thorn */ _L,
-/* 253 ydieresis */ _L,
-/* 254 .notdef */ _C,
-/* 255 .notdef */ _C,
+/* 0 .notdef */ _CTYPE_C,
+/* 1 .notdef */ _CTYPE_C,
+/* 2 .notdef */ _CTYPE_C,
+/* 3 .notdef */ _CTYPE_C,
+/* 4 .notdef */ _CTYPE_C,
+/* 5 .notdef */ _CTYPE_C,
+/* 6 .notdef */ _CTYPE_C,
+/* 7 .notdef */ _CTYPE_C,
+
+/* 8 .notdef */ _CTYPE_C,
+/* 9 .notdef */ _CTYPE_C|_CTYPE_S,
+/* 10 .notdef */ _CTYPE_C|_CTYPE_S,
+/* 11 .notdef */ _CTYPE_C|_CTYPE_S,
+/* 12 .notdef */ _CTYPE_C|_CTYPE_S,
+/* 13 .notdef */ _CTYPE_C|_CTYPE_S,
+/* 14 .notdef */ _CTYPE_C,
+/* 15 .notdef */ _CTYPE_C,
+
+/* 16 .notdef */ _CTYPE_C,
+/* 17 .notdef */ _CTYPE_C,
+/* 18 .notdef */ _CTYPE_C,
+/* 19 .notdef */ _CTYPE_C,
+/* 20 .notdef */ _CTYPE_C,
+/* 21 .notdef */ _CTYPE_C,
+/* 22 .notdef */ _CTYPE_C,
+/* 23 .notdef */ _CTYPE_C,
+
+/* 24 .notdef */ _CTYPE_C,
+/* 25 .notdef */ _CTYPE_C,
+/* 26 .notdef */ _CTYPE_C,
+/* 27 .notdef */ _CTYPE_C,
+/* 28 .notdef */ _CTYPE_C,
+/* 29 .notdef */ _CTYPE_C,
+/* 30 .notdef */ _CTYPE_C,
+/* 31 .notdef */ _CTYPE_C,
+
+/* 32 space */ _CTYPE_S|_CTYPE_B,
+/* 33 exclam */ _CTYPE_P,
+/* 34 quotedbl */ _CTYPE_P,
+/* 35 numbersign */ _CTYPE_P,
+/* 36 dollar */ _CTYPE_P,
+/* 37 percent */ _CTYPE_P,
+/* 38 ampersand */ _CTYPE_P,
+/* 39 quoteright */ _CTYPE_P,
+
+/* 40 parenleft */ _CTYPE_P,
+/* 41 parenright */ _CTYPE_P,
+/* 42 asterisk */ _CTYPE_P,
+/* 43 plus */ _CTYPE_P,
+/* 44 comma */ _CTYPE_P,
+/* 45 hyphen */ _CTYPE_P,
+/* 46 period */ _CTYPE_P,
+/* 47 slash */ _CTYPE_P,
+
+/* 48 zero */ _CTYPE_D,
+/* 49 one */ _CTYPE_D,
+/* 50 two */ _CTYPE_D,
+/* 51 three */ _CTYPE_D,
+/* 52 four */ _CTYPE_D,
+/* 53 five */ _CTYPE_D,
+/* 54 six */ _CTYPE_D,
+/* 55 seven */ _CTYPE_D,
+
+/* 56 eight */ _CTYPE_D,
+/* 57 nine */ _CTYPE_D,
+/* 58 colon */ _CTYPE_P,
+/* 59 semicolon */ _CTYPE_P,
+/* 60 less */ _CTYPE_P,
+/* 61 equal */ _CTYPE_P,
+/* 62 greater */ _CTYPE_P,
+/* 63 question */ _CTYPE_P,
+
+/* 64 at */ _CTYPE_P,
+/* 65 A */ _CTYPE_U|_CTYPE_X,
+/* 66 B */ _CTYPE_U|_CTYPE_X,
+/* 67 C */ _CTYPE_U|_CTYPE_X,
+/* 68 D */ _CTYPE_U|_CTYPE_X,
+/* 69 E */ _CTYPE_U|_CTYPE_X,
+/* 70 F */ _CTYPE_U|_CTYPE_X,
+/* 71 G */ _CTYPE_U,
+
+/* 72 H */ _CTYPE_U,
+/* 73 I */ _CTYPE_U,
+/* 74 J */ _CTYPE_U,
+/* 75 K */ _CTYPE_U,
+/* 76 L */ _CTYPE_U,
+/* 77 M */ _CTYPE_U,
+/* 78 N */ _CTYPE_U,
+/* 79 O */ _CTYPE_U,
+
+/* 80 P */ _CTYPE_U,
+/* 81 Q */ _CTYPE_U,
+/* 82 R */ _CTYPE_U,
+/* 83 S */ _CTYPE_U,
+/* 84 T */ _CTYPE_U,
+/* 85 U */ _CTYPE_U,
+/* 86 V */ _CTYPE_U,
+/* 87 W */ _CTYPE_U,
+
+/* 88 X */ _CTYPE_U,
+/* 89 Y */ _CTYPE_U,
+/* 90 Z */ _CTYPE_U,
+/* 91 bracketleft */ _CTYPE_P,
+/* 92 backslash */ _CTYPE_P,
+/* 93 bracketright */ _CTYPE_P,
+/* 94 asciicircum */ _CTYPE_P,
+/* 95 underscore */ _CTYPE_P,
+
+/* 96 quoteleft */ _CTYPE_P,
+/* 97 a */ _CTYPE_L|_CTYPE_X,
+/* 98 b */ _CTYPE_L|_CTYPE_X,
+/* 99 c */ _CTYPE_L|_CTYPE_X,
+/* 100 d */ _CTYPE_L|_CTYPE_X,
+/* 101 e */ _CTYPE_L|_CTYPE_X,
+/* 102 f */ _CTYPE_L|_CTYPE_X,
+/* 103 g */ _CTYPE_L,
+
+/* 104 h */ _CTYPE_L,
+/* 105 i */ _CTYPE_L,
+/* 106 j */ _CTYPE_L,
+/* 107 k */ _CTYPE_L,
+/* 108 l */ _CTYPE_L,
+/* 109 m */ _CTYPE_L,
+/* 110 n */ _CTYPE_L,
+/* 111 o */ _CTYPE_L,
+
+/* 112 p */ _CTYPE_L,
+/* 113 q */ _CTYPE_L,
+/* 114 r */ _CTYPE_L,
+/* 115 s */ _CTYPE_L,
+/* 116 t */ _CTYPE_L,
+/* 117 u */ _CTYPE_L,
+/* 118 v */ _CTYPE_L,
+/* 119 w */ _CTYPE_L,
+
+/* 120 x */ _CTYPE_L,
+/* 121 y */ _CTYPE_L,
+/* 122 z */ _CTYPE_L,
+/* 123 braceleft */ _CTYPE_P,
+/* 124 bar */ _CTYPE_P,
+/* 125 braceright */ _CTYPE_P,
+/* 126 asciitilde */ _CTYPE_P,
+/* 127 .notdef */ _CTYPE_C,
+
+/* 128 .notdef */ _CTYPE_C,
+/* 129 Agrave */ _CTYPE_U,
+/* 130 Aacute */ _CTYPE_U,
+/* 131 Acircumflex */ _CTYPE_U,
+/* 132 Atilde */ _CTYPE_U,
+/* 133 Adieresis */ _CTYPE_U,
+/* 134 Aring */ _CTYPE_U,
+/* 135 Ccedilla */ _CTYPE_U,
+
+/* 136 Egrave */ _CTYPE_U,
+/* 137 Eacute */ _CTYPE_U,
+/* 138 Ecircumflex */ _CTYPE_U,
+/* 139 Edieresis */ _CTYPE_U,
+/* 140 Igrave */ _CTYPE_U,
+/* 141 Iacute */ _CTYPE_U,
+/* 142 Icircumflex */ _CTYPE_U,
+/* 143 Idieresis */ _CTYPE_U,
+
+/* 144 Eth */ _CTYPE_U,
+/* 145 Ntilde */ _CTYPE_U,
+/* 146 Ograve */ _CTYPE_U,
+/* 147 Oacute */ _CTYPE_U,
+/* 148 Ocircumflex */ _CTYPE_U,
+/* 149 Otilde */ _CTYPE_U,
+/* 150 Odieresis */ _CTYPE_U,
+/* 151 Ugrave */ _CTYPE_U,
+
+/* 152 Uacute */ _CTYPE_U,
+/* 153 Ucircumflex */ _CTYPE_U,
+/* 154 Udieresis */ _CTYPE_U,
+/* 155 Yacute */ _CTYPE_U,
+/* 156 Thorn */ _CTYPE_U,
+/* 157 mu */ _CTYPE_P,
+/* 158 multiply */ _CTYPE_P,
+/* 159 divide */ _CTYPE_P,
+
+/* 160 copyright */ _CTYPE_P,
+/* 161 exclamdown */ _CTYPE_P,
+/* 162 cent */ _CTYPE_P,
+/* 163 sterling */ _CTYPE_P,
+/* 164 fraction */ _CTYPE_P,
+/* 165 yen */ _CTYPE_P,
+/* 166 florin */ _CTYPE_P,
+/* 167 section */ _CTYPE_P,
+
+/* 168 currency */ _CTYPE_P,
+/* 169 quotesingle */ _CTYPE_P,
+/* 170 quotedblleft */ _CTYPE_P,
+/* 171 guillemotleft */ _CTYPE_P,
+/* 172 guilsinglleft */ _CTYPE_P,
+/* 173 guilsinglright */ _CTYPE_P,
+/* 174 fi */ _CTYPE_L,
+/* 175 fl */ _CTYPE_L,
+
+/* 176 registered */ _CTYPE_P,
+/* 177 endash */ _CTYPE_P,
+/* 178 dagger */ _CTYPE_P,
+/* 179 daggerdbl */ _CTYPE_P,
+/* 180 periodcentered */ _CTYPE_P,
+/* 181 brokenbar */ _CTYPE_P,
+/* 182 paragraph */ _CTYPE_P,
+/* 183 bullet */ _CTYPE_P,
+
+/* 184 quotesinglbase */ _CTYPE_P,
+/* 185 quotedblbase */ _CTYPE_P,
+/* 186 quotedblright */ _CTYPE_P,
+/* 187 guillemotright */ _CTYPE_P,
+/* 188 ellipsis */ _CTYPE_P,
+/* 189 perthousand */ _CTYPE_P,
+/* 190 logicalnot */ _CTYPE_P,
+/* 191 questiondown */ _CTYPE_P,
+
+/* 192 onesuperior */ _CTYPE_P,
+/* 193 grave */ _CTYPE_P,
+/* 194 acute */ _CTYPE_P,
+/* 195 circumflex */ _CTYPE_P,
+/* 196 tilde */ _CTYPE_P,
+/* 197 macron */ _CTYPE_P,
+/* 198 breve */ _CTYPE_P,
+/* 199 dotaccent */ _CTYPE_P,
+
+/* 200 dieresis */ _CTYPE_P,
+/* 201 twosuperior */ _CTYPE_P,
+/* 202 ring */ _CTYPE_P,
+/* 203 cedilla */ _CTYPE_P,
+/* 204 threesuperior */ _CTYPE_P,
+/* 205 hungarumlaut */ _CTYPE_P,
+/* 206 ogonek */ _CTYPE_P,
+/* 207 caron */ _CTYPE_P,
+
+/* 208 emdash */ _CTYPE_P,
+/* 209 plusminus */ _CTYPE_P,
+/* 210 onequarter */ _CTYPE_P,
+/* 211 onehalf */ _CTYPE_P,
+/* 212 threequarters */ _CTYPE_P,
+/* 213 agrave */ _CTYPE_L,
+/* 214 aacute */ _CTYPE_L,
+/* 215 acircumflex */ _CTYPE_L,
+
+/* 216 atilde */ _CTYPE_L,
+/* 217 adieresis */ _CTYPE_L,
+/* 218 aring */ _CTYPE_L,
+/* 219 ccedilla */ _CTYPE_L,
+/* 220 egrave */ _CTYPE_L,
+/* 221 eacute */ _CTYPE_L,
+/* 222 ecircumflex */ _CTYPE_L,
+/* 223 edieresis */ _CTYPE_L,
+
+/* 224 igrave */ _CTYPE_L,
+/* 225 AE */ _CTYPE_U,
+/* 226 iacute */ _CTYPE_L,
+/* 227 ordfeminine */ _CTYPE_P,
+/* 228 icircumflex */ _CTYPE_L,
+/* 229 idieresis */ _CTYPE_L,
+/* 230 eth */ _CTYPE_L,
+/* 231 ntilde */ _CTYPE_L,
+
+/* 232 Lslash */ _CTYPE_U,
+/* 233 Oslash */ _CTYPE_U,
+/* 234 OE */ _CTYPE_U,
+/* 235 ordmasculine */ _CTYPE_P,
+/* 236 ograve */ _CTYPE_L,
+/* 237 oacute */ _CTYPE_L,
+/* 238 ocircumflex */ _CTYPE_L,
+/* 239 otilde */ _CTYPE_L,
+
+/* 240 odieresis */ _CTYPE_L,
+/* 241 ae */ _CTYPE_L,
+/* 242 ugrave */ _CTYPE_L,
+/* 243 uacute */ _CTYPE_L,
+/* 244 ucircumflex */ _CTYPE_L,
+/* 245 dotlessi */ _CTYPE_L,
+/* 246 udieresis */ _CTYPE_L,
+/* 247 yacute */ _CTYPE_L,
+
+/* 248 lslash */ _CTYPE_L,
+/* 249 oslash */ _CTYPE_L,
+/* 250 oe */ _CTYPE_L,
+/* 251 germandbls */ _CTYPE_L,
+/* 252 thorn */ _CTYPE_L,
+/* 253 ydieresis */ _CTYPE_L,
+/* 254 .notdef */ _CTYPE_C,
+/* 255 .notdef */ _CTYPE_C,
};
/*
* There are some pathological cases: ydieresis, germandbls, and the
* fi & fl ligatures don't have "other case" equivalents; therefore
* they're entered as themselves because they are in fact "lower case"
- * and the Type table lists them as _L.
+ * and the Type table lists them as _CTYPE_L.
*/
const unsigned char _NX_ULTable_[256] = {
/* 0 .notdef */ 0,
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
{
FIXSIGNEDCHAR(c);
if (c < 256)
- return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_U|_L|_D)));
+ return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_CTYPE_U|_CTYPE_L|_CTYPE_D)));
return 0;
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
{
FIXSIGNEDCHAR(c);
if (c < 256)
- return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_U|_L)));
+ return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_CTYPE_U|_CTYPE_L)));
return 0;
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
{
FIXSIGNEDCHAR(c);
if (c < 256)
- return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_C)));
+ return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_CTYPE_C)));
return 0;
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
{
FIXSIGNEDCHAR(c);
if (c < 256)
- return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_D)));
+ return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_CTYPE_D)));
return 0;
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
{
FIXSIGNEDCHAR(c);
if (c < 256)
- return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_P|_U|_L|_D)));
+ return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_D)));
return 1;
/* NOTE: for 3.0, everything > 256 is probably Kanji, so say is graphic */
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
{
FIXSIGNEDCHAR(c);
if (c < 256)
- return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_L)));
+ return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_CTYPE_L)));
return 0;
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
{
FIXSIGNEDCHAR(c);
if (c < 256)
- return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_P|_U|_L|_D|_B)));
+ return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_D|_CTYPE_B)));
return 1;
/* NOTE: for 3.0, everything > 255 is probably Kanji, so say printable... */
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
{
FIXSIGNEDCHAR(c);
if (c < 256)
- return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_P)));
+ return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_CTYPE_P)));
return 0;
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
{
FIXSIGNEDCHAR(c);
if (c < 256)
- return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_S)));
+ return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_CTYPE_S)));
return 0;
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
{
FIXSIGNEDCHAR(c);
if (c < 256)
- return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_U)));
+ return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_CTYPE_U)));
return 0;
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
{
FIXSIGNEDCHAR(c);
if (c < 256)
- return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_D|_X)));
+ return ((unsigned int)((_NX_CTypeTable_ + 1)[c] & (_CTYPE_D|_CTYPE_X)));
return 0;
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+.\" Copyright (c) 2002, 2003 Tim J. Robbins
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/locale/big5.5,v 1.3 2004/07/05 06:36:36 ru Exp $
+.\"
+.Dd August 7, 2003
+.Dt BIG5 5
+.Os
+.Sh NAME
+.Nm big5
+.Nd
+.Dq "Big Five"
+encoding for Traditional Chinese text
+.Sh SYNOPSIS
+.Nm ENCODING
+.Qq BIG5
+.Sh DESCRIPTION
+.Dq Big Five
+is the de facto standard for encoding Traditional Chinese text.
+Each character is represented by either one or two bytes.
+Characters from the
+.Tn ASCII
+character set are represented as single bytes in the range 0x00 - 0x7F.
+Traditional Chinese characters are represented by two bytes:
+the first in the range 0xA1 - 0xFE, the second in the range
+0x40 - 0xFE.
+.Sh SEE ALSO
+.Xr euc 5 ,
+.Xr gb18030 5 ,
+.Xr utf8 5
/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved.
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
*
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)big5.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/big5.c,v 1.7 2002/03/22 21:52:18 obrien Exp $");
+#include <sys/param.h>
+__FBSDID("$FreeBSD: src/lib/libc/locale/big5.c,v 1.16 2004/05/17 11:16:14 tjr Exp $");
-#include <rune.h>
-#include <stddef.h>
-#include <stdio.h>
+#include <errno.h>
+#include <runetype.h>
#include <stdlib.h>
-#include <sys/types.h>
+#include <string.h>
+#include <wchar.h>
+#include "mblocal.h"
-rune_t _BIG5_sgetrune(const char *, size_t, char const **);
-int _BIG5_sputrune(rune_t, char *, size_t, char **);
+int _BIG5_init(_RuneLocale *);
+size_t _BIG5_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
+ mbstate_t * __restrict);
+int _BIG5_mbsinit(const mbstate_t *);
+size_t _BIG5_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
+
+typedef struct {
+ wchar_t ch;
+} _BIG5State;
int
-_BIG5_init(rl)
- _RuneLocale *rl;
+_BIG5_init(_RuneLocale *rl)
{
- rl->sgetrune = _BIG5_sgetrune;
- rl->sputrune = _BIG5_sputrune;
+
+ __mbrtowc = _BIG5_mbrtowc;
+ __wcrtomb = _BIG5_wcrtomb;
+ __mbsinit = _BIG5_mbsinit;
_CurrentRuneLocale = rl;
__mb_cur_max = 2;
return (0);
}
-static inline int
-_big5_check(c)
- u_int c;
+int
+_BIG5_mbsinit(const mbstate_t *ps)
+{
+
+ return (ps == NULL || ((const _BIG5State *)ps)->ch == 0);
+}
+
+static __inline int
+_big5_check(u_int c)
{
+
c &= 0xff;
return ((c >= 0xa1 && c <= 0xfe) ? 2 : 1);
}
-rune_t
-_BIG5_sgetrune(string, n, result)
- const char *string;
- size_t n;
- char const **result;
+size_t
+_BIG5_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
+ mbstate_t * __restrict ps)
{
- rune_t rune = 0;
- int len;
+ _BIG5State *bs;
+ wchar_t wc;
+ size_t len;
+
+ bs = (_BIG5State *)ps;
- if (n < 1 || (len = _big5_check(*string)) > n) {
- if (result)
- *result = string;
- return (_INVALID_RUNE);
+ if ((bs->ch & ~0xFF) != 0) {
+ /* Bad conversion state. */
+ errno = EINVAL;
+ return ((size_t)-1);
}
- while (--len >= 0)
- rune = (rune << 8) | ((u_int)(*string++) & 0xff);
- if (result)
- *result = string;
- return rune;
-}
-int
-_BIG5_sputrune(c, string, n, result)
- rune_t c;
- char *string, **result;
- size_t n;
-{
- if (c & 0x8000) {
- if (n >= 2) {
- string[0] = (c >> 8) & 0xff;
- string[1] = c & 0xff;
- if (result)
- *result = string + 2;
- return (2);
+ if (s == NULL) {
+ s = "";
+ n = 1;
+ pwc = NULL;
+ }
+
+ if (n == 0)
+ /* Incomplete multibyte sequence */
+ return ((size_t)-2);
+
+ if (bs->ch != 0) {
+ if (*s == '\0') {
+ errno = EILSEQ;
+ return ((size_t)-1);
}
+ wc = (bs->ch << 8) | (*s & 0xFF);
+ if (pwc != NULL)
+ *pwc = wc;
+ bs->ch = 0;
+ return (1);
}
- else {
- if (n >= 1) {
- *string = c & 0xff;
- if (result)
- *result = string + 1;
- return (1);
+
+ len = (size_t)_big5_check(*s);
+ wc = *s++ & 0xff;
+ if (len == 2) {
+ if (n < 2) {
+ /* Incomplete multibyte sequence */
+ bs->ch = wc;
+ return ((size_t)-2);
+ }
+ if (*s == '\0') {
+ errno = EILSEQ;
+ return ((size_t)-1);
}
+ wc = (wc << 8) | (*s++ & 0xff);
+ if (pwc != NULL)
+ *pwc = wc;
+ return (2);
+ } else {
+ if (pwc != NULL)
+ *pwc = wc;
+ return (wc == L'\0' ? 0 : 1);
}
- if (result)
- *result = string;
- return (0);
-
+}
+
+size_t
+_BIG5_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
+{
+ _BIG5State *bs;
+
+ bs = (_BIG5State *)ps;
+
+ if (bs->ch != 0) {
+ errno = EINVAL;
+ return ((size_t)-1);
+ }
+
+ if (s == NULL)
+ /* Reset to initial shift state (no-op) */
+ return (1);
+ if (wc & 0x8000) {
+ *s++ = (wc >> 8) & 0xff;
+ *s = wc & 0xff;
+ return (2);
+ }
+ *s = wc & 0xff;
+ return (1);
}
---- big5.c.orig Tue May 20 15:21:44 2003
-+++ big5.c Wed Jun 18 12:02:34 2003
-@@ -45,6 +45,7 @@
- #include <stdio.h>
+--- big5.c.orig Thu Nov 25 11:38:16 2004
++++ big5.c Fri Feb 18 15:48:14 2005
+@@ -41,6 +41,8 @@
+ #include <sys/param.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/big5.c,v 1.16 2004/05/17 11:16:14 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <errno.h>
+ #include <runetype.h>
#include <stdlib.h>
- #include <sys/types.h>
-+#include <ctype.h>
-
- rune_t _BIG5_sgetrune(const char *, size_t, char const **);
- int _BIG5_sputrune(rune_t, char *, size_t, char **);
-@@ -77,13 +78,17 @@
- rune_t rune = 0;
- int len;
-
-- if (n < 1 || (len = _big5_check(*string)) > n) {
-- if (result)
-- *result = string;
-+ if (result)
-+ *result = string;
-+ if (n < 1 || (len = _big5_check(*string)) > n)
- return (_INVALID_RUNE);
-- }
- while (--len >= 0)
- rune = (rune << 8) | ((u_int)(*string++) & 0xff);
-+ if (!isrune(rune)) {
-+ if (result)
-+ (*result)++;
-+ return (_INVALID_RUNE);
-+ }
- if (result)
- *result = string;
- return rune;
+@@ -48,30 +50,29 @@
+ #include <wchar.h>
+ #include "mblocal.h"
+
+-int _BIG5_init(_RuneLocale *);
+-size_t _BIG5_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
+- mbstate_t * __restrict);
+-int _BIG5_mbsinit(const mbstate_t *);
+-size_t _BIG5_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
++__private_extern__ int _BIG5_init(struct __xlocale_st_runelocale *);
++static size_t _BIG5_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
++ mbstate_t * __restrict, locale_t);
++static int _BIG5_mbsinit(const mbstate_t *, locale_t);
++static size_t _BIG5_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict, locale_t);
+
+ typedef struct {
+ wchar_t ch;
+ } _BIG5State;
+
+-int
+-_BIG5_init(_RuneLocale *rl)
++__private_extern__ int
++_BIG5_init(struct __xlocale_st_runelocale *xrl)
+ {
+
+- __mbrtowc = _BIG5_mbrtowc;
+- __wcrtomb = _BIG5_wcrtomb;
+- __mbsinit = _BIG5_mbsinit;
+- _CurrentRuneLocale = rl;
+- __mb_cur_max = 2;
++ xrl->__mbrtowc = _BIG5_mbrtowc;
++ xrl->__wcrtomb = _BIG5_wcrtomb;
++ xrl->__mbsinit = _BIG5_mbsinit;
++ xrl->__mb_cur_max = 2;
+ return (0);
+ }
+
+-int
+-_BIG5_mbsinit(const mbstate_t *ps)
++static int
++_BIG5_mbsinit(const mbstate_t *ps, locale_t loc)
+ {
+
+ return (ps == NULL || ((const _BIG5State *)ps)->ch == 0);
+@@ -85,9 +86,9 @@
+ return ((c >= 0xa1 && c <= 0xfe) ? 2 : 1);
+ }
+
+-size_t
++static size_t
+ _BIG5_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
+- mbstate_t * __restrict ps)
++ mbstate_t * __restrict ps, locale_t loc)
+ {
+ _BIG5State *bs;
+ wchar_t wc;
+@@ -146,8 +147,8 @@
+ }
+ }
+
+-size_t
+-_BIG5_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
++static size_t
++_BIG5_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps, locale_t loc)
+ {
+ _BIG5State *bs;
+
--- /dev/null
+--- btowc.3.orig Fri Mar 11 18:06:40 2005
++++ btowc.3 Fri Mar 11 18:08:08 2005
+@@ -29,7 +29,9 @@
+ .Os
+ .Sh NAME
+ .Nm btowc ,
+-.Nm wctob
++.Nm wctob ,
++.Nm btowc_l ,
++.Nm wctob_l
+ .Nd "convert between wide and single-byte characters"
+ .Sh LIBRARY
+ .Lb libc
+@@ -39,6 +41,11 @@
+ .Fn btowc "int c"
+ .Ft int
+ .Fn wctob "wint_t c"
++.In xlocale.h
++.Ft wint_t
++.Fn btowc_l "int c" "locale_t loc"
++.Ft int
++.Fn wctob_l "wint_t c" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn btowc
+@@ -59,10 +66,23 @@
+ .Fn wctob
+ returns
+ .Dv WEOF .
++.Pp
++While the
++.Fn btowc
++and
++.Fn wctob
++functions use the current locale, the
++.Fn btowc_l
++and
++.Fn wctob_l
++functions may be passed locales directly. See
++.Xr xlocale 3
++for more information.
+ .Sh SEE ALSO
+ .Xr mbrtowc 3 ,
+ .Xr multibyte 3 ,
+-.Xr wcrtomb 3
++.Xr wcrtomb 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn btowc
/*-
- * Copyright (c) 2002 Tim J. Robbins.
+ * Copyright (c) 2002, 2003 Tim J. Robbins.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/btowc.c,v 1.1 2002/08/03 13:49:55 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/btowc.c,v 1.4 2004/05/12 14:26:54 tjr Exp $");
-#include <rune.h>
+#include <stdio.h>
#include <wchar.h>
+#include "mblocal.h"
wint_t
btowc(int c)
{
- rune_t r;
+ static const mbstate_t initial;
+ mbstate_t mbs = initial;
char cc;
+ wchar_t wc;
if (c == EOF)
return (WEOF);
+ /*
+ * We expect mbrtowc() to return 0 or 1, hence the check for n > 1
+ * which detects error return values as well as "impossible" byte
+ * counts.
+ */
cc = (char)c;
- if ((r = sgetrune(&cc, 1, NULL)) == _INVALID_RUNE)
+ if (__mbrtowc(&wc, &cc, 1, &mbs) > 1)
return (WEOF);
- return (r);
+ return (wc);
}
--- /dev/null
+--- btowc.c.orig Thu Nov 25 11:38:16 2004
++++ btowc.c Fri Feb 18 15:58:50 2005
+@@ -27,18 +27,21 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/btowc.c,v 1.4 2004/05/12 14:26:54 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdio.h>
+ #include <wchar.h>
+ #include "mblocal.h"
+
+ wint_t
+-btowc(int c)
++btowc_l(int c, locale_t loc)
+ {
+ static const mbstate_t initial;
+ mbstate_t mbs = initial;
+ char cc;
+ wchar_t wc;
+
++ NORMALIZE_LOCALE(loc);
+ if (c == EOF)
+ return (WEOF);
+ /*
+@@ -47,7 +50,13 @@
+ * counts.
+ */
+ cc = (char)c;
+- if (__mbrtowc(&wc, &cc, 1, &mbs) > 1)
++ if (loc->__lc_ctype->__mbrtowc(&wc, &cc, 1, &mbs, loc) > 1)
+ return (WEOF);
+ return (wc);
++}
++
++wint_t
++btowc(int c)
++{
++ return btowc_l(c, __current_locale());
+ }
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/collate.c,v 1.32 2002/10/29 09:03:57 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/collate.c,v 1.33 2004/09/22 16:56:48 stefanf Exp $");
#include "namespace.h"
#include <arpa/inet.h>
delta += delta / 8;
dest_str = malloc(dest_len = delta);
if (dest_str == NULL)
- __collate_err(EX_OSERR, __FUNCTION__);
+ __collate_err(EX_OSERR, __func__);
len = 0;
while (*s) {
nlen = len + strlen(__collate_substitute_table[*s]);
if (dest_len <= nlen) {
dest_str = reallocf(dest_str, dest_len = nlen + delta);
if (dest_str == NULL)
- __collate_err(EX_OSERR, __FUNCTION__);
+ __collate_err(EX_OSERR, __func__);
}
(void)strcpy(dest_str + len, __collate_substitute_table[*s++]);
len = nlen;
u_char *t = strdup(s);
if (t == NULL)
- __collate_err(EX_OSERR, __FUNCTION__);
+ __collate_err(EX_OSERR, __func__);
return (t);
}
---- collate.c.orig Tue Oct 29 01:03:57 2002
-+++ collate.c Sat May 3 14:14:24 2003
-@@ -29,7 +29,6 @@
- __FBSDID("$FreeBSD: src/lib/libc/locale/collate.c,v 1.32 2002/10/29 09:03:57 tjr Exp $");
+--- collate.c.orig 2004-11-25 11:38:16.000000000 -0800
++++ collate.c 2005-02-17 10:35:00.000000000 -0800
+@@ -28,6 +28,11 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/collate.c,v 1.33 2004/09/22 16:56:48 stefanf Exp $");
++#include "xlocale_private.h"
++/* assumes the locale_t variable is named loc */
++#define __collate_substitute_table (loc->__lc_collate->__substitute_table)
++#define __collate_char_pri_table (loc->__lc_collate->__char_pri_table)
++
#include "namespace.h"
--#include <arpa/inet.h>
+ #include <arpa/inet.h>
#include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
+@@ -44,36 +49,46 @@
+
+ #include "libc_private.h"
+
+-int __collate_load_error = 1;
+-int __collate_substitute_nontrivial;
+-
+-u_char __collate_substitute_table[UCHAR_MAX + 1][STR_LEN];
+-struct __collate_st_char_pri __collate_char_pri_table[UCHAR_MAX + 1];
+-struct __collate_st_chain_pri *__collate_chain_pri_table;
+-
+ void __collate_err(int ex, const char *f) __dead2;
+
+-int
+-__collate_load_tables(const char *encoding)
++/*
++ * Normally, the __collate_* routines should all be __private_extern__,
++ * but grep is using them (3715846). Until we can provide an alternative,
++ * we leave them public, and provide a read-only __collate_load_error variable
++ */
++#undef __collate_load_error
++int __collate_load_error = 1;
++
++__private_extern__ int
++__collate_load_tables(const char *encoding, locale_t loc)
+ {
+ FILE *fp;
+ int i, saverr, chains;
+ uint32_t u32;
+ char strbuf[STR_LEN], buf[PATH_MAX];
+- void *TMP_substitute_table, *TMP_char_pri_table, *TMP_chain_pri_table;
+- static char collate_encoding[ENCODING_LEN + 1];
++ struct __xlocale_st_collate *TMP;
++ static struct __xlocale_st_collate *cache = NULL;
+
+ /* 'encoding' must be already checked. */
+ if (strcmp(encoding, "C") == 0 || strcmp(encoding, "POSIX") == 0) {
+- __collate_load_error = 1;
++ loc->__collate_load_error = 1;
++ if (loc == &__global_locale)
++ __collate_load_error = 1;
++ XL_RELEASE(loc->__lc_collate);
++ loc->__lc_collate = NULL;
+ return (_LDP_CACHE);
+ }
+
+ /*
+ * If the locale name is the same as our cache, use the cache.
+ */
+- if (strcmp(encoding, collate_encoding) == 0) {
+- __collate_load_error = 0;
++ if (cache && strcmp(encoding, cache->__encoding) == 0) {
++ loc->__collate_load_error = 0;
++ if (loc == &__global_locale)
++ __collate_load_error = 0;
++ XL_RELEASE(loc->__lc_collate);
++ loc->__lc_collate = cache;
++ XL_RETAIN(loc->__lc_collate);
+ return (_LDP_CACHE);
+ }
+
+@@ -121,115 +136,106 @@
+ } else
+ chains = TABLE_SIZE;
+
+- if ((TMP_substitute_table =
+- malloc(sizeof(__collate_substitute_table))) == NULL) {
+- saverr = errno;
+- (void)fclose(fp);
+- errno = saverr;
+- return (_LDP_ERROR);
+- }
+- if ((TMP_char_pri_table =
+- malloc(sizeof(__collate_char_pri_table))) == NULL) {
++ if ((TMP =
++ malloc(sizeof(struct __xlocale_st_collate) + sizeof(struct __collate_st_chain_pri) * chains)) == NULL) {
+ saverr = errno;
+- free(TMP_substitute_table);
+- (void)fclose(fp);
+- errno = saverr;
+- return (_LDP_ERROR);
+- }
+- if ((TMP_chain_pri_table =
+- malloc(sizeof(*__collate_chain_pri_table) * chains)) == NULL) {
+- saverr = errno;
+- free(TMP_substitute_table);
+- free(TMP_char_pri_table);
+ (void)fclose(fp);
+ errno = saverr;
+ return (_LDP_ERROR);
+ }
++ TMP->__refcount = 2; /* one for the locale, one for the cache */
++ TMP->__free_extra = NULL;
++ TMP->__chain_pri_table = (struct __collate_st_chain_pri *)(TMP + 1);
+
+ #define FREAD(a, b, c, d) \
+ { \
+ if (fread(a, b, c, d) != c) { \
+ saverr = errno; \
+- free(TMP_substitute_table); \
+- free(TMP_char_pri_table); \
+- free(TMP_chain_pri_table); \
++ free(TMP); \
+ (void)fclose(d); \
+ errno = saverr; \
+ return (_LDP_ERROR); \
+ } \
+ }
+
+- FREAD(TMP_substitute_table, sizeof(__collate_substitute_table), 1, fp);
+- FREAD(TMP_char_pri_table, sizeof(__collate_char_pri_table), 1, fp);
+- FREAD(TMP_chain_pri_table,
+- sizeof(*__collate_chain_pri_table), chains, fp);
++ FREAD(TMP->__substitute_table, sizeof(TMP->__substitute_table), 1, fp);
++ FREAD(TMP->__char_pri_table, sizeof(TMP->__char_pri_table), 1, fp);
++ FREAD(TMP->__chain_pri_table,
++ sizeof(struct __collate_st_chain_pri), chains, fp);
+ (void)fclose(fp);
+
+- (void)strcpy(collate_encoding, encoding);
+- if (__collate_substitute_table_ptr != NULL)
+- free(__collate_substitute_table_ptr);
+- __collate_substitute_table_ptr = TMP_substitute_table;
+- if (__collate_char_pri_table_ptr != NULL)
+- free(__collate_char_pri_table_ptr);
+- __collate_char_pri_table_ptr = TMP_char_pri_table;
+- if (__collate_chain_pri_table != NULL)
+- free(__collate_chain_pri_table);
+- __collate_chain_pri_table = TMP_chain_pri_table;
++ (void)strcpy(TMP->__encoding, encoding);
++ XL_RELEASE(cache);
++ cache = TMP;
++ XL_RELEASE(loc->__lc_collate);
++ loc->__lc_collate = cache;
++ /* no need to retain, since we set __refcount to 2 above */
+
+- __collate_substitute_nontrivial = 0;
++ loc->__collate_substitute_nontrivial = 0;
+ for (i = 0; i < UCHAR_MAX + 1; i++) {
+ if (__collate_substitute_table[i][0] != i ||
+ __collate_substitute_table[i][1] != 0) {
+- __collate_substitute_nontrivial = 1;
++ loc->__collate_substitute_nontrivial = 1;
+ break;
+ }
+ }
+- __collate_load_error = 0;
++ loc->__collate_load_error = 0;
++ if (loc == &__global_locale)
++ __collate_load_error = 0;
+
+ return (_LDP_LOADED);
+ }
+
+-u_char *
+-__collate_substitute(s)
++__private_extern__ u_char *
++__collate_substitute_l(s, loc)
+ const u_char *s;
++ locale_t loc;
+ {
+ int dest_len, len, nlen;
+- int delta = strlen(s);
++ int delta = strlen((const char *)s);
+ u_char *dest_str = NULL;
+
+ if (s == NULL || *s == '\0')
+- return (__collate_strdup(""));
++ return (__collate_strdup((u_char *)""));
+ delta += delta / 8;
+ dest_str = malloc(dest_len = delta);
+ if (dest_str == NULL)
+ __collate_err(EX_OSERR, __func__);
+ len = 0;
+ while (*s) {
+- nlen = len + strlen(__collate_substitute_table[*s]);
++ nlen = len + strlen((const char *)__collate_substitute_table[*s]);
+ if (dest_len <= nlen) {
+ dest_str = reallocf(dest_str, dest_len = nlen + delta);
+ if (dest_str == NULL)
+ __collate_err(EX_OSERR, __func__);
+ }
+- (void)strcpy(dest_str + len, __collate_substitute_table[*s++]);
++ (void)strcpy((char *)(dest_str + len), (const char *)__collate_substitute_table[*s++]);
+ len = nlen;
+ }
+ return (dest_str);
+ }
+
+-void
+-__collate_lookup(t, len, prim, sec)
++u_char *
++__collate_substitute(s)
++ const u_char *s;
++{
++ return __collate_substitute_l(s, __current_locale());
++}
++
++__private_extern__ void
++__collate_lookup_l(t, len, prim, sec, loc)
+ const u_char *t;
+ int *len, *prim, *sec;
++ locale_t loc;
+ {
+ struct __collate_st_chain_pri *p2;
+
+ *len = 1;
+ *prim = *sec = 0;
+- for (p2 = __collate_chain_pri_table; p2->str[0] != '\0'; p2++) {
++ for (p2 = loc->__lc_collate->__chain_pri_table; p2->str[0] != '\0'; p2++) {
+ if (*t == p2->str[0] &&
+- strncmp(t, p2->str, strlen(p2->str)) == 0) {
+- *len = strlen(p2->str);
++ strncmp((const char *)t, (const char *)p2->str, strlen((const char *)p2->str)) == 0) {
++ *len = strlen((const char *)p2->str);
+ *prim = p2->prim;
+ *sec = p2->sec;
+ return;
+@@ -239,11 +245,19 @@
+ *sec = __collate_char_pri_table[*t].sec;
+ }
+
++void
++__collate_lookup(t, len, prim, sec)
++ const u_char *t;
++ int *len, *prim, *sec;
++{
++ return __collate_lookup_l(t, len, prim, sec, __current_locale());
++}
++
+ u_char *
+ __collate_strdup(s)
+ u_char *s;
+ {
+- u_char *t = strdup(s);
++ u_char *t = (u_char *)strdup((const char *)s);
+
+ if (t == NULL)
+ __collate_err(EX_OSERR, __func__);
+@@ -274,6 +288,7 @@
+ {
+ int i;
+ struct __collate_st_chain_pri *p2;
++ locale_t loc = __current_locale();
+
+ printf("Substitute table:\n");
+ for (i = 0; i < UCHAR_MAX + 1; i++)
+@@ -281,7 +296,7 @@
+ printf("\t'%c' --> \"%s\"\n", i,
+ __collate_substitute_table[i]);
+ printf("Chain priority table:\n");
+- for (p2 = __collate_chain_pri_table; p2->str[0] != '\0'; p2++)
++ for (p2 = loc->__lc_collate->__chain_pri_table; p2->str[0] != '\0'; p2++)
+ printf("\t\"%s\" : %d %d\n", p2->str, p2->prim, p2->sec);
+ printf("Char priority table:\n");
+ for (i = 0; i < UCHAR_MAX + 1; i++)
--- /dev/null
+--- collate.h.orig 2003-05-20 15:21:44.000000000 -0700
++++ collate.h 2005-02-19 14:36:36.000000000 -0800
+@@ -31,7 +31,9 @@
+ #define _COLLATE_H_
+
+ #include <sys/cdefs.h>
++#ifndef __LIBC__
+ #include <sys/types.h>
++#endif /* !__LIBC__ */
+ #include <limits.h>
+
+ #define STR_LEN 10
+@@ -43,24 +45,32 @@
+ int prim, sec;
+ };
+ struct __collate_st_chain_pri {
+- u_char str[STR_LEN];
++ unsigned char str[STR_LEN];
+ int prim, sec;
+ };
+
++#ifndef __LIBC__
+ extern int __collate_load_error;
+ extern int __collate_substitute_nontrivial;
+ #define __collate_substitute_table (*__collate_substitute_table_ptr)
+-extern u_char __collate_substitute_table[UCHAR_MAX + 1][STR_LEN];
++extern unsigned char __collate_substitute_table[UCHAR_MAX + 1][STR_LEN];
+ #define __collate_char_pri_table (*__collate_char_pri_table_ptr)
+ extern struct __collate_st_char_pri __collate_char_pri_table[UCHAR_MAX + 1];
+ extern struct __collate_st_chain_pri *__collate_chain_pri_table;
++#endif /* !__LIBC__ */
+
+ __BEGIN_DECLS
+-u_char *__collate_strdup(u_char *);
+-u_char *__collate_substitute(const u_char *);
+-int __collate_load_tables(const char *);
+-void __collate_lookup(const u_char *, int *, int *, int *);
++unsigned char *__collate_strdup(unsigned char *);
++#ifdef __LIBC__
++unsigned char *__collate_substitute_l(const unsigned char *, locale_t);
++int __collate_load_tables(const char *, locale_t);
++void __collate_lookup_l(const unsigned char *, int *, int *, int *, locale_t);
++int __collate_range_cmp(int, int, locale_t);
++#else /* !__LIBC__ */
++unsigned char *__collate_substitute(const unsigned char *);
++void __collate_lookup(const unsigned char *, int *, int *, int *);
+ int __collate_range_cmp(int, int);
++#endif /* __LIBC__ */
+ #ifdef COLLATE_DEBUG
+ void __collate_print_tables(void);
+ #endif
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/collcmp.c,v 1.14 2002/03/22 21:52:18 obrien Exp $");
-
-#define ASCII_COMPATIBLE_COLLATE /* see share/colldef */
+__FBSDID("$FreeBSD: src/lib/libc/locale/collcmp.c,v 1.17 2003/08/03 19:28:23 ache Exp $");
#include <string.h>
#include "collate.h"
-#ifndef ASCII_COMPATIBLE_COLLATE
-#include <ctype.h>
-#endif
/*
- * Compare two characters converting collate information
- * into ASCII-compatible range, it allows to handle
- * "[a-z]"-type ranges with national characters.
+ * Compare two characters using collate
*/
-int __collate_range_cmp (c1, c2)
+int __collate_range_cmp(c1, c2)
int c1, c2;
{
static char s1[2], s2[2];
- int ret;
-#ifndef ASCII_COMPATIBLE_COLLATE
- int as1, as2, al1, al2;
-#endif
-
- c1 &= UCHAR_MAX;
- c2 &= UCHAR_MAX;
- if (c1 == c2)
- return (0);
-
-#ifndef ASCII_COMPATIBLE_COLLATE
- as1 = isascii(c1);
- as2 = isascii(c2);
- al1 = isalpha(c1);
- al2 = isalpha(c2);
- if (as1 || as2 || al1 || al2) {
- if ((as1 && as2) || (!al1 && !al2))
- return (c1 - c2);
- if (al1 && !al2) {
- if (isupper(c1))
- return ('A' - c2);
- else
- return ('a' - c2);
- } else if (al2 && !al1) {
- if (isupper(c2))
- return (c1 - 'A');
- else
- return (c1 - 'a');
- }
- }
-#endif
s1[0] = c1;
s2[0] = c2;
- if ((ret = strcoll(s1, s2)) != 0)
- return (ret);
- return (c1 - c2);
+ return (strcoll(s1, s2));
}
--- /dev/null
+--- collcmp.c.orig 2004-11-25 11:38:16.000000000 -0800
++++ collcmp.c 2005-02-17 10:18:01.000000000 -0800
+@@ -27,6 +27,7 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/collcmp.c,v 1.17 2003/08/03 19:28:23 ache Exp $");
+
++#include <xlocale.h>
+ #include <string.h>
+ #include "collate.h"
+
+@@ -34,12 +35,13 @@
+ * Compare two characters using collate
+ */
+
+-int __collate_range_cmp(c1, c2)
++int __collate_range_cmp(c1, c2, loc)
+ int c1, c2;
++ locale_t loc;
+ {
+ static char s1[2], s2[2];
+
+ s1[0] = c1;
+ s2[0] = c2;
+- return (strcoll(s1, s2));
++ return (strcoll_l(s1, s2, loc));
+ }
.\" SUCH DAMAGE.
.\"
.\" @(#)ctype.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/locale/ctype.3,v 1.12 2002/12/18 13:33:03 ru Exp $
+.\" $FreeBSD: src/lib/libc/locale/ctype.3,v 1.15 2004/06/30 20:09:08 ru Exp $
.\"
-.Dd June 4, 1993
+.Dd March 30, 2004
.Dt CTYPE 3
.Os
.Sh NAME
The above functions perform character tests and conversions on the integer
.Fa c .
They are available as macros, defined in the include file
-.Aq Pa ctype.h ,
+.In ctype.h ,
or as true functions in the C library.
See the specific manual pages for more information.
.Sh SEE ALSO
.Xr iscntrl 3 ,
.Xr isdigit 3 ,
.Xr isgraph 3 ,
+.Xr isideogram 3 ,
.Xr islower 3 ,
+.Xr isphonogram 3 ,
.Xr isprint 3 ,
.Xr ispunct 3 ,
+.Xr isrune 3 ,
.Xr isspace 3 ,
+.Xr isspecial 3 ,
.Xr isupper 3 ,
.Xr isxdigit 3 ,
.Xr toascii 3 ,
.Xr tolower 3 ,
.Xr toupper 3 ,
+.Xr wctype 3 ,
.Xr ascii 7
.Sh STANDARDS
These functions, except for
--- /dev/null
+--- ctype.3.orig Fri Mar 11 18:02:47 2005
++++ ctype.3 Fri Mar 11 18:03:52 2005
+@@ -115,6 +115,12 @@
+ .In ctype.h ,
+ or as true functions in the C library.
+ See the specific manual pages for more information.
++.Pp
++Extended locale versions of these functions are documented in
++.Xr ctype_l 3 .
++See
++.Xr xlocale 3
++for more information.
+ .Sh SEE ALSO
+ .Xr digittoint 3 ,
+ .Xr isalnum 3 ,
+@@ -138,7 +144,8 @@
+ .Xr tolower 3 ,
+ .Xr toupper 3 ,
+ .Xr wctype 3 ,
+-.Xr ascii 7
++.Xr ascii 7 ,
++.Xr ctype_l 3
+ .Sh STANDARDS
+ These functions, except for
+ .Fn digittoint ,
.\" SUCH DAMAGE.
.\"
.\" @(#)digittoint.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/locale/digittoint.3,v 1.2 2002/03/18 15:44:27 ru Exp $
+.\" $FreeBSD: src/lib/libc/locale/digittoint.3,v 1.3 2004/03/30 07:19:35 tjr Exp $
.\"
.Dd April 6, 2001
.Dt DIGITTOINT 3
.Xr isxdigit 3 ,
the function will return 0.
.Sh SEE ALSO
-.Xr isalnum 3 ,
-.Xr isalpha 3 ,
-.Xr isascii 3 ,
-.Xr iscntrl 3 ,
+.Xr ctype 3 ,
.Xr isdigit 3 ,
-.Xr isgraph 3 ,
-.Xr islower 3 ,
-.Xr isprint 3 ,
-.Xr ispunct 3 ,
-.Xr isspace 3 ,
-.Xr isupper 3 ,
-.Xr isxdigit 3 ,
-.Xr stdio 3 ,
-.Xr tolower 3 ,
-.Xr toupper 3 ,
-.Xr ascii 7
+.Xr isxdigit 3
--- /dev/null
+--- digittoint.3.orig Fri Mar 11 19:44:47 2005
++++ digittoint.3 Fri Mar 11 19:45:48 2005
+@@ -36,7 +36,8 @@
+ .Dt DIGITTOINT 3
+ .Os
+ .Sh NAME
+-.Nm digittoint
++.Nm digittoint ,
++.Nm digittoint_l
+ .Nd convert a numeric character to its integer value
+ .Sh LIBRARY
+ .Lb libc
+@@ -44,12 +45,23 @@
+ .In ctype.h
+ .Ft int
+ .Fn digittoint "int c"
++.In xlocale.h
++.Ft int
++.Fn digittoint_l "int c" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn digittoint
+ function converts a numeric character to its corresponding integer value.
+ The character can be any decimal digit or hexadecimal digit.
+ With hexadecimal characters, the case of the values does not matter.
++.Pp
++While the
++.Fn digittoint
++function uses the current locale, the
++.Fn digittoint_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn digittoint
+@@ -60,4 +72,5 @@
+ .Sh SEE ALSO
+ .Xr ctype 3 ,
+ .Xr isdigit 3 ,
+-.Xr isxdigit 3
++.Xr isxdigit 3 ,
++.Xr xlocale 3
+++ /dev/null
-.\" Copyright (c) 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" This code is derived from software contributed to Berkeley by
-.\" Paul Borman at Krystal Technologies.
-.\"
-.\" 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.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
-.\"
-.\" @(#)euc.4 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/locale/euc.4,v 1.9 2001/07/15 07:53:05 dd Exp $
-.\"
-.Dd June 4, 1993
-.Dt EUC 4
-.Os
-.Sh NAME
-.Nm euc
-.Nd EUC encoding of runes
-.Sh SYNOPSIS
-.Nm ENCODING
-.Qq EUC
-.Pp
-.Nm VARIABLE
-.Ar len1
-.Ar mask1
-.Ar len2
-.Ar mask2
-.Ar len3
-.Ar mask3
-.Ar len4
-.Ar mask4
-.Ar mask
-.Sh DESCRIPTION
-The
-.Nm EUC
-encoding is provided for compatibility with
-.Ux
-based systems.
-See
-.Xr mklocale 1
-for a complete description of the
-.Ev LC_CTYPE
-source file format.
-.Pp
-.Nm EUC
-implements a system of 4 multibyte codesets.
-A multibyte character in the first codeset consists of
-.Ar len1
-bytes starting with a byte in the range of 0x00 to 0x7f.
-To allow use of ASCII,
-.Ar len1
-is always 1.
-A multibyte character in the second codeset consists of
-.Ar len2
-bytes starting with a byte in the range of 0x80-0xff excluding 0x8e and 0x8f.
-A multibyte character in the third codeset consists of
-.Ar len3
-bytes starting with the byte 0x8e.
-A multibyte character in the fourth codeset consists of
-.Ar len4
-bytes starting with the byte 0x8f.
-.Pp
-The
-.Ev rune_t
-encoding of
-.Nm EUC
-multibyte characters is dependent on the
-.Ar len
-and
-.Ar mask
-arguments.
-First, the bytes are moved into a
-.Ev rune_t
-as follows:
-.Bd -literal
-byte0 << ((\fIlen\fPN-1) * 8) | byte1 << ((\fIlen\fPN-2) * 8) | ... | byte\fIlen\fPN-1
-.Ed
-.Pp
-The result is then ANDed with
-.Ar ~mask
-and ORed with
-.Ar maskN .
-Codesets 2 and 3 are special in that the leading byte (0x8e or 0x8f) is
-first removed and the
-.Ar lenN
-argument is reduced by 1.
-.Pp
-For example, the Japanese locale has the following
-.Ev VARIABLE
-line:
-.Bd -literal
-VARIABLE 1 0x0000 2 0x8080 2 0x0080 3 0x8000 0x8080
-.Ed
-.Pp
-Codeset 1 consists of the values 0x0000 - 0x007f.
-.Pp
-Codeset 2 consists of the values who have the bits 0x8080 set.
-.Pp
-Codeset 3 consists of the values 0x0080 - 0x00ff.
-.Pp
-Codeset 4 consists of the values 0x8000 - 0xff7f excluding the values
-which have the 0x0080 bit set.
-.Pp
-Notice that the global
-.Ar mask
-is set to 0x8080, this implies that from those 2 bits the codeset can
-be determined.
-.Sh "EXAMPLE - Japanese Locale"
-This is a complete example of an
-.Ev LC_CTYPE
-source file for the Japanese locale
-.Bd -literal
-/*
- * Japanese LOCALE_CTYPE definitions using EUC of JIS character sets
- */
-
-ENCODING "EUC"
-
-/* JIS JIS JIS */
-/* X201 X208 X201 */
-/* 00-7f 84-fe */
-
-VARIABLE 1 0x0000 2 0x8080 2 0x0080 3 0x8000 0x8080
-
-/*
- * Code Set 1
- */
-ALPHA 'A' - 'Z' 'a' - 'z'
-CONTROL 0x00 - 0x1f 0x7f
-DIGIT '0' - '9'
-GRAPH 0x21 - 0x7e
-LOWER 'a' - 'z'
-PUNCT 0x21 - 0x2f 0x3a - 0x40 0x5b - 0x60 0x7b - 0x7e
-SPACE 0x09 - 0x0d 0x20
-UPPER 'A' - 'Z'
-XDIGIT 'a' - 'f' 'A' - 'F'
-BLANK ' ' '\t'
-PRINT 0x20 - 0x7e
-
-MAPLOWER < 'A' - 'Z' : 'a' > < 'a' - 'z' : 'a' >
-MAPUPPER < 'A' - 'Z' : 'A' > < 'a' - 'z' : 'A' >
-TODIGIT < '0' - '9' : 0 >
-TODIGIT < 'A' - 'F' : 10 > < 'a' - 'f' : 10 >
-
-/*
- * Code Set 2
- */
-
-SPACE 0xa1a1
-PHONOGRAM 0xa1bc
-SPECIAL 0xa1a2 - 0xa1fe
-PUNCT 0xa1a2 - 0xa1f8 /* A few too many in here... */
-
-SPECIAL 0xa2a1 - 0xa2ae 0xa2ba - 0xa2c1 0xa2ca - 0xa2d0 0xa2dc - 0xa2ea
-SPECIAL 0xa2f2 - 0xa2f9 0xa2fe
-
-DIGIT 0xa3b0 - 0xa3b9
-UPPER 0xa3c1 - 0xa3da /* Romaji */
-LOWER 0xa3e1 - 0xa3fa /* Romaji */
-MAPLOWER < 0xa3c1 - 0xa3da : 0xa3e1 > /* English */
-MAPLOWER < 0xa3e1 - 0xa3fa : 0xa3e1 > /* English */
-MAPUPPER < 0xa3c1 - 0xa3da : 0xa3c1 >
-MAPUPPER < 0xa3e1 - 0xa3fa : 0xa3c1 >
-
-XDIGIT 0xa3c1 - 0xa3c6 0xa3e1 - 0xa3e6
-
-TODIGIT < 0xa3b0 - 0xa3b9 : 0 >
-TODIGIT < 0xa3c1 - 0xa3c6 : 10 > < 0xa3e1 - 0xa3e6 : 10 >
-
-PHONOGRAM 0xa4a1 - 0xa4f3
-PHONOGRAM 0xa5a1 - 0xa5f6
-
-UPPER 0xa6a1 - 0xa6b8 /* Greek */
-LOWER 0xa6c1 - 0xa6d8 /* Greek */
-MAPLOWER < 0xa6a1 - 0xa6b8 : 0xa6c1 > < 0xa6c1 - 0xa6d8 : 0xa6c1 >
-MAPUPPER < 0xa6a1 - 0xa6b8 : 0xa6a1 > < 0xa6c1 - 0xa6d8 : 0xa6a1 >
-
-UPPER 0xa7a1 - 0xa7c1 /* Cyrillic */
-LOWER 0xa7d1 - 0xa7f1 /* Cyrillic */
-MAPLOWER < 0xa7a1 - 0xa7c1 : 0xa7d1 > < 0xa7d1 - 0xa7f1 : 0xa7d1 >
-MAPUPPER < 0xa7a1 - 0xa7c1 : 0xa7a1 > < 0xa7d1 - 0xa7f1 : 0xa7a1 >
-
-SPECIAL 0xa8a1 - 0xa8c0
-
-IDEOGRAM 0xb0a1 - 0xb0fe 0xb1a1 - 0xb1fe 0xb2a1 - 0xb2fe
-IDEOGRAM 0xb3a1 - 0xb3fe 0xb4a1 - 0xb4fe 0xb5a1 - 0xb5fe
-IDEOGRAM 0xb6a1 - 0xb6fe 0xb7a1 - 0xb7fe 0xb8a1 - 0xb8fe
-IDEOGRAM 0xb9a1 - 0xb9fe 0xbaa1 - 0xbafe 0xbba1 - 0xbbfe
-IDEOGRAM 0xbca1 - 0xbcfe 0xbda1 - 0xbdfe 0xbea1 - 0xbefe
-IDEOGRAM 0xbfa1 - 0xbffe 0xc0a1 - 0xc0fe 0xc1a1 - 0xc1fe
-IDEOGRAM 0xc2a1 - 0xc2fe 0xc3a1 - 0xc3fe 0xc4a1 - 0xc4fe
-IDEOGRAM 0xc5a1 - 0xc5fe 0xc6a1 - 0xc6fe 0xc7a1 - 0xc7fe
-IDEOGRAM 0xc8a1 - 0xc8fe 0xc9a1 - 0xc9fe 0xcaa1 - 0xcafe
-IDEOGRAM 0xcba1 - 0xcbfe 0xcca1 - 0xccfe 0xcda1 - 0xcdfe
-IDEOGRAM 0xcea1 - 0xcefe 0xcfa1 - 0xcfd3 0xd0a1 - 0xd0fe
-IDEOGRAM 0xd1a1 - 0xd1fe 0xd2a1 - 0xd2fe 0xd3a1 - 0xd3fe
-IDEOGRAM 0xd4a1 - 0xd4fe 0xd5a1 - 0xd5fe 0xd6a1 - 0xd6fe
-IDEOGRAM 0xd7a1 - 0xd7fe 0xd8a1 - 0xd8fe 0xd9a1 - 0xd9fe
-IDEOGRAM 0xdaa1 - 0xdafe 0xdba1 - 0xdbfe 0xdca1 - 0xdcfe
-IDEOGRAM 0xdda1 - 0xddfe 0xdea1 - 0xdefe 0xdfa1 - 0xdffe
-IDEOGRAM 0xe0a1 - 0xe0fe 0xe1a1 - 0xe1fe 0xe2a1 - 0xe2fe
-IDEOGRAM 0xe3a1 - 0xe3fe 0xe4a1 - 0xe4fe 0xe5a1 - 0xe5fe
-IDEOGRAM 0xe6a1 - 0xe6fe 0xe7a1 - 0xe7fe 0xe8a1 - 0xe8fe
-IDEOGRAM 0xe9a1 - 0xe9fe 0xeaa1 - 0xeafe 0xeba1 - 0xebfe
-IDEOGRAM 0xeca1 - 0xecfe 0xeda1 - 0xedfe 0xeea1 - 0xeefe
-IDEOGRAM 0xefa1 - 0xeffe 0xf0a1 - 0xf0fe 0xf1a1 - 0xf1fe
-IDEOGRAM 0xf2a1 - 0xf2fe 0xf3a1 - 0xf3fe 0xf4a1 - 0xf4a4
-/*
- * This is for Code Set 3, half-width kana
- */
-SPECIAL 0xa1 - 0xdf
-PHONOGRAM 0xa1 - 0xdf
-CONTROL 0x84 - 0x97 0x9b - 0x9f 0xe0 - 0xfe
-.Ed
-.Sh "SEE ALSO"
-.Xr mklocale 1 ,
-.Xr setlocale 3
--- /dev/null
+.\" Copyright (c) 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Paul Borman at Krystal Technologies.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" @(#)euc.4 8.1 (Berkeley) 6/4/93
+.\" $FreeBSD: src/lib/libc/locale/euc.5,v 1.12 2004/07/05 06:36:36 ru Exp $
+.\"
+.Dd November 8, 2003
+.Dt EUC 5
+.Os
+.Sh NAME
+.Nm euc
+.Nd EUC encoding of wide characters
+.Sh SYNOPSIS
+.Nm ENCODING
+.Qq EUC
+.Pp
+.Nm VARIABLE
+.Ar len1
+.Ar mask1
+.Ar len2
+.Ar mask2
+.Ar len3
+.Ar mask3
+.Ar len4
+.Ar mask4
+.Ar mask
+.Sh DESCRIPTION
+.\"The
+.\".Nm EUC
+.\"encoding is provided for compatibility with
+.\".Ux
+.\"based systems.
+.\"See
+.\".Xr mklocale 1
+.\"for a complete description of the
+.\".Ev LC_CTYPE
+.\"source file format.
+.\".Pp
+.Nm EUC
+implements a system of 4 multibyte codesets.
+A multibyte character in the first codeset consists of
+.Ar len1
+bytes starting with a byte in the range of 0x00 to 0x7f.
+To allow use of
+.Tn ASCII ,
+.Ar len1
+is always 1.
+A multibyte character in the second codeset consists of
+.Ar len2
+bytes starting with a byte in the range of 0x80-0xff excluding 0x8e and 0x8f.
+A multibyte character in the third codeset consists of
+.Ar len3
+bytes starting with the byte 0x8e.
+A multibyte character in the fourth codeset consists of
+.Ar len4
+bytes starting with the byte 0x8f.
+.Pp
+The
+.Vt wchar_t
+encoding of
+.Nm EUC
+multibyte characters is dependent on the
+.Ar len
+and
+.Ar mask
+arguments.
+First, the bytes are moved into a
+.Vt wchar_t
+as follows:
+.Bd -literal
+byte0 << ((\fIlen\fPN-1) * 8) | byte1 << ((\fIlen\fPN-2) * 8) | ... | byte\fIlen\fPN-1
+.Ed
+.Pp
+The result is then ANDed with
+.Ar ~mask
+and ORed with
+.Ar maskN .
+Codesets 2 and 3 are special in that the leading byte (0x8e or 0x8f) is
+first removed and the
+.Ar lenN
+argument is reduced by 1.
+.Pp
+For example, the
+.Li ja_JP.eucJP
+locale has the following
+.Va VARIABLE
+line:
+.Bd -literal
+VARIABLE 1 0x0000 2 0x8080 2 0x0080 3 0x8000 0x8080
+.Ed
+.Pp
+Codeset 1 consists of the values 0x0000 - 0x007f.
+.Pp
+Codeset 2 consists of the values who have the bits 0x8080 set.
+.Pp
+Codeset 3 consists of the values 0x0080 - 0x00ff.
+.Pp
+Codeset 4 consists of the values 0x8000 - 0xff7f excluding the values
+which have the 0x0080 bit set.
+.Pp
+Notice that the global
+.Ar mask
+is set to 0x8080, this implies that from those 2 bits the codeset can
+be determined.
+.Sh SEE ALSO
+.Xr mklocale 1 ,
+.Xr setlocale 3
/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved.
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
*
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)euc.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/euc.c,v 1.11 2002/08/09 08:22:29 ache Exp $");
-
-#include <sys/types.h>
+#include <sys/param.h>
+__FBSDID("$FreeBSD: src/lib/libc/locale/euc.c,v 1.20 2004/06/23 07:01:43 tjr Exp $");
#include <errno.h>
-#include <rune.h>
-#include <stddef.h>
-#include <stdio.h>
+#include <limits.h>
+#include <runetype.h>
#include <stdlib.h>
#include <string.h>
+#include <wchar.h>
+#include "mblocal.h"
-rune_t _EUC_sgetrune(const char *, size_t, char const **);
-int _EUC_sputrune(rune_t, char *, size_t, char **);
+int _EUC_init(_RuneLocale *);
+size_t _EUC_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
+ mbstate_t * __restrict);
+int _EUC_mbsinit(const mbstate_t *);
+size_t _EUC_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
typedef struct {
int count[4];
- rune_t bits[4];
- rune_t mask;
+ wchar_t bits[4];
+ wchar_t mask;
} _EucInfo;
+typedef struct {
+ wchar_t ch;
+ int set;
+ int want;
+} _EucState;
+
int
-_EUC_init(rl)
- _RuneLocale *rl;
+_EUC_init(_RuneLocale *rl)
{
_EucInfo *ei;
int x, new__mb_cur_max;
char *v, *e;
- rl->sgetrune = _EUC_sgetrune;
- rl->sputrune = _EUC_sputrune;
-
- if (rl->variable == NULL)
+ if (rl->__variable == NULL)
return (EFTYPE);
- v = (char *)rl->variable;
+ v = (char *)rl->__variable;
while (*v == ' ' || *v == '\t')
++v;
free(ei);
return (EFTYPE);
}
- rl->variable = ei;
- rl->variable_len = sizeof(_EucInfo);
+ rl->__variable = ei;
+ rl->__variable_len = sizeof(_EucInfo);
_CurrentRuneLocale = rl;
__mb_cur_max = new__mb_cur_max;
+ __mbrtowc = _EUC_mbrtowc;
+ __wcrtomb = _EUC_wcrtomb;
+ __mbsinit = _EUC_mbsinit;
return (0);
}
-#define CEI ((_EucInfo *)(_CurrentRuneLocale->variable))
+int
+_EUC_mbsinit(const mbstate_t *ps)
+{
+
+ return (ps == NULL || ((const _EucState *)ps)->want == 0);
+}
+
+#define CEI ((_EucInfo *)(_CurrentRuneLocale->__variable))
#define _SS2 0x008e
#define _SS3 0x008f
#define GR_BITS 0x80808080 /* XXX: to be fixed */
-static inline int
-_euc_set(c)
- u_int c;
+static __inline int
+_euc_set(u_int c)
{
c &= 0xff;
-
return ((c & 0x80) ? c == _SS3 ? 3 : c == _SS2 ? 2 : 1 : 0);
}
-rune_t
-_EUC_sgetrune(string, n, result)
- const char *string;
- size_t n;
- char const **result;
+
+size_t
+_EUC_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
+ mbstate_t * __restrict ps)
{
- rune_t rune = 0;
- int len, set;
+ _EucState *es;
+ int i, set, want;
+ wchar_t wc;
+ const char *os;
- if (n < 1 || (len = CEI->count[set = _euc_set(*string)]) > n) {
- if (result)
- *result = string;
- return (_INVALID_RUNE);
+ es = (_EucState *)ps;
+
+ if (es->want < 0 || es->want > MB_CUR_MAX || es->set < 0 ||
+ es->set > 3) {
+ errno = EINVAL;
+ return ((size_t)-1);
}
- switch (set) {
- case 3:
- case 2:
- --len;
- ++string;
- /* FALLTHROUGH */
- case 1:
- case 0:
- while (len-- > 0)
- rune = (rune << 8) | ((u_int)(*string++) & 0xff);
- break;
+
+ if (s == NULL) {
+ s = "";
+ n = 1;
+ pwc = NULL;
}
- if (result)
- *result = string;
- return ((rune & ~CEI->mask) | CEI->bits[set]);
+
+ if (n == 0)
+ /* Incomplete multibyte sequence */
+ return ((size_t)-2);
+
+ os = s;
+
+ if (es->want == 0) {
+ want = CEI->count[set = _euc_set(*s)];
+ if (set == 2 || set == 3) {
+ --want;
+ if (--n == 0) {
+ /* Incomplete multibyte sequence */
+ es->set = set;
+ es->want = want;
+ es->ch = 0;
+ return ((size_t)-2);
+ }
+ ++s;
+ if (*s == '\0') {
+ errno = EILSEQ;
+ return ((size_t)-1);
+ }
+ }
+ wc = (unsigned char)*s++;
+ } else {
+ set = es->set;
+ want = es->want;
+ wc = es->ch;
+ }
+ for (i = (es->want == 0) ? 1 : 0; i < MIN(want, n); i++) {
+ if (*s == '\0') {
+ errno = EILSEQ;
+ return ((size_t)-1);
+ }
+ wc = (wc << 8) | (unsigned char)*s++;
+ }
+ if (i < want) {
+ /* Incomplete multibyte sequence */
+ es->set = set;
+ es->want = want - i;
+ es->ch = wc;
+ return ((size_t)-2);
+ }
+ wc = (wc & ~CEI->mask) | CEI->bits[set];
+ if (pwc != NULL)
+ *pwc = wc;
+ es->want = 0;
+ return (wc == L'\0' ? 0 : s - os);
}
-int
-_EUC_sputrune(c, string, n, result)
- rune_t c;
- char *string, **result;
- size_t n;
+size_t
+_EUC_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
{
- rune_t m = c & CEI->mask;
- rune_t nm = c & ~m;
+ _EucState *es;
+ wchar_t m, nm;
int i, len;
+ es = (_EucState *)ps;
+
+ if (es->want != 0) {
+ errno = EINVAL;
+ return ((size_t)-1);
+ }
+
+ if (s == NULL)
+ /* Reset to initial shift state (no-op) */
+ return (1);
+
+ m = wc & CEI->mask;
+ nm = wc & ~m;
+
if (m == CEI->bits[1]) {
CodeSet1:
/* Codeset 1: The first byte must have 0x80 in it. */
i = len = CEI->count[1];
- if (n >= len) {
- if (result)
- *result = string + len;
- while (i-- > 0)
- *string++ = (nm >> (i << 3)) | 0x80;
- } else
- if (result)
- *result = (char *) 0;
+ while (i-- > 0)
+ *s++ = (nm >> (i << 3)) | 0x80;
} else {
- if (m == CEI->bits[0]) {
+ if (m == CEI->bits[0])
i = len = CEI->count[0];
- if (n < len) {
- if (result)
- *result = NULL;
- return (len);
- }
+ else if (m == CEI->bits[2]) {
+ i = len = CEI->count[2];
+ *s++ = _SS2;
+ --i;
+ /* SS2 designates G2 into GR */
+ nm |= GR_BITS;
+ } else if (m == CEI->bits[3]) {
+ i = len = CEI->count[3];
+ *s++ = _SS3;
+ --i;
+ /* SS3 designates G3 into GR */
+ nm |= GR_BITS;
} else
- if (m == CEI->bits[2]) {
- i = len = CEI->count[2];
- if (n < len) {
- if (result)
- *result = NULL;
- return (len);
- }
- *string++ = _SS2;
- --i;
- /* SS2 designates G2 into GR */
- nm |= GR_BITS;
- } else
- if (m == CEI->bits[3]) {
- i = len = CEI->count[3];
- if (n < len) {
- if (result)
- *result = NULL;
- return (len);
- }
- *string++ = _SS3;
- --i;
- /* SS3 designates G3 into GR */
- nm |= GR_BITS;
- } else
- goto CodeSet1; /* Bletch */
+ goto CodeSet1; /* Bletch */
while (i-- > 0)
- *string++ = (nm >> (i << 3)) & 0xff;
- if (result)
- *result = string;
+ *s++ = (nm >> (i << 3)) & 0xff;
}
return (len);
}
---- euc.c.orig Tue May 20 15:21:44 2003
-+++ euc.c Wed Jun 18 12:01:30 2003
-@@ -48,6 +48,7 @@
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-+#include <ctype.h>
-
- rune_t _EUC_sgetrune(const char *, size_t, char const **);
- int _EUC_sputrune(rune_t, char *, size_t, char **);
-@@ -135,11 +136,10 @@
- rune_t rune = 0;
- int len, set;
-
-- if (n < 1 || (len = CEI->count[set = _euc_set(*string)]) > n) {
-- if (result)
-- *result = string;
-+ if (result)
-+ *result = string;
-+ if (n < 1 || (len = CEI->count[set = _euc_set(*string)]) > n)
- return (_INVALID_RUNE);
-- }
- switch (set) {
- case 3:
- case 2:
-@@ -151,6 +151,11 @@
- while (len-- > 0)
- rune = (rune << 8) | ((u_int)(*string++) & 0xff);
- break;
-+ }
-+ if (!isrune(rune)) {
-+ if (result)
-+ (*result)++;
-+ return (_INVALID_RUNE);
+--- euc.c.orig Thu Nov 25 11:38:16 2004
++++ euc.c Fri Feb 18 15:30:38 2005
+@@ -41,6 +41,8 @@
+ #include <sys/param.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/euc.c,v 1.20 2004/06/23 07:01:43 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <errno.h>
+ #include <limits.h>
+ #include <runetype.h>
+@@ -49,11 +51,12 @@
+ #include <wchar.h>
+ #include "mblocal.h"
+
+-int _EUC_init(_RuneLocale *);
+-size_t _EUC_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
+- mbstate_t * __restrict);
+-int _EUC_mbsinit(const mbstate_t *);
+-size_t _EUC_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
++__private_extern__ int _EUC_init(struct __xlocale_st_runelocale *);
++static size_t _EUC_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
++ mbstate_t * __restrict, locale_t);
++static int _EUC_mbsinit(const mbstate_t *, locale_t);
++static size_t _EUC_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict,
++ locale_t);
+
+ typedef struct {
+ int count[4];
+@@ -67,12 +70,20 @@
+ int want;
+ } _EucState;
+
+-int
+-_EUC_init(_RuneLocale *rl)
++/* This will be called by the XL_RELEASE() macro to free the extra storage */
++static void
++_EUC_free_extra(struct __xlocale_st_runelocale *xrl)
++{
++ free(xrl->_CurrentRuneLocale.__variable);
++}
++
++__private_extern__ int
++_EUC_init(struct __xlocale_st_runelocale *xrl)
+ {
+ _EucInfo *ei;
+ int x, new__mb_cur_max;
+ char *v, *e;
++ _RuneLocale *rl = &xrl->_CurrentRuneLocale;
+
+ if (rl->__variable == NULL)
+ return (EFTYPE);
+@@ -111,23 +122,21 @@
}
- if (result)
- *result = string;
+ rl->__variable = ei;
+ rl->__variable_len = sizeof(_EucInfo);
+- _CurrentRuneLocale = rl;
+- __mb_cur_max = new__mb_cur_max;
+- __mbrtowc = _EUC_mbrtowc;
+- __wcrtomb = _EUC_wcrtomb;
+- __mbsinit = _EUC_mbsinit;
++ xrl->__mb_cur_max = new__mb_cur_max;
++ xrl->__mbrtowc = _EUC_mbrtowc;
++ xrl->__wcrtomb = _EUC_wcrtomb;
++ xrl->__mbsinit = _EUC_mbsinit;
++ xrl->__free_extra = (__free_extra_t)_EUC_free_extra;
+ return (0);
+ }
+
+-int
+-_EUC_mbsinit(const mbstate_t *ps)
++static int
++_EUC_mbsinit(const mbstate_t *ps, locale_t loc)
+ {
+
+ return (ps == NULL || ((const _EucState *)ps)->want == 0);
+ }
+
+-#define CEI ((_EucInfo *)(_CurrentRuneLocale->__variable))
+-
+ #define _SS2 0x008e
+ #define _SS3 0x008f
+
+@@ -140,18 +149,20 @@
+ return ((c & 0x80) ? c == _SS3 ? 3 : c == _SS2 ? 2 : 1 : 0);
+ }
+
+-size_t
++static size_t
+ _EUC_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
+- mbstate_t * __restrict ps)
++ mbstate_t * __restrict ps, locale_t loc)
+ {
+ _EucState *es;
+ int i, set, want;
+ wchar_t wc;
+ const char *os;
++ struct __xlocale_st_runelocale *rl = loc->__lc_ctype;
++ _EucInfo *CEI = (_EucInfo *)rl->_CurrentRuneLocale.__variable;
+
+ es = (_EucState *)ps;
+
+- if (es->want < 0 || es->want > MB_CUR_MAX || es->set < 0 ||
++ if (es->want < 0 || es->want > rl->__mb_cur_max || es->set < 0 ||
+ es->set > 3) {
+ errno = EINVAL;
+ return ((size_t)-1);
+@@ -213,12 +224,14 @@
+ return (wc == L'\0' ? 0 : s - os);
+ }
+
+-size_t
+-_EUC_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
++static size_t
++_EUC_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps,
++ locale_t loc)
+ {
+ _EucState *es;
+ wchar_t m, nm;
+ int i, len;
++ _EucInfo *CEI = (_EucInfo *)loc->__lc_ctype->_CurrentRuneLocale.__variable;
+
+ es = (_EucState *)ps;
+
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/fix_grouping.c,v 1.7 2002/03/22 21:52:18 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/fix_grouping.c,v 1.8 2003/06/26 10:46:16 phantom Exp $");
#include <ctype.h>
#include <limits.h>
static const char nogrouping[] = { CHAR_MAX, '\0' };
/*
- * "3;3;-1" -> "\003\003\177"
+ * Internal helper used to convert grouping sequences from string
+ * representation into POSIX specified form, i.e.
+ *
+ * "3;3;-1" -> "\003\003\177\000"
*/
const char *
-__fix_locale_grouping_str(const char *str) {
-
+__fix_locale_grouping_str(const char *str)
+{
char *src, *dst;
char n;
+++ /dev/null
-/*-
- * Copyright (c) 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Paul Borman at Krystal Technologies.
- *
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)frune.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/frune.c,v 1.3 2002/09/18 06:19:12 tjr Exp $");
-
-#include <limits.h>
-#include <rune.h>
-#include <stddef.h>
-#include <stdio.h>
-
-__warn_references(fgetrune, "warning: fgetrune() is deprecated. See fgetrune(3).");
-long
-fgetrune(fp)
- FILE *fp;
-{
- rune_t r;
- int c, len;
- char buf[MB_LEN_MAX];
- char const *result;
-
- len = 0;
- do {
- if ((c = getc(fp)) == EOF) {
- if (len)
- break;
- return (EOF);
- }
- buf[len++] = c;
-
- if ((r = sgetrune(buf, len, &result)) != _INVALID_RUNE)
- return (r);
- } while (result == buf && len < MB_LEN_MAX);
-
- while (--len > 0)
- ungetc(buf[len], fp);
- return (_INVALID_RUNE);
-}
-
-__warn_references(fungetrune, "warning: fungetrune() is deprecated. See fungetrune(3).");
-int
-fungetrune(r, fp)
- rune_t r;
- FILE* fp;
-{
- int len;
- char buf[MB_LEN_MAX];
-
- len = sputrune(r, buf, MB_LEN_MAX, 0);
- while (len-- > 0)
- if (ungetc(buf[len], fp) == EOF)
- return (EOF);
- return (0);
-}
-
-__warn_references(fputrune, "warning: fputrune() is deprecated. See fputrune(3).");
-int
-fputrune(r, fp)
- rune_t r;
- FILE *fp;
-{
- int i, len;
- char buf[MB_LEN_MAX];
-
- len = sputrune(r, buf, MB_LEN_MAX, 0);
-
- for (i = 0; i < len; ++i)
- if (putc(buf[i], fp) == EOF)
- return (EOF);
-
- return (0);
-}
--- /dev/null
+.\" Copyright (c) 2002, 2003 Tim J. Robbins
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/locale/gb18030.5,v 1.6 2004/07/05 06:36:36 ru Exp $
+.\"
+.Dd August 10, 2003
+.Dt GB18030 5
+.Os
+.Sh NAME
+.Nm gb18030
+.Nd "GB 18030 encoding method for Chinese text"
+.Sh SYNOPSIS
+.Nm ENCODING
+.Qq GB18030
+.Sh DESCRIPTION
+The
+.Nm GB18030
+encoding implements GB 18030-2000, a PRC national standard for the encoding of
+Chinese characters.
+It is a superset of the older GB\ 2312-1980 and GBK encodings,
+and incorporates Unicode's Unihan Extension A completely.
+It also provides code space for all Unicode 3.0 code points.
+.Pp
+Multibyte characters in the
+.Nm GB18030
+encoding can be one byte, two bytes, or
+four bytes long.
+There are a total of over 1.5 million code positions.
+.Pp
+.No GB\ 11383-1981 Pq Tn ASCII
+characters are represented by single bytes in the range 0x00 to 0x7F.
+.Pp
+Chinese characters are represented as either two bytes or four bytes.
+Characters that are represented by two bytes begin with a byte in the range
+0x81-0xFE and end with a byte either in the range 0x40-0x7E or 0x80-0xFE.
+.Pp
+Characters that are represented by four bytes begin with a byte in the range
+0x81-0xFE, have a second byte in the range 0x30-0x39, a third byte in the range
+0x81-0xFE and a fourth byte in the range 0x30-0x39.
+.Sh SEE ALSO
+.Xr euc 5 ,
+.Xr gb2312 5 ,
+.Xr gbk 5 ,
+.Xr utf8 5
+.Rs
+.%T "Chinese National Standard GB 18030-2000: Information Technology -- Chinese ideograms coded character set for information interchange -- Extension for the basic set"
+.%D "March 2000"
+.Re
+.Rs
+.%Q "The Unicode Consortium"
+.%T "The Unicode Standard, Version 3.0"
+.%D "2000"
+.Re
+.Sh STANDARDS
+The
+.Nm GB18030
+encoding is believed to be compatible with GB 18030-2000.
--- /dev/null
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins
+ * 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.
+ */
+/*
+ * PRC National Standard GB 18030-2000 encoding of Chinese text.
+ *
+ * See gb18030(5) for details.
+ */
+
+#include <sys/param.h>
+__FBSDID("$FreeBSD: src/lib/libc/locale/gb18030.c,v 1.6 2004/05/12 14:09:04 tjr Exp $");
+
+#include <errno.h>
+#include <runetype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include "mblocal.h"
+
+int _GB18030_init(_RuneLocale *);
+size_t _GB18030_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
+ mbstate_t * __restrict);
+int _GB18030_mbsinit(const mbstate_t *);
+size_t _GB18030_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
+
+typedef struct {
+ int count;
+ u_char bytes[4];
+} _GB18030State;
+
+int
+_GB18030_init(_RuneLocale *rl)
+{
+
+ __mbrtowc = _GB18030_mbrtowc;
+ __wcrtomb = _GB18030_wcrtomb;
+ __mbsinit = _GB18030_mbsinit;
+ _CurrentRuneLocale = rl;
+ __mb_cur_max = 4;
+
+ return (0);
+}
+
+int
+_GB18030_mbsinit(const mbstate_t *ps)
+{
+
+ return (ps == NULL || ((const _GB18030State *)ps)->count == 0);
+}
+
+size_t
+_GB18030_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s,
+ size_t n, mbstate_t * __restrict ps)
+{
+ _GB18030State *gs;
+ wchar_t wch;
+ int ch, len, ocount;
+ size_t ncopy;
+
+ gs = (_GB18030State *)ps;
+
+ if (gs->count < 0 || gs->count > sizeof(gs->bytes)) {
+ errno = EINVAL;
+ return ((size_t)-1);
+ }
+
+ if (s == NULL) {
+ s = "";
+ n = 1;
+ pwc = NULL;
+ }
+
+ ncopy = MIN(MIN(n, MB_CUR_MAX), sizeof(gs->bytes) - gs->count);
+ memcpy(gs->bytes + gs->count, s, ncopy);
+ ocount = gs->count;
+ gs->count += ncopy;
+ s = (char *)gs->bytes;
+ n = gs->count;
+
+ if (n == 0)
+ /* Incomplete multibyte sequence */
+ return ((size_t)-2);
+
+ /*
+ * Single byte: [00-7f]
+ * Two byte: [81-fe][40-7e,80-fe]
+ * Four byte: [81-fe][30-39][81-fe][30-39]
+ */
+ ch = (unsigned char)*s++;
+ if (ch <= 0x7f) {
+ len = 1;
+ wch = ch;
+ } else if (ch >= 0x81 && ch <= 0xfe) {
+ wch = ch;
+ if (n < 2)
+ return ((size_t)-2);
+ ch = (unsigned char)*s++;
+ if ((ch >= 0x40 && ch <= 0x7e) || (ch >= 0x80 && ch <= 0xfe)) {
+ wch = (wch << 8) | ch;
+ len = 2;
+ } else if (ch >= 0x30 && ch <= 0x39) {
+ /*
+ * Strip high bit off the wide character we will
+ * eventually output so that it is positive when
+ * cast to wint_t on 32-bit twos-complement machines.
+ */
+ wch = ((wch & 0x7f) << 8) | ch;
+ if (n < 3)
+ return ((size_t)-2);
+ ch = (unsigned char)*s++;
+ if (ch < 0x81 || ch > 0xfe)
+ goto ilseq;
+ wch = (wch << 8) | ch;
+ if (n < 4)
+ return ((size_t)-2);
+ ch = (unsigned char)*s++;
+ if (ch < 0x30 || ch > 0x39)
+ goto ilseq;
+ wch = (wch << 8) | ch;
+ len = 4;
+ } else
+ goto ilseq;
+ } else
+ goto ilseq;
+
+ if (pwc != NULL)
+ *pwc = wch;
+ gs->count = 0;
+ return (wch == L'\0' ? 0 : len - ocount);
+ilseq:
+ errno = EILSEQ;
+ return ((size_t)-1);
+}
+
+size_t
+_GB18030_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
+{
+ _GB18030State *gs;
+ size_t len;
+ int c;
+
+ gs = (_GB18030State *)ps;
+
+ if (gs->count != 0) {
+ errno = EINVAL;
+ return ((size_t)-1);
+ }
+
+ if (s == NULL)
+ /* Reset to initial shift state (no-op) */
+ return (1);
+ if ((wc & ~0x7fffffff) != 0)
+ goto ilseq;
+ if (wc & 0x7f000000) {
+ /* Replace high bit that mbrtowc() removed. */
+ wc |= 0x80000000;
+ c = (wc >> 24) & 0xff;
+ if (c < 0x81 || c > 0xfe)
+ goto ilseq;
+ *s++ = c;
+ c = (wc >> 16) & 0xff;
+ if (c < 0x30 || c > 0x39)
+ goto ilseq;
+ *s++ = c;
+ c = (wc >> 8) & 0xff;
+ if (c < 0x81 || c > 0xfe)
+ goto ilseq;
+ *s++ = c;
+ c = wc & 0xff;
+ if (c < 0x30 || c > 0x39)
+ goto ilseq;
+ *s++ = c;
+ len = 4;
+ } else if (wc & 0x00ff0000)
+ goto ilseq;
+ else if (wc & 0x0000ff00) {
+ c = (wc >> 8) & 0xff;
+ if (c < 0x81 || c > 0xfe)
+ goto ilseq;
+ *s++ = c;
+ c = wc & 0xff;
+ if (c < 0x40 || c == 0x7f || c == 0xff)
+ goto ilseq;
+ *s++ = c;
+ len = 2;
+ } else if (wc <= 0x7f) {
+ *s++ = wc;
+ len = 1;
+ } else
+ goto ilseq;
+
+ return (len);
+ilseq:
+ errno = EILSEQ;
+ return ((size_t)-1);
+}
--- /dev/null
+--- gb18030.c.orig Thu Nov 25 11:38:16 2004
++++ gb18030.c Fri Feb 18 15:43:22 2005
+@@ -32,6 +32,8 @@
+ #include <sys/param.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/gb18030.c,v 1.6 2004/05/12 14:09:04 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <errno.h>
+ #include <runetype.h>
+ #include <stdlib.h>
+@@ -39,40 +41,41 @@
+ #include <wchar.h>
+ #include "mblocal.h"
+
+-int _GB18030_init(_RuneLocale *);
+-size_t _GB18030_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
+- mbstate_t * __restrict);
+-int _GB18030_mbsinit(const mbstate_t *);
+-size_t _GB18030_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
++#define GB18030_MB_CUR_MAX 4
++
++__private_extern__ int _GB18030_init(struct __xlocale_st_runelocale *);
++static size_t _GB18030_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
++ mbstate_t * __restrict, locale_t);
++static int _GB18030_mbsinit(const mbstate_t *, locale_t);
++static size_t _GB18030_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict, locale_t);
+
+ typedef struct {
+ int count;
+ u_char bytes[4];
+ } _GB18030State;
+
+-int
+-_GB18030_init(_RuneLocale *rl)
++__private_extern__ int
++_GB18030_init(struct __xlocale_st_runelocale *xrl)
+ {
+
+- __mbrtowc = _GB18030_mbrtowc;
+- __wcrtomb = _GB18030_wcrtomb;
+- __mbsinit = _GB18030_mbsinit;
+- _CurrentRuneLocale = rl;
+- __mb_cur_max = 4;
++ xrl->__mbrtowc = _GB18030_mbrtowc;
++ xrl->__wcrtomb = _GB18030_wcrtomb;
++ xrl->__mbsinit = _GB18030_mbsinit;
++ xrl->__mb_cur_max = GB18030_MB_CUR_MAX;
+
+ return (0);
+ }
+
+-int
+-_GB18030_mbsinit(const mbstate_t *ps)
++static int
++_GB18030_mbsinit(const mbstate_t *ps, locale_t loc)
+ {
+
+ return (ps == NULL || ((const _GB18030State *)ps)->count == 0);
+ }
+
+-size_t
++static size_t
+ _GB18030_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s,
+- size_t n, mbstate_t * __restrict ps)
++ size_t n, mbstate_t * __restrict ps, locale_t loc)
+ {
+ _GB18030State *gs;
+ wchar_t wch;
+@@ -92,7 +95,7 @@
+ pwc = NULL;
+ }
+
+- ncopy = MIN(MIN(n, MB_CUR_MAX), sizeof(gs->bytes) - gs->count);
++ ncopy = MIN(MIN(n, GB18030_MB_CUR_MAX), sizeof(gs->bytes) - gs->count);
+ memcpy(gs->bytes + gs->count, s, ncopy);
+ ocount = gs->count;
+ gs->count += ncopy;
+@@ -154,8 +157,8 @@
+ return ((size_t)-1);
+ }
+
+-size_t
+-_GB18030_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
++static size_t
++_GB18030_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps, locale_t loc)
+ {
+ _GB18030State *gs;
+ size_t len;
--- /dev/null
+.\" Copyright (c) 2003 Tim J. Robbins
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/locale/gb2312.5,v 1.4 2004/07/05 06:36:36 ru Exp $
+.\"
+.Dd November 7, 2003
+.Dt GB2312 5
+.Os
+.Sh NAME
+.Nm gb2312
+.Nd "GB2312 encoding method for Chinese text"
+.Sh SYNOPSIS
+.Nm ENCODING
+.Qq GB2312
+.Sh DESCRIPTION
+The
+.Nm GB2312
+encoding implements GB\ 2312-1980, a PRC national standard
+for the encoding of simplified Chinese characters.
+.Pp
+Multibyte characters in the GB2312
+encoding can be one byte or two bytes long.
+.No GB\ 11383-1981 Pq Tn ASCII
+characters are represented by single bytes in the range 0x00 to 0x7F.
+Simplified Chinese characters are represented by two bytes, both in
+the range 0xA1-0xFE.
+.Sh SEE ALSO
+.Xr euc 5 ,
+.Xr gb18030 5 ,
+.Xr gbk 5
+.Sh STANDARDS
+The
+.Nm GB2312
+encoding is believed to be compatible with GB\ 2312-1980.
+This standard has been superseded by GB\ 18030-2000, but is still
+in wide use.
--- /dev/null
+/*-
+ * Copyright (c) 2004 Tim J. Robbins. All rights reserved.
+ * Copyright (c) 2003 David Xu <davidxu@freebsd.org>
+ * 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 <sys/param.h>
+__FBSDID("$FreeBSD: src/lib/libc/locale/gb2312.c,v 1.8 2004/05/12 14:09:04 tjr Exp $");
+
+#include <errno.h>
+#include <runetype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include "mblocal.h"
+
+int _GB2312_init(_RuneLocale *);
+size_t _GB2312_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
+ mbstate_t * __restrict);
+int _GB2312_mbsinit(const mbstate_t *);
+size_t _GB2312_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
+
+typedef struct {
+ int count;
+ u_char bytes[2];
+} _GB2312State;
+
+int
+_GB2312_init(_RuneLocale *rl)
+{
+
+ _CurrentRuneLocale = rl;
+ __mbrtowc = _GB2312_mbrtowc;
+ __wcrtomb = _GB2312_wcrtomb;
+ __mbsinit = _GB2312_mbsinit;
+ __mb_cur_max = 2;
+ return (0);
+}
+
+int
+_GB2312_mbsinit(const mbstate_t *ps)
+{
+
+ return (ps == NULL || ((const _GB2312State *)ps)->count == 0);
+}
+
+static __inline int
+_GB2312_check(const char *str, size_t n)
+{
+ const u_char *s = (const u_char *)str;
+
+ if (n == 0)
+ /* Incomplete multibyte sequence */
+ return (-2);
+ if (s[0] >= 0xa1 && s[0] <= 0xfe) {
+ if (n < 2)
+ /* Incomplete multibyte sequence */
+ return (-2);
+ if (s[1] < 0xa1 || s[1] > 0xfe)
+ /* Invalid multibyte sequence */
+ return (-1);
+ return (2);
+ } else if (s[0] & 0x80) {
+ /* Invalid multibyte sequence */
+ return (-1);
+ }
+ return (1);
+}
+
+size_t
+_GB2312_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
+ mbstate_t * __restrict ps)
+{
+ _GB2312State *gs;
+ wchar_t wc;
+ int i, len, ocount;
+ size_t ncopy;
+
+ gs = (_GB2312State *)ps;
+
+ if (gs->count < 0 || gs->count > sizeof(gs->bytes)) {
+ errno = EINVAL;
+ return ((size_t)-1);
+ }
+
+ if (s == NULL) {
+ s = "";
+ n = 1;
+ pwc = NULL;
+ }
+
+ ncopy = MIN(MIN(n, MB_CUR_MAX), sizeof(gs->bytes) - gs->count);
+ memcpy(gs->bytes + gs->count, s, ncopy);
+ ocount = gs->count;
+ gs->count += ncopy;
+ s = (char *)gs->bytes;
+ n = gs->count;
+
+ if ((len = _GB2312_check(s, n)) < 0)
+ return ((size_t)len);
+ wc = 0;
+ i = len;
+ while (i-- > 0)
+ wc = (wc << 8) | (unsigned char)*s++;
+ if (pwc != NULL)
+ *pwc = wc;
+ gs->count = 0;
+ return (wc == L'\0' ? 0 : len - ocount);
+}
+
+size_t
+_GB2312_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
+{
+ _GB2312State *gs;
+
+ gs = (_GB2312State *)ps;
+
+ if (gs->count != 0) {
+ errno = EINVAL;
+ return ((size_t)-1);
+ }
+
+ if (s == NULL)
+ /* Reset to initial shift state (no-op) */
+ return (1);
+ if (wc & 0x8000) {
+ *s++ = (wc >> 8) & 0xff;
+ *s = wc & 0xff;
+ return (2);
+ }
+ *s = wc & 0xff;
+ return (1);
+}
--- /dev/null
+--- gb2312.c.orig Thu Nov 25 11:38:17 2004
++++ gb2312.c Fri Feb 18 15:45:33 2005
+@@ -28,6 +28,8 @@
+ #include <sys/param.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/gb2312.c,v 1.8 2004/05/12 14:09:04 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <errno.h>
+ #include <runetype.h>
+ #include <stdlib.h>
+@@ -35,31 +37,32 @@
+ #include <wchar.h>
+ #include "mblocal.h"
+
+-int _GB2312_init(_RuneLocale *);
+-size_t _GB2312_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
+- mbstate_t * __restrict);
+-int _GB2312_mbsinit(const mbstate_t *);
+-size_t _GB2312_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
++#define GB2312_MB_CUR_MAX 2
++
++__private_extern__ int _GB2312_init(struct __xlocale_st_runelocale *);
++static size_t _GB2312_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
++ mbstate_t * __restrict, locale_t);
++static int _GB2312_mbsinit(const mbstate_t *, locale_t);
++static size_t _GB2312_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict, locale_t);
+
+ typedef struct {
+ int count;
+ u_char bytes[2];
+ } _GB2312State;
+
+-int
+-_GB2312_init(_RuneLocale *rl)
++__private_extern__ int
++_GB2312_init(struct __xlocale_st_runelocale *xrl)
+ {
+
+- _CurrentRuneLocale = rl;
+- __mbrtowc = _GB2312_mbrtowc;
+- __wcrtomb = _GB2312_wcrtomb;
+- __mbsinit = _GB2312_mbsinit;
+- __mb_cur_max = 2;
++ xrl->__mbrtowc = _GB2312_mbrtowc;
++ xrl->__wcrtomb = _GB2312_wcrtomb;
++ xrl->__mbsinit = _GB2312_mbsinit;
++ xrl->__mb_cur_max = GB2312_MB_CUR_MAX;
+ return (0);
+ }
+
+-int
+-_GB2312_mbsinit(const mbstate_t *ps)
++static int
++_GB2312_mbsinit(const mbstate_t *ps, locale_t loc)
+ {
+
+ return (ps == NULL || ((const _GB2312State *)ps)->count == 0);
+@@ -88,9 +91,9 @@
+ return (1);
+ }
+
+-size_t
++static size_t
+ _GB2312_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
+- mbstate_t * __restrict ps)
++ mbstate_t * __restrict ps, locale_t loc)
+ {
+ _GB2312State *gs;
+ wchar_t wc;
+@@ -110,7 +113,7 @@
+ pwc = NULL;
+ }
+
+- ncopy = MIN(MIN(n, MB_CUR_MAX), sizeof(gs->bytes) - gs->count);
++ ncopy = MIN(MIN(n, GB2312_MB_CUR_MAX), sizeof(gs->bytes) - gs->count);
+ memcpy(gs->bytes + gs->count, s, ncopy);
+ ocount = gs->count;
+ gs->count += ncopy;
+@@ -129,8 +132,8 @@
+ return (wc == L'\0' ? 0 : len - ocount);
+ }
+
+-size_t
+-_GB2312_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
++static size_t
++_GB2312_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps, locale_t loc)
+ {
+ _GB2312State *gs;
+
--- /dev/null
+.\" Copyright (c) 2003 Tim J. Robbins
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/locale/gbk.5,v 1.4 2004/07/05 06:36:36 ru Exp $
+.\"
+.Dd August 10, 2003
+.Dt GBK 5
+.Os
+.Sh NAME
+.Nm gbk
+.Nd "Guojia biaozhun kuozhan (GBK) encoding method for Chinese text"
+.Sh SYNOPSIS
+.Nm ENCODING
+.Qq GBK
+.Sh DESCRIPTION
+GBK is a backwards-compatible extension of the GB\ 2312-1980 encoding
+method for Chinese text, which adds the characters defined in the
+Unified Han portion of the Unicode 2.1 standard.
+.Pp
+Multibyte characters in the GBK
+encoding can be one byte or two bytes long.
+.No GB\ 11383-1981 Pq Tn ASCII
+characters are represented by single bytes in the range 0x00 to 0x7F.
+Chinese characters are represented by two bytes, beginning with a byte in
+the range 0x80-0xFE and ending with a byte in the range 0x40-0xFE.
+.Sh SEE ALSO
+.Xr euc 5 ,
+.Xr gb18030 5 ,
+.Xr gb2312 5 ,
+.Xr utf8 5
+.Rs
+.%Q "The Unicode Consortium"
+.%T "The Unicode Standard, Version 2.1"
+.%D "1999"
+.Re
+.Rs
+.%T "Chinese National Standard GB 18030-2000: Information Technology -- Chinese ideograms coded character set for information interchange -- Extension for the basic set"
+.%D "March 2000"
+.Re
+.Sh STANDARDS
+GBK is not a standard, but has been superseded by
+GB\ 18030-2000.
--- /dev/null
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved.
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Paul Borman at Krystal Technologies.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <sys/param.h>
+__FBSDID("$FreeBSD: src/lib/libc/locale/gbk.c,v 1.11 2004/05/17 11:16:14 tjr Exp $");
+
+#include <errno.h>
+#include <runetype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include "mblocal.h"
+
+int _GBK_init(_RuneLocale *);
+size_t _GBK_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
+ mbstate_t * __restrict);
+int _GBK_mbsinit(const mbstate_t *);
+size_t _GBK_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
+
+typedef struct {
+ wchar_t ch;
+} _GBKState;
+
+int
+_GBK_init(_RuneLocale *rl)
+{
+
+ __mbrtowc = _GBK_mbrtowc;
+ __wcrtomb = _GBK_wcrtomb;
+ __mbsinit = _GBK_mbsinit;
+ _CurrentRuneLocale = rl;
+ __mb_cur_max = 2;
+ return (0);
+}
+
+int
+_GBK_mbsinit(const mbstate_t *ps)
+{
+
+ return (ps == NULL || ((const _GBKState *)ps)->ch == 0);
+}
+
+static __inline int
+_gbk_check(u_int c)
+{
+
+ c &= 0xff;
+ return ((c >= 0x81 && c <= 0xfe) ? 2 : 1);
+}
+
+size_t
+_GBK_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
+ mbstate_t * __restrict ps)
+{
+ _GBKState *gs;
+ wchar_t wc;
+ size_t len;
+
+ gs = (_GBKState *)ps;
+
+ if ((gs->ch & ~0xFF) != 0) {
+ /* Bad conversion state. */
+ errno = EINVAL;
+ return ((size_t)-1);
+ }
+
+ if (s == NULL) {
+ s = "";
+ n = 1;
+ pwc = NULL;
+ }
+
+ if (n == 0)
+ /* Incomplete multibyte sequence */
+ return ((size_t)-2);
+
+ if (gs->ch != 0) {
+ if (*s == '\0') {
+ errno = EILSEQ;
+ return ((size_t)-1);
+ }
+ wc = (gs->ch << 8) | (*s & 0xFF);
+ if (pwc != NULL)
+ *pwc = wc;
+ gs->ch = 0;
+ return (1);
+ }
+
+ len = (size_t)_gbk_check(*s);
+ wc = *s++ & 0xff;
+ if (len == 2) {
+ if (n < 2) {
+ /* Incomplete multibyte sequence */
+ gs->ch = wc;
+ return ((size_t)-2);
+ }
+ if (*s == '\0') {
+ errno = EILSEQ;
+ return ((size_t)-1);
+ }
+ wc = (wc << 8) | (*s++ & 0xff);
+ if (pwc != NULL)
+ *pwc = wc;
+ return (2);
+ } else {
+ if (pwc != NULL)
+ *pwc = wc;
+ return (wc == L'\0' ? 0 : 1);
+ }
+}
+
+size_t
+_GBK_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
+{
+ _GBKState *gs;
+
+ gs = (_GBKState *)ps;
+
+ if (gs->ch != 0) {
+ errno = EINVAL;
+ return ((size_t)-1);
+ }
+
+ if (s == NULL)
+ /* Reset to initial shift state (no-op) */
+ return (1);
+ if (wc & 0x8000) {
+ *s++ = (wc >> 8) & 0xff;
+ *s = wc & 0xff;
+ return (2);
+ }
+ *s = wc & 0xff;
+ return (1);
+}
--- /dev/null
+--- gbk.c.orig Thu Nov 25 11:38:17 2004
++++ gbk.c Fri Feb 18 15:46:58 2005
+@@ -38,6 +38,8 @@
+ #include <sys/param.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/gbk.c,v 1.11 2004/05/17 11:16:14 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <errno.h>
+ #include <runetype.h>
+ #include <stdlib.h>
+@@ -45,30 +47,29 @@
+ #include <wchar.h>
+ #include "mblocal.h"
+
+-int _GBK_init(_RuneLocale *);
+-size_t _GBK_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
+- mbstate_t * __restrict);
+-int _GBK_mbsinit(const mbstate_t *);
+-size_t _GBK_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
++__private_extern__ int _GBK_init(struct __xlocale_st_runelocale *);
++static size_t _GBK_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
++ mbstate_t * __restrict, locale_t);
++static int _GBK_mbsinit(const mbstate_t *, locale_t);
++static size_t _GBK_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict, locale_t);
+
+ typedef struct {
+ wchar_t ch;
+ } _GBKState;
+
+-int
+-_GBK_init(_RuneLocale *rl)
++__private_extern__ int
++_GBK_init(struct __xlocale_st_runelocale *xrl)
+ {
+
+- __mbrtowc = _GBK_mbrtowc;
+- __wcrtomb = _GBK_wcrtomb;
+- __mbsinit = _GBK_mbsinit;
+- _CurrentRuneLocale = rl;
+- __mb_cur_max = 2;
++ xrl->__mbrtowc = _GBK_mbrtowc;
++ xrl->__wcrtomb = _GBK_wcrtomb;
++ xrl->__mbsinit = _GBK_mbsinit;
++ xrl->__mb_cur_max = 2;
+ return (0);
+ }
+
+-int
+-_GBK_mbsinit(const mbstate_t *ps)
++static int
++_GBK_mbsinit(const mbstate_t *ps, locale_t loc)
+ {
+
+ return (ps == NULL || ((const _GBKState *)ps)->ch == 0);
+@@ -82,9 +83,9 @@
+ return ((c >= 0x81 && c <= 0xfe) ? 2 : 1);
+ }
+
+-size_t
++static size_t
+ _GBK_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
+- mbstate_t * __restrict ps)
++ mbstate_t * __restrict ps, locale_t loc)
+ {
+ _GBKState *gs;
+ wchar_t wc;
+@@ -143,8 +144,8 @@
+ }
+ }
+
+-size_t
+-_GBK_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
++static size_t
++_GBK_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps, locale_t loc)
+ {
+ _GBKState *gs;
+
.\" SUCH DAMAGE.
.\"
.\" @(#)isalnum.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/locale/isalnum.3,v 1.17 2002/10/06 10:15:38 tjr Exp $
+.\" $FreeBSD: src/lib/libc/locale/isalnum.3,v 1.19 2004/08/21 07:37:08 tjr Exp $
.\"
-.Dd October 6, 2002
+.Dd August 21, 2004
.Dt ISALNUM 3
.Os
.Sh NAME
function returns zero if the character tests false and
returns non-zero if the character tests true.
.Sh COMPATIBILITY
-Although
-.Fn isalnum
-accepts arguments outside of the range of the
-.Vt "unsigned char"
-type in locales with large character sets,
-this is a
+The
.Bx 4.4
-extension and the
+extension of accepting arguments outside of the range of the
+.Vt "unsigned char"
+type in locales with large character sets is considered obsolete
+and may not be supported in future releases.
+The
.Fn iswalnum
-function should be used instead for maximum portability.
+function should be used instead.
.Sh SEE ALSO
.Xr ctype 3 ,
.Xr isalpha 3 ,
--- /dev/null
+--- isalnum.3.orig Fri Mar 11 19:25:22 2005
++++ isalnum.3 Fri Mar 11 19:25:38 2005
+@@ -104,7 +104,8 @@
+ .Xr isdigit 3 ,
+ .Xr iswalnum 3 ,
+ .Xr multibyte 3 ,
+-.Xr ascii 7
++.Xr ascii 7 ,
++.Xr isalnum_l
+ .Sh STANDARDS
+ The
+ .Fn isalnum
.\" SUCH DAMAGE.
.\"
.\" @(#)isalpha.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/locale/isalpha.3,v 1.16 2002/10/06 10:15:38 tjr Exp $
+.\" $FreeBSD: src/lib/libc/locale/isalpha.3,v 1.18 2004/08/21 07:37:08 tjr Exp $
.\"
-.Dd October 6, 2002
+.Dd August 21, 2004
.Dt ISALPHA 3
.Os
.Sh NAME
function returns zero if the character tests false and
returns non-zero if the character tests true.
.Sh COMPATIBILITY
-Although
-.Fn isalpha
-accepts arguments outside of the range of the
-.Vt "unsigned char"
-type in locales with large character sets,
-this is a
+The
.Bx 4.4
-extension and the
+extension of accepting arguments outside of the range of the
+.Vt "unsigned char"
+type in locales with large character sets is considered obsolete
+and may not be supported in future releases.
+The
.Fn iswalpha
-function should be used instead for maximum portability.
+function should be used instead.
.Sh SEE ALSO
.Xr ctype 3 ,
.Xr islower 3 ,
--- /dev/null
+--- isalpha.3.orig Fri Mar 11 19:25:22 2005
++++ isalpha.3 Fri Mar 11 19:27:14 2005
+@@ -102,7 +102,8 @@
+ .Xr isupper 3 ,
+ .Xr iswalpha 3 ,
+ .Xr multibyte 3 ,
+-.Xr ascii 7
++.Xr ascii 7 ,
++.Xr isalnum_l
+ .Sh STANDARDS
+ The
+ .Fn isalpha
.\" SUCH DAMAGE.
.\"
.\" @(#)isblank.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/locale/isblank.3,v 1.17 2002/12/18 12:45:08 ru Exp $
+.\" $FreeBSD: src/lib/libc/locale/isblank.3,v 1.19 2004/08/21 07:37:08 tjr Exp $
.\"
-.Dd October 6, 2002
+.Dd August 21, 2004
.Dt ISBLANK 3
.Os
.Sh NAME
or the value of
.Dv EOF .
.Sh COMPATIBILITY
-Although
-.Fn isblank
-accepts arguments outside of the range of the
-.Vt "unsigned char"
-type in locales with large character sets,
-this is a
+The
.Bx 4.4
-extension and the
+extension of accepting arguments outside of the range of the
+.Vt "unsigned char"
+type in locales with large character sets is considered obsolete
+and may not be supported in future releases.
+The
.Fn iswblank
-function should be used instead for maximum portability.
+function should be used instead.
.Sh RETURN VALUES
The
.Fn isblank
--- /dev/null
+--- isblank.3.orig Fri Mar 11 19:25:22 2005
++++ isblank.3 Fri Mar 11 19:27:12 2005
+@@ -85,7 +85,8 @@
+ .Xr ctype 3 ,
+ .Xr iswblank 3 ,
+ .Xr multibyte 3 ,
+-.Xr ascii 7
++.Xr ascii 7 ,
++.Xr isalnum_l
+ .Sh STANDARDS
+ The
+ .Fn isblank
.\" SUCH DAMAGE.
.\"
.\" @(#)iscntrl.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/locale/iscntrl.3,v 1.15 2002/12/05 08:50:00 ru Exp $
+.\" $FreeBSD: src/lib/libc/locale/iscntrl.3,v 1.17 2004/08/21 07:37:08 tjr Exp $
.\"
-.Dd October 6, 2002
+.Dd August 21, 2004
.Dt ISCNTRL 3
.Os
.Sh NAME
function returns zero if the character tests false and
returns non-zero if the character tests true.
.Sh COMPATIBILITY
-Although
-.Fn iscntrl
-accepts arguments outside of the range of the
-.Vt "unsigned char"
-type in locales with large character sets,
-this is a
+The
.Bx 4.4
-extension and the
-.Fn iwcntrl
-function should be used instead for maximum portability.
+extension of accepting arguments outside of the range of the
+.Vt "unsigned char"
+type in locales with large character sets is considered obsolete
+and may not be supported in future releases.
+The
+.Fn iswcntrl
+function should be used instead.
.Sh SEE ALSO
.Xr ctype 3 ,
.Xr iswcntrl 3 ,
--- /dev/null
+--- iscntrl.3.orig Fri Mar 11 19:25:22 2005
++++ iscntrl.3 Fri Mar 11 19:27:09 2005
+@@ -92,7 +92,8 @@
+ .Xr ctype 3 ,
+ .Xr iswcntrl 3 ,
+ .Xr multibyte 3 ,
+-.Xr ascii 7
++.Xr ascii 7 ,
++.Xr isalnum_l
+ .Sh STANDARDS
+ The
+ .Fn iscntrl
.\" SUCH DAMAGE.
.\"
.\" @(#)isdigit.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/locale/isdigit.3,v 1.16 2002/10/06 10:15:38 tjr Exp $
+.\" $FreeBSD: src/lib/libc/locale/isdigit.3,v 1.19 2004/08/21 07:37:08 tjr Exp $
.\"
-.Dd October 6, 2002
+.Dd August 21, 2004
.Dt ISDIGIT 3
.Os
.Sh NAME
.Sh DESCRIPTION
The
.Fn isdigit
-function tests for any decimal-digit character.
-For any locale,
-this includes the following characters only:
+function tests for a decimal digit character.
+Regardless of locale, this includes the following characters only:
.Pp
.Bl -column \&``0''______ \&``0''______ \&``0''______ \&``0''______ \&``0''______
.It "\&``0''\t``1''\t``2''\t``3''\t``4''"
.It "\&``5''\t``6''\t``7''\t``8''\t``9''"
.El
.Pp
+The
+.Fn isnumber
+function behaves similarly to
+.Fn isdigit ,
+but may recognize additional characters, depending on the current locale
+setting.
+.Pp
For single C
.Va char Ns s
locales (see
.Sh RETURN VALUES
The
.Fn isdigit
-function returns zero if the character tests false and
+and
+.Fn isnumber
+functions return zero if the character tests false and
returns non-zero if the character tests true.
.Sh COMPATIBILITY
-Although
-.Fn isdigit
-accepts arguments outside of the range of the
-.Vt "unsigned char"
-type in locales with large character sets,
-this is a
+The
.Bx 4.4
-extension and the
+extension of accepting arguments outside of the range of the
+.Vt "unsigned char"
+type in locales with large character sets is considered obsolete
+and may not be supported in future releases.
+The
.Fn iswdigit
-function should be used instead for maximum portability.
+function should be used instead.
.Sh SEE ALSO
.Xr ctype 3 ,
.Xr iswdigit 3 ,
.Fn isdigit
function conforms to
.St -isoC .
+.Sh HISTORY
+The
+.Fn isnumber
+function appeared in
+.Bx 4.4 .
--- /dev/null
+--- isdigit.3.orig Fri Mar 11 19:25:22 2005
++++ isdigit.3 Fri Mar 11 19:27:06 2005
+@@ -98,7 +98,8 @@
+ .Xr ctype 3 ,
+ .Xr iswdigit 3 ,
+ .Xr multibyte 3 ,
+-.Xr ascii 7
++.Xr ascii 7 ,
++.Xr isalnum_l
+ .Sh STANDARDS
+ The
+ .Fn isdigit
.\" SUCH DAMAGE.
.\"
.\" @(#)isgraph.3 8.2 (Berkeley) 12/11/93
-.\" $FreeBSD: src/lib/libc/locale/isgraph.3,v 1.17 2002/10/06 10:15:38 tjr Exp $
+.\" $FreeBSD: src/lib/libc/locale/isgraph.3,v 1.19 2004/08/21 07:37:08 tjr Exp $
.\"
-.Dd October 6, 2002
+.Dd August 21, 2004
.Dt ISGRAPH 3
.Os
.Sh NAME
function returns zero if the character tests false and
returns non-zero if the character tests true.
.Sh COMPATIBILITY
-Although
-.Fn isgraph
-accepts arguments outside of the range of the
-.Vt "unsigned char"
-type in locales with large character sets,
-this is a
+The
.Bx 4.4
-extension and the
+extension of accepting arguments outside of the range of the
+.Vt "unsigned char"
+type in locales with large character sets is considered obsolete
+and may not be supported in future releases.
+The
.Fn iswgraph
-function should be used instead for maximum portability.
+function should be used instead.
.Sh SEE ALSO
.Xr ctype 3 ,
.Xr iswgraph 3 ,
--- /dev/null
+--- isgraph.3.orig Fri Mar 11 19:25:22 2005
++++ isgraph.3 Fri Mar 11 19:27:03 2005
+@@ -107,7 +107,8 @@
+ .Xr ctype 3 ,
+ .Xr iswgraph 3 ,
+ .Xr multibyte 3 ,
+-.Xr ascii 7
++.Xr ascii 7 ,
++.Xr isalnum_l
+ .Sh STANDARDS
+ The
+ .Fn isgraph
--- /dev/null
+.\"
+.\" Copyright (c) 2004 Tim J. Robbins
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/locale/isideogram.3,v 1.2 2004/07/04 20:55:48 ru Exp $
+.\"
+.Dd March 30, 2004
+.Dt ISIDEOGRAM 3
+.Os
+.Sh NAME
+.Nm isideogram
+.Nd ideographic character test
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In ctype.h
+.Ft int
+.Fn isideogram "int c"
+.Sh DESCRIPTION
+The
+.Fn isideogram
+function tests for an ideographic character.
+.Sh RETURN VALUES
+The
+.Fn isideogram
+function returns zero if the character tests false and
+returns non-zero if the character tests true.
+.Sh SEE ALSO
+.Xr ctype 3 ,
+.Xr isphonogram 3 ,
+.Xr iswideogram 3
+.Sh HISTORY
+The
+.Fn isideogram
+function appeared in
+.Bx 4.4 .
--- /dev/null
+--- isideogram.3.orig Fri Mar 11 19:25:22 2005
++++ isideogram.3 Fri Mar 11 19:26:54 2005
+@@ -49,7 +49,8 @@
+ .Sh SEE ALSO
+ .Xr ctype 3 ,
+ .Xr isphonogram 3 ,
+-.Xr iswideogram 3
++.Xr iswideogram 3 ,
++.Xr isalnum_l
+ .Sh HISTORY
+ The
+ .Fn isideogram
.\" SUCH DAMAGE.
.\"
.\" @(#)islower.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/locale/islower.3,v 1.15 2002/10/06 10:15:38 tjr Exp $
+.\" $FreeBSD: src/lib/libc/locale/islower.3,v 1.17 2004/08/21 07:37:08 tjr Exp $
.\"
-.Dd October 6, 2002
+.Dd August 21, 2004
.Dt ISLOWER 3
.Os
.Sh NAME
function returns zero if the character tests false and
returns non-zero if the character tests true.
.Sh COMPATIBILITY
-Although
-.Fn islower
-accepts arguments outside of the range of the
-.Vt "unsigned char"
-type in locales with large character sets,
-this is a
+The
.Bx 4.4
-extension and the
+extension of accepting arguments outside of the range of the
+.Vt "unsigned char"
+type in locales with large character sets is considered obsolete
+and may not be supported in future releases.
+The
.Fn iswlower
-function should be used instead for maximum portability.
+function should be used instead.
.Sh SEE ALSO
.Xr ctype 3 ,
.Xr iswlower 3 ,
--- /dev/null
+--- islower.3.orig Fri Mar 11 19:25:22 2005
++++ islower.3 Fri Mar 11 19:26:51 2005
+@@ -92,7 +92,8 @@
+ .Xr iswlower 3 ,
+ .Xr multibyte 3 ,
+ .Xr tolower 3 ,
+-.Xr ascii 7
++.Xr ascii 7 ,
++.Xr isalnum_l
+ .Sh STANDARDS
+ The
+ .Fn islower
--- /dev/null
+.\"
+.\" Copyright (c) 2004 Tim J. Robbins
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/locale/isphonogram.3,v 1.1 2004/03/30 07:23:54 tjr Exp $
+.\"
+.Dd March 30, 2004
+.Dt ISPHONOGRAM 3
+.Os
+.Sh NAME
+.Nm isphonogram
+.Nd phonographic character test
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In ctype.h
+.Ft int
+.Fn isphonogram "int c"
+.Sh DESCRIPTION
+The
+.Fn isphonogram
+function tests for a phonographic character.
+.Sh RETURN VALUES
+The
+.Fn isphonogram
+function returns zero if the character tests false and
+returns non-zero if the character tests true.
+.Sh SEE ALSO
+.Xr ctype 3 ,
+.Xr isideogram 3 ,
+.Xr iswphonogram 3
+.Sh HISTORY
+The
+.Fn isphonogram
+function appeared in
+.Bx 4.4 .
--- /dev/null
+--- isphonogram.3.orig Fri Mar 11 19:25:22 2005
++++ isphonogram.3 Fri Mar 11 19:26:47 2005
+@@ -49,7 +49,8 @@
+ .Sh SEE ALSO
+ .Xr ctype 3 ,
+ .Xr isideogram 3 ,
+-.Xr iswphonogram 3
++.Xr iswphonogram 3 ,
++.Xr isalnum_l
+ .Sh HISTORY
+ The
+ .Fn isphonogram
.\" SUCH DAMAGE.
.\"
.\" @(#)isprint.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/locale/isprint.3,v 1.18 2002/10/06 10:15:38 tjr Exp $
+.\" $FreeBSD: src/lib/libc/locale/isprint.3,v 1.20 2004/08/21 07:37:08 tjr Exp $
.\"
-.Dd October 6, 2002
+.Dd August 21, 2004
.Dt ISPRINT 3
.Os
.Sh NAME
function returns zero if the character tests false and
returns non-zero if the character tests true.
.Sh COMPATIBILITY
-Although
-.Fn isprint
-accepts arguments outside of the range of the
-.Vt "unsigned char"
-type in locales with large character sets,
-this is a
+The
.Bx 4.4
-extension and the
+extension of accepting arguments outside of the range of the
+.Vt "unsigned char"
+type in locales with large character sets is considered obsolete
+and may not be supported in future releases.
+The
.Fn iswprint
-function should be used instead for maximum portability.
+function should be used instead.
.Sh SEE ALSO
.Xr ctype 3 ,
.Xr iswprint 3 ,
--- /dev/null
+--- isprint.3.orig Fri Mar 11 19:25:22 2005
++++ isprint.3 Fri Mar 11 19:26:43 2005
+@@ -105,7 +105,8 @@
+ .Xr ctype 3 ,
+ .Xr iswprint 3 ,
+ .Xr multibyte 3 ,
+-.Xr ascii 7
++.Xr ascii 7 ,
++.Xr isalnum_l
+ .Sh STANDARDS
+ The
+ .Fn isprint
.\" SUCH DAMAGE.
.\"
.\" @(#)ispunct.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/locale/ispunct.3,v 1.16 2002/10/06 10:15:38 tjr Exp $
+.\" $FreeBSD: src/lib/libc/locale/ispunct.3,v 1.18 2004/08/21 07:37:08 tjr Exp $
.\"
-.Dd October 6, 2002
+.Dd August 21, 2004
.Dt ISPUNCT 3
.Os
.Sh NAME
function returns zero if the character tests false and
returns non-zero if the character tests true.
.Sh COMPATIBILITY
-Although
-.Fn ispunct
-accepts arguments outside of the range of the
-.Vt "unsigned char"
-type in locales with large character sets,
-this is a
+The
.Bx 4.4
-extension and the
+extension of accepting arguments outside of the range of the
+.Vt "unsigned char"
+type in locales with large character sets is considered obsolete
+and may not be supported in future releases.
+The
.Fn iswpunct
-function should be used instead for maximum portability.
+function should be used instead.
.Sh SEE ALSO
.Xr ctype 3 ,
.Xr iswpunct 3 ,
--- /dev/null
+--- ispunct.3.orig Fri Mar 11 19:25:22 2005
++++ ispunct.3 Fri Mar 11 19:26:38 2005
+@@ -97,7 +97,8 @@
+ .Xr ctype 3 ,
+ .Xr iswpunct 3 ,
+ .Xr multibyte 3 ,
+-.Xr ascii 7
++.Xr ascii 7 ,
++.Xr isalnum_l
+ .Sh STANDARDS
+ The
+ .Fn ispunct
--- /dev/null
+.\"
+.\" Copyright (c) 2004 Tim J. Robbins
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/locale/isrune.3,v 1.1 2004/03/30 07:23:54 tjr Exp $
+.\"
+.Dd March 30, 2004
+.Dt ISRUNE 3
+.Os
+.Sh NAME
+.Nm isrune
+.Nd valid character test
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In ctype.h
+.Ft int
+.Fn isrune "int c"
+.Sh DESCRIPTION
+The
+.Fn isrune
+function tests for any character that is valid in the current
+character set.
+In the
+.Tn ASCII
+character set, this is equivalent to
+.Fn isascii .
+.Sh RETURN VALUES
+The
+.Fn isrune
+function returns zero if the character tests false and
+returns non-zero if the character tests true.
+.Sh SEE ALSO
+.Xr ctype 3 ,
+.Xr isascii 3 ,
+.Xr iswrune 3 ,
+.Xr ascii 7
+.Sh HISTORY
+The
+.Fn isrune
+function appeared in
+.Bx 4.4 .
--- /dev/null
+--- isrune.3.orig Fri Mar 11 19:25:22 2005
++++ isrune.3 Fri Mar 11 19:26:33 2005
+@@ -55,7 +55,8 @@
+ .Xr ctype 3 ,
+ .Xr isascii 3 ,
+ .Xr iswrune 3 ,
+-.Xr ascii 7
++.Xr ascii 7 ,
++.Xr isalnum_l
+ .Sh HISTORY
+ The
+ .Fn isrune
.\" SUCH DAMAGE.
.\"
.\" @(#)isspace.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/locale/isspace.3,v 1.15 2002/10/06 10:15:38 tjr Exp $
+.\" $FreeBSD: src/lib/libc/locale/isspace.3,v 1.17 2004/08/21 07:37:08 tjr Exp $
.\"
-.Dd October 6, 2002
+.Dd August 21, 2004
.Dt ISSPACE 3
.Os
.Sh NAME
function returns zero if the character tests false and
returns non-zero if the character tests true.
.Sh COMPATIBILITY
-Although
-.Fn isspace
-accepts arguments outside of the range of the
-.Vt "unsigned char"
-type in locales with large character sets,
-this is a
+The
.Bx 4.4
-extension and the
+extension of accepting arguments outside of the range of the
+.Vt "unsigned char"
+type in locales with large character sets is considered obsolete
+and may not be supported in future releases.
+The
.Fn iswspace
-function should be used instead for maximum portability.
+function should be used instead.
.Sh SEE ALSO
.Xr ctype 3 ,
.Xr iswspace 3 ,
--- /dev/null
+--- isspace.3.orig Fri Mar 11 19:25:22 2005
++++ isspace.3 Fri Mar 11 19:26:20 2005
+@@ -89,7 +89,8 @@
+ .Xr ctype 3 ,
+ .Xr iswspace 3 ,
+ .Xr multibyte 3 ,
+-.Xr ascii 7
++.Xr ascii 7 ,
++.Xr isalnum_l
+ .Sh STANDARDS
+ The
+ .Fn isspace
--- /dev/null
+.\"
+.\" Copyright (c) 2004 Tim J. Robbins
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/locale/isspecial.3,v 1.1 2004/03/30 07:23:54 tjr Exp $
+.\"
+.Dd March 30, 2004
+.Dt ISSPECIAL 3
+.Os
+.Sh NAME
+.Nm isspecial
+.Nd special character test
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In ctype.h
+.Ft int
+.Fn isspecial "int c"
+.Sh DESCRIPTION
+The
+.Fn isspecial
+function tests for a special character.
+.Sh RETURN VALUES
+The
+.Fn isspecial
+function returns zero if the character tests false and
+returns non-zero if the character tests true.
+.Sh SEE ALSO
+.Xr ctype 3 ,
+.Xr iswspecial 3
+.Sh HISTORY
+The
+.Fn isspecial
+function appeared in
+.Bx 4.4 .
--- /dev/null
+--- isspecial.3.orig Fri Mar 11 19:25:22 2005
++++ isspecial.3 Fri Mar 11 19:26:16 2005
+@@ -48,7 +48,8 @@
+ returns non-zero if the character tests true.
+ .Sh SEE ALSO
+ .Xr ctype 3 ,
+-.Xr iswspecial 3
++.Xr iswspecial 3 ,
++.Xr isalnum_l
+ .Sh HISTORY
+ The
+ .Fn isspecial
.\" SUCH DAMAGE.
.\"
.\" @(#)isupper.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/locale/isupper.3,v 1.16 2002/10/06 10:15:38 tjr Exp $
+.\" $FreeBSD: src/lib/libc/locale/isupper.3,v 1.18 2004/08/21 07:37:08 tjr Exp $
.\"
-.Dd October 6, 2002
+.Dd August 21, 2004
.Dt ISUPPER 3
.Os
.Sh NAME
function returns zero if the character tests false and
returns non-zero if the character tests true.
.Sh COMPATIBILITY
-Although
-.Fn isupper
-accepts arguments outside of the range of the
-.Vt "unsigned char"
-type in locales with large character sets,
-this is a
+The
.Bx 4.4
-extension and the
+extension of accepting arguments outside of the range of the
+.Vt "unsigned char"
+type in locales with large character sets is considered obsolete
+and may not be supported in future releases.
+The
.Fn iswupper
-function should be used instead for maximum portability.
+function should be used instead.
.Sh SEE ALSO
.Xr ctype 3 ,
.Xr iswupper 3 ,
--- /dev/null
+--- isupper.3.orig Fri Mar 11 19:25:22 2005
++++ isupper.3 Fri Mar 11 19:26:13 2005
+@@ -92,7 +92,8 @@
+ .Xr iswupper 3 ,
+ .Xr multibyte 3 ,
+ .Xr toupper 3 ,
+-.Xr ascii 7
++.Xr ascii 7 ,
++.Xr isalnum_l
+ .Sh STANDARDS
+ The
+ .Fn isupper
--- /dev/null
+--- iswalnum.3.orig Fri Mar 11 19:18:47 2005
++++ iswalnum.3 Fri Mar 11 19:20:06 2005
+@@ -114,6 +114,12 @@
+ functions (like
+ .Xr isalnum 3 ) ,
+ for details.
++.Pp
++Extended locale versions of these functions are documented in
++.Xr iswalnum_l 3 .
++See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The functions return zero if the character tests false and
+ return non-zero if the character tests true.
+@@ -137,7 +143,8 @@
+ .Xr isspecial 3 ,
+ .Xr isupper 3 ,
+ .Xr isxdigit 3 ,
+-.Xr wctype 3
++.Xr wctype 3 ,
++.Xr iswalnum_l 3
+ .Sh STANDARDS
+ These functions conform to
+ .St -p1003.1-2001 ,
.\" SUCH DAMAGE.
.\"
.\" @(#)isxdigit.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/locale/isxdigit.3,v 1.16 2002/10/06 10:15:38 tjr Exp $
+.\" $FreeBSD: src/lib/libc/locale/isxdigit.3,v 1.20 2004/08/21 07:37:08 tjr Exp $
.\"
-.Dd October 6, 2002
+.Dd August 21, 2004
.Dt ISXDIGIT 3
.Os
.Sh NAME
The
.Fn isxdigit
function tests for any hexadecimal-digit character.
-For any locale, this includes the following characters only:
+Regardless of locale, this includes the following characters only:
.Pp
.Bl -column \&``0''______ \&``0''______ \&``0''______ \&``0''______ \&``0''______
.It "\&``0''\t``1''\t``2''\t``3''\t``4''"
.It "\&``e''\t``f''"
.El
.Pp
+The
+.Fn ishexnumber
+function behaves similarly to
+.Fn isxdigit ,
+but may recognize additional characters,
+depending on the current locale setting.
+.Pp
For single C
.Va char Ns s
locales (see
function returns zero if the character tests false and
returns non-zero if the character tests true.
.Sh COMPATIBILITY
-Although
-.Fn isxdigit
-and
-.Fn ishexnumber
-accept arguments outside of the range of the
-.Vt "unsigned char"
-type in locales with large character sets,
-this is a
+The
.Bx 4.4
-extension and the
-.Fn isxwdigit
-and
-.Fn iswhexnumber
-functions should be used instead for maximum portability.
+extension of accepting arguments outside of the range of the
+.Vt "unsigned char"
+type in locales with large character sets is considered obsolete
+and may not be supported in future releases.
+The
+.Fn iswxdigit
+function should be used instead.
.Sh SEE ALSO
.Xr ctype 3 ,
.Xr iswxdigit 3 ,
.Fn isxdigit
function conforms to
.St -isoC .
+.Sh HISTORY
+The
+.Fn ishexnumber
+function appeared in
+.Bx 4.4 .
--- /dev/null
+--- isxdigit.3.orig Fri Mar 11 19:25:22 2005
++++ isxdigit.3 Fri Mar 11 19:26:08 2005
+@@ -99,7 +99,8 @@
+ .Xr ctype 3 ,
+ .Xr iswxdigit 3 ,
+ .Xr multibyte 3 ,
+-.Xr ascii 7
++.Xr ascii 7 ,
++.Xr isalnum_l
+ .Sh STANDARDS
+ The
+ .Fn isxdigit
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/ldpart.c,v 1.12 2002/10/27 17:44:33 wollman Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/ldpart.c,v 1.15 2004/04/25 19:56:50 ache Exp $");
#include "namespace.h"
#include <sys/types.h>
#include <unistd.h>
#include "un-namespace.h"
-#include "setlocale.h"
#include "ldpart.h"
+#include "setlocale.h"
static int split_lines(char *, const char *);
int
__part_load_locale(const char *name,
int *using_locale,
- char *locale_buf,
+ char **locale_buf,
const char *category_filename,
int locale_buf_size_max,
int locale_buf_size_min,
/*
* If the locale name is the same as our cache, use the cache.
*/
- if (locale_buf != NULL && strcmp(name, locale_buf) == 0) {
+ if (*locale_buf != NULL && strcmp(name, *locale_buf) == 0) {
*using_locale = 1;
return (_LDP_CACHE);
}
namesize = strlen(name) + 1;
/* 'PathLocale' must be already set & checked. */
+
/* Range checking not needed, 'name' size is limited */
strcpy(filename, _PathLocale);
strcat(filename, "/");
/*
* Record the successful parse in the cache.
*/
- if (locale_buf != NULL)
- free(locale_buf);
- locale_buf = lbuf;
- for (p = locale_buf, i = 0; i < num_lines; i++)
+ if (*locale_buf != NULL)
+ free(*locale_buf);
+ *locale_buf = lbuf;
+ for (p = *locale_buf, i = 0; i < num_lines; i++)
dst_localebuf[i] = (p += strlen(p) + 1);
for (i = num_lines; i < locale_buf_size_max; i++)
dst_localebuf[i] = NULL;
{
int i;
- for (i = 0; p < plim; i++) {
- p = strchr(p, '\n');
- *p++ = '\0';
+ i = 0;
+ while (p < plim) {
+ if (*p == '\n') {
+ *p = '\0';
+ i++;
+ }
+ p++;
}
return (i);
}
---- ldpart.c.orig Tue May 20 15:21:44 2003
-+++ ldpart.c Wed Jun 11 13:11:52 2003
-@@ -47,7 +47,7 @@
- int
+--- ldpart.c.orig 2004-11-25 11:38:17.000000000 -0800
++++ ldpart.c 2005-02-13 01:59:35.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/ldpart.c,v 1.15 2004/04/25 19:56:50 ache Exp $");
+
++#include "xlocale_private.h"
++
+ #include "namespace.h"
+ #include <sys/types.h>
+ #include <sys/stat.h>
+@@ -44,9 +46,9 @@
+
+ static int split_lines(char *, const char *);
+
+-int
++__private_extern__ int
__part_load_locale(const char *name,
- int *using_locale,
-- char *locale_buf,
-+ char **locale_buf,
+- int *using_locale,
++ unsigned char *using_locale,
+ char **locale_buf,
const char *category_filename,
int locale_buf_size_max,
- int locale_buf_size_min,
-@@ -69,7 +69,7 @@
+@@ -60,20 +62,6 @@
+ struct stat st;
+ size_t namesize, bufsize;
+
+- /* 'name' must be already checked. */
+- if (strcmp(name, "C") == 0 || strcmp(name, "POSIX") == 0) {
+- *using_locale = 0;
+- return (_LDP_CACHE);
+- }
+-
+- /*
+- * If the locale name is the same as our cache, use the cache.
+- */
+- if (*locale_buf != NULL && strcmp(name, *locale_buf) == 0) {
+- *using_locale = 1;
+- return (_LDP_CACHE);
+- }
+-
/*
- * If the locale name is the same as our cache, use the cache.
+ * Slurp the locale file into the cache.
*/
-- if (locale_buf != NULL && strcmp(name, locale_buf) == 0) {
-+ if (*locale_buf != NULL && strcmp(name, *locale_buf) == 0) {
- *using_locale = 1;
- return (_LDP_CACHE);
- }
-@@ -124,10 +124,10 @@
- /*
- * Record the successful parse in the cache.
- */
-- if (locale_buf != NULL)
-- free(locale_buf);
-- locale_buf = lbuf;
-- for (p = locale_buf, i = 0; i < num_lines; i++)
-+ if (*locale_buf != NULL)
-+ free(*locale_buf);
-+ *locale_buf = lbuf;
-+ for (p = *locale_buf, i = 0; i < num_lines; i++)
- dst_localebuf[i] = (p += strlen(p) + 1);
- for (i = num_lines; i < locale_buf_size_max; i++)
- dst_localebuf[i] = NULL;
+@@ -164,3 +152,9 @@
+ return (i);
+ }
+
++__private_extern__ void
++__ldpart_free_extra(struct __xlocale_st_ldpart *lp)
++{
++ if (lp)
++ free(lp->_locale_buf);
++}
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: src/lib/libc/locale/ldpart.h,v 1.5 2002/08/08 05:51:54 ache Exp $
+ * $FreeBSD: src/lib/libc/locale/ldpart.h,v 1.6 2003/06/13 00:14:07 jkh Exp $
*/
#ifndef _LDPART_H_
#define _LDP_ERROR (-1)
#define _LDP_CACHE 1
-int __part_load_locale(const char *, int*, char *, const char *,
+int __part_load_locale(const char *, int*, char **, const char *,
int, int, const char **);
#endif /* !_LDPART_H_ */
---- ldpart.h.orig Tue May 20 15:21:44 2003
-+++ ldpart.h Wed Jun 11 13:12:07 2003
+--- ldpart.h.orig 2004-11-25 11:38:17.000000000 -0800
++++ ldpart.h 2005-02-13 19:02:54.000000000 -0800
@@ -33,7 +33,7 @@
#define _LDP_ERROR (-1)
#define _LDP_CACHE 1
--int __part_load_locale(const char *, int*, char *, const char *,
-+int __part_load_locale(const char *, int*, char **, const char *,
+-int __part_load_locale(const char *, int*, char **, const char *,
++int __part_load_locale(const char *, unsigned char *, char **, const char *,
int, int, const char **);
#endif /* !_LDPART_H_ */
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/lmessages.c,v 1.12 2002/08/08 05:51:54 ache Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/lmessages.c,v 1.14 2003/06/26 10:46:16 phantom Exp $");
#include <stddef.h>
-#include "lmessages.h"
#include "ldpart.h"
+#include "lmessages.h"
#define LCMESSAGES_SIZE_FULL (sizeof(struct lc_messages_T) / sizeof(char *))
#define LCMESSAGES_SIZE_MIN \
int ret;
ret = __part_load_locale(name, &_messages_using_locale,
- _messages_locale_buf, "LC_MESSAGES",
+ &_messages_locale_buf, "LC_MESSAGES",
LCMESSAGES_SIZE_FULL, LCMESSAGES_SIZE_MIN,
(const char **)&_messages_locale);
if (ret == _LDP_LOADED) {
---- lmessages.c.orig Tue May 20 15:21:44 2003
-+++ lmessages.c Wed Jun 11 13:13:38 2003
-@@ -55,7 +55,7 @@
+--- lmessages.c.orig 2004-11-25 11:38:17.000000000 -0800
++++ lmessages.c 2005-02-17 10:13:34.000000000 -0800
+@@ -27,7 +27,10 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/lmessages.c,v 1.14 2003/06/26 10:46:16 phantom Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stddef.h>
++#include <string.h>
+
+ #include "ldpart.h"
+ #include "lmessages.h"
+@@ -45,47 +48,76 @@
+ "no" /* nostr */
+ };
+
+-static struct lc_messages_T _messages_locale;
+-static int _messages_using_locale;
+-static char *_messages_locale_buf;
+-
+-int
+-__messages_load_locale(const char *name)
++__private_extern__ int
++__messages_load_locale(const char *name, locale_t loc)
+ {
int ret;
++ struct __xlocale_st_messages *xp;
++ static struct __xlocale_st_messages *cache = NULL;
++
++ /* 'name' must be already checked. */
++ if (strcmp(name, "C") == 0 || strcmp(name, "POSIX") == 0) {
++ loc->_messages_using_locale = 0;
++ XL_RELEASE(loc->__lc_messages);
++ loc->__lc_messages = NULL;
++ return (_LDP_CACHE);
++ }
- ret = __part_load_locale(name, &_messages_using_locale,
-- _messages_locale_buf, "LC_MESSAGES",
-+ &_messages_locale_buf, "LC_MESSAGES/LC_MESSAGES",
+- ret = __part_load_locale(name, &_messages_using_locale,
+- &_messages_locale_buf, "LC_MESSAGES",
++ /*
++ * If the locale name is the same as our cache, use the cache.
++ */
++ if (cache && cache->_messages_locale_buf && strcmp(name, cache->_messages_locale_buf) == 0) {
++ loc->_messages_using_locale = 1;
++ XL_RELEASE(loc->__lc_messages);
++ loc->__lc_messages = cache;
++ XL_RETAIN(loc->__lc_messages);
++ return (_LDP_CACHE);
++ }
++ if ((xp = (struct __xlocale_st_messages *)malloc(sizeof(*xp))) == NULL)
++ return _LDP_ERROR;
++ xp->__refcount = 1;
++ xp->__free_extra = (__free_extra_t)__ldpart_free_extra;
++ xp->_messages_locale_buf = NULL;
++
++ ret = __part_load_locale(name, &loc->_messages_using_locale,
++ &xp->_messages_locale_buf, "LC_MESSAGES/LC_MESSAGES",
LCMESSAGES_SIZE_FULL, LCMESSAGES_SIZE_MIN,
- (const char **)&_messages_locale);
+- (const char **)&_messages_locale);
++ (const char **)&xp->_messages_locale);
if (ret == _LDP_LOADED) {
+- if (_messages_locale.yesstr == NULL)
+- _messages_locale.yesstr = empty;
+- if (_messages_locale.nostr == NULL)
+- _messages_locale.nostr = empty;
+- }
++ if (xp->_messages_locale.yesstr == NULL)
++ xp->_messages_locale.yesstr = empty;
++ if (xp->_messages_locale.nostr == NULL)
++ xp->_messages_locale.nostr = empty;
++ XL_RELEASE(loc->__lc_messages);
++ loc->__lc_messages = xp;
++ XL_RELEASE(cache);
++ cache = xp;
++ XL_RETAIN(cache);
++ } else if (ret == _LDP_ERROR)
++ free(xp);
+ return (ret);
+ }
+
+-struct lc_messages_T *
+-__get_current_messages_locale(void)
++__private_extern__ struct lc_messages_T *
++__get_current_messages_locale(locale_t loc)
+ {
+- return (_messages_using_locale
+- ? &_messages_locale
++ return (loc->_messages_using_locale
++ ? &loc->__lc_messages->_messages_locale
+ : (struct lc_messages_T *)&_C_messages_locale);
+ }
+
+ #ifdef LOCALE_DEBUG
+ void
+ msgdebug() {
++locale_t loc = __current_locale();
+ printf( "yesexpr = %s\n"
+ "noexpr = %s\n"
+ "yesstr = %s\n"
+ "nostr = %s\n",
+- _messages_locale.yesexpr,
+- _messages_locale.noexpr,
+- _messages_locale.yesstr,
+- _messages_locale.nostr
++ loc->__lc_messages->_messages_locale.yesexpr,
++ loc->__lc_messages->_messages_locale.noexpr,
++ loc->__lc_messages->_messages_locale.yesstr,
++ loc->__lc_messages->_messages_locale.nostr
+ );
+ }
+ #endif /* LOCALE_DEBUG */
--- /dev/null
+--- lmessages.h.orig 2003-05-20 15:21:44.000000000 -0700
++++ lmessages.h 2005-02-19 14:39:44.000000000 -0800
+@@ -29,6 +29,8 @@
+ #ifndef _LMESSAGES_H_
+ #define _LMESSAGES_H_
+
++#include <xlocale.h>
++
+ struct lc_messages_T {
+ const char *yesexpr;
+ const char *noexpr;
+@@ -36,7 +38,7 @@
+ const char *nostr;
+ };
+
+-struct lc_messages_T *__get_current_messages_locale(void);
+-int __messages_load_locale(const char *);
++struct lc_messages_T *__get_current_messages_locale(locale_t);
++int __messages_load_locale(const char *, locale_t);
+
+ #endif /* !_LMESSAGES_H_ */
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/lmonetary.c,v 1.17 2002/10/12 11:31:07 ache Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/lmonetary.c,v 1.19 2003/06/26 10:46:16 phantom Exp $");
#include <limits.h>
#include <stddef.h>
#include <stdlib.h>
-#include "lmonetary.h"
+
#include "ldpart.h"
+#include "lmonetary.h"
extern int __mlocale_changed;
extern const char * __fix_locale_grouping_str(const char *);
int ret;
ret = __part_load_locale(name, &_monetary_using_locale,
- _monetary_locale_buf, "LC_MONETARY",
+ &_monetary_locale_buf, "LC_MONETARY",
LCMONETARY_SIZE_FULL, LCMONETARY_SIZE_MIN,
(const char **)&_monetary_locale);
if (ret != _LDP_ERROR)
/*
* The six additional C99 international monetary formatting
* parameters default to the national parameters when
- * reading FreeBSD 4 LC_MONETARY data files.
+ * reading FreeBSD LC_MONETARY data files.
*/
#define M_ASSIGN_ICHAR(NAME) \
do { \
"n_sep_by_space = %d\n"
"p_sign_posn = %d\n"
"n_sign_posn = %d\n",
+ "int_p_cs_precedes = %d\n"
+ "int_p_sep_by_space = %d\n"
+ "int_n_cs_precedes = %d\n"
+ "int_n_sep_by_space = %d\n"
+ "int_p_sign_posn = %d\n"
+ "int_n_sign_posn = %d\n",
_monetary_locale.int_curr_symbol,
_monetary_locale.currency_symbol,
_monetary_locale.mon_decimal_point,
_monetary_locale.n_cs_precedes[0],
_monetary_locale.n_sep_by_space[0],
_monetary_locale.p_sign_posn[0],
- _monetary_locale.n_sign_posn[0]
+ _monetary_locale.n_sign_posn[0],
+ _monetary_locale.int_p_cs_precedes[0],
+ _monetary_locale.int_p_sep_by_space[0],
+ _monetary_locale.int_n_cs_precedes[0],
+ _monetary_locale.int_n_sep_by_space[0],
+ _monetary_locale.int_p_sign_posn[0],
+ _monetary_locale.int_n_sign_posn[0]
);
}
#endif /* LOCALE_DEBUG */
---- lmonetary.c.orig Tue May 20 15:21:44 2003
-+++ lmonetary.c Wed Jun 11 13:12:44 2003
-@@ -88,7 +88,7 @@
+--- lmonetary.c.orig 2004-11-25 11:38:17.000000000 -0800
++++ lmonetary.c 2005-03-16 23:01:33.000000000 -0800
+@@ -27,14 +27,16 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/lmonetary.c,v 1.19 2003/06/26 10:46:16 phantom Exp $");
+
++#include "xlocale_private.h"
++
+ #include <limits.h>
+ #include <stddef.h>
+ #include <stdlib.h>
++#include <string.h>
+
+ #include "ldpart.h"
+ #include "lmonetary.h"
+
+-extern int __mlocale_changed;
+ extern const char * __fix_locale_grouping_str(const char *);
+
+ #define LCMONETARY_SIZE_FULL (sizeof(struct lc_monetary_T) / sizeof(char *))
+@@ -69,10 +71,6 @@
+ numempty /* int_n_sign_posn */
+ };
+
+-static struct lc_monetary_T _monetary_locale;
+-static int _monetary_using_locale;
+-static char *_monetary_locale_buf;
+-
+ static char
+ cnv(const char *str)
+ {
+@@ -83,23 +81,57 @@
+ return ((char)i);
+ }
+
+-int
+-__monetary_load_locale(const char *name)
++__private_extern__ int
++__monetary_load_locale(const char *name, locale_t loc)
+ {
int ret;
++ struct __xlocale_st_monetary *xp;
++ static struct __xlocale_st_monetary *cache = NULL;
++
++ /* 'name' must be already checked. */
++ if (strcmp(name, "C") == 0 || strcmp(name, "POSIX") == 0) {
++ if (!loc->_monetary_using_locale)
++ return (_LDP_CACHE);
++ loc->_monetary_using_locale = 0;
++ XL_RELEASE(loc->__lc_monetary);
++ loc->__lc_monetary = NULL;
++ loc->__mlocale_changed = 1;
++ return (_LDP_CACHE);
++ }
++
++ if (loc->_monetary_using_locale && strcmp(name, loc->__lc_monetary->_monetary_locale_buf) == 0)
++ return (_LDP_CACHE);
++ /*
++ * If the locale name is the same as our cache, use the cache.
++ */
++ if (cache && cache->_monetary_locale_buf && strcmp(name, cache->_monetary_locale_buf) == 0) {
++ loc->_monetary_using_locale = 1;
++ XL_RELEASE(loc->__lc_monetary);
++ loc->__lc_monetary = cache;
++ XL_RETAIN(loc->__lc_monetary);
++ loc->__mlocale_changed = 1;
++ return (_LDP_CACHE);
++ }
++ if ((xp = (struct __xlocale_st_monetary *)malloc(sizeof(*xp))) == NULL)
++ return _LDP_ERROR;
++ xp->__refcount = 1;
++ xp->__free_extra = (__free_extra_t)__ldpart_free_extra;
++ xp->_monetary_locale_buf = NULL;
- ret = __part_load_locale(name, &_monetary_using_locale,
-- _monetary_locale_buf, "LC_MONETARY",
-+ &_monetary_locale_buf, "LC_MONETARY",
+- ret = __part_load_locale(name, &_monetary_using_locale,
+- &_monetary_locale_buf, "LC_MONETARY",
++ ret = __part_load_locale(name, &loc->_monetary_using_locale,
++ &xp->_monetary_locale_buf, "LC_MONETARY",
LCMONETARY_SIZE_FULL, LCMONETARY_SIZE_MIN,
- (const char **)&_monetary_locale);
+- (const char **)&_monetary_locale);
++ (const char **)&xp->_monetary_locale);
if (ret != _LDP_ERROR)
+- __mlocale_changed = 1;
++ loc->__mlocale_changed = 1;
++ else
++ free(xp);
+ if (ret == _LDP_LOADED) {
+- _monetary_locale.mon_grouping =
+- __fix_locale_grouping_str(_monetary_locale.mon_grouping);
++ xp->_monetary_locale.mon_grouping =
++ __fix_locale_grouping_str(xp->_monetary_locale.mon_grouping);
+
+-#define M_ASSIGN_CHAR(NAME) (((char *)_monetary_locale.NAME)[0] = \
+- cnv(_monetary_locale.NAME))
++#define M_ASSIGN_CHAR(NAME) (((char *)xp->_monetary_locale.NAME)[0] = \
++ cnv(xp->_monetary_locale.NAME))
+
+ M_ASSIGN_CHAR(int_frac_digits);
+ M_ASSIGN_CHAR(frac_digits);
+@@ -117,9 +149,9 @@
+ */
+ #define M_ASSIGN_ICHAR(NAME) \
+ do { \
+- if (_monetary_locale.int_##NAME == NULL) \
+- _monetary_locale.int_##NAME = \
+- _monetary_locale.NAME; \
++ if (xp->_monetary_locale.int_##NAME == NULL) \
++ xp->_monetary_locale.int_##NAME = \
++ xp->_monetary_locale.NAME; \
+ else \
+ M_ASSIGN_CHAR(int_##NAME); \
+ } while (0)
+@@ -130,21 +162,27 @@
+ M_ASSIGN_ICHAR(n_sep_by_space);
+ M_ASSIGN_ICHAR(p_sign_posn);
+ M_ASSIGN_ICHAR(n_sign_posn);
++ XL_RELEASE(loc->__lc_monetary);
++ loc->__lc_monetary = xp;
++ XL_RELEASE(cache);
++ cache = xp;
++ XL_RETAIN(cache);
+ }
+ return (ret);
+ }
+
+-struct lc_monetary_T *
+-__get_current_monetary_locale(void)
++__private_extern__ struct lc_monetary_T *
++__get_current_monetary_locale(locale_t loc)
+ {
+- return (_monetary_using_locale
+- ? &_monetary_locale
++ return (loc->_monetary_using_locale
++ ? &loc->__lc_monetary->_monetary_locale
+ : (struct lc_monetary_T *)&_C_monetary_locale);
+ }
+
+ #ifdef LOCALE_DEBUG
+ void
+ monetdebug() {
++locale_t loc = __current_locale();
+ printf( "int_curr_symbol = %s\n"
+ "currency_symbol = %s\n"
+ "mon_decimal_point = %s\n"
+@@ -166,27 +204,27 @@
+ "int_n_sep_by_space = %d\n"
+ "int_p_sign_posn = %d\n"
+ "int_n_sign_posn = %d\n",
+- _monetary_locale.int_curr_symbol,
+- _monetary_locale.currency_symbol,
+- _monetary_locale.mon_decimal_point,
+- _monetary_locale.mon_thousands_sep,
+- _monetary_locale.mon_grouping,
+- _monetary_locale.positive_sign,
+- _monetary_locale.negative_sign,
+- _monetary_locale.int_frac_digits[0],
+- _monetary_locale.frac_digits[0],
+- _monetary_locale.p_cs_precedes[0],
+- _monetary_locale.p_sep_by_space[0],
+- _monetary_locale.n_cs_precedes[0],
+- _monetary_locale.n_sep_by_space[0],
+- _monetary_locale.p_sign_posn[0],
+- _monetary_locale.n_sign_posn[0],
+- _monetary_locale.int_p_cs_precedes[0],
+- _monetary_locale.int_p_sep_by_space[0],
+- _monetary_locale.int_n_cs_precedes[0],
+- _monetary_locale.int_n_sep_by_space[0],
+- _monetary_locale.int_p_sign_posn[0],
+- _monetary_locale.int_n_sign_posn[0]
++ loc->__lc_monetary->_monetary_locale.int_curr_symbol,
++ loc->__lc_monetary->_monetary_locale.currency_symbol,
++ loc->__lc_monetary->_monetary_locale.mon_decimal_point,
++ loc->__lc_monetary->_monetary_locale.mon_thousands_sep,
++ loc->__lc_monetary->_monetary_locale.mon_grouping,
++ loc->__lc_monetary->_monetary_locale.positive_sign,
++ loc->__lc_monetary->_monetary_locale.negative_sign,
++ loc->__lc_monetary->_monetary_locale.int_frac_digits[0],
++ loc->__lc_monetary->_monetary_locale.frac_digits[0],
++ loc->__lc_monetary->_monetary_locale.p_cs_precedes[0],
++ loc->__lc_monetary->_monetary_locale.p_sep_by_space[0],
++ loc->__lc_monetary->_monetary_locale.n_cs_precedes[0],
++ loc->__lc_monetary->_monetary_locale.n_sep_by_space[0],
++ loc->__lc_monetary->_monetary_locale.p_sign_posn[0],
++ loc->__lc_monetary->_monetary_locale.n_sign_posn[0],
++ loc->__lc_monetary->_monetary_locale.int_p_cs_precedes[0],
++ loc->__lc_monetary->_monetary_locale.int_p_sep_by_space[0],
++ loc->__lc_monetary->_monetary_locale.int_n_cs_precedes[0],
++ loc->__lc_monetary->_monetary_locale.int_n_sep_by_space[0],
++ loc->__lc_monetary->_monetary_locale.int_p_sign_posn[0],
++ loc->__lc_monetary->_monetary_locale.int_n_sign_posn[0]
+ );
+ }
+ #endif /* LOCALE_DEBUG */
--- /dev/null
+--- lmonetary.h.orig 2003-05-20 15:21:44.000000000 -0700
++++ lmonetary.h 2005-02-19 14:41:58.000000000 -0800
+@@ -29,6 +29,8 @@
+ #ifndef _LMONETARY_H_
+ #define _LMONETARY_H_
+
++#include <xlocale.h>
++
+ struct lc_monetary_T {
+ const char *int_curr_symbol;
+ const char *currency_symbol;
+@@ -53,7 +55,7 @@
+ const char *int_n_sign_posn;
+ };
+
+-struct lc_monetary_T *__get_current_monetary_locale(void);
+-int __monetary_load_locale(const char *);
++struct lc_monetary_T *__get_current_monetary_locale(locale_t);
++int __monetary_load_locale(const char *, locale_t);
+
+ #endif /* !_LMONETARY_H_ */
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/lnumeric.c,v 1.14 2003/03/20 08:05:20 ache Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/lnumeric.c,v 1.16 2003/06/26 10:46:16 phantom Exp $");
#include <limits.h>
-#include "lnumeric.h"
+
#include "ldpart.h"
+#include "lnumeric.h"
extern int __nlocale_changed;
extern const char *__fix_locale_grouping_str(const char *);
int ret;
ret = __part_load_locale(name, &_numeric_using_locale,
- _numeric_locale_buf, "LC_NUMERIC",
+ &_numeric_locale_buf, "LC_NUMERIC",
LCNUMERIC_SIZE, LCNUMERIC_SIZE,
(const char **)&_numeric_locale);
if (ret != _LDP_ERROR)
---- lnumeric.c.orig Tue May 20 15:21:44 2003
-+++ lnumeric.c Wed Jun 11 13:13:11 2003
-@@ -54,7 +54,7 @@
+--- lnumeric.c.orig 2004-11-25 11:38:17.000000000 -0800
++++ lnumeric.c 2005-03-16 23:02:09.000000000 -0800
+@@ -27,12 +27,14 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/lnumeric.c,v 1.16 2003/06/26 10:46:16 phantom Exp $");
+
++#include "xlocale_private.h"
++
+ #include <limits.h>
++#include <string.h>
+
+ #include "ldpart.h"
+ #include "lnumeric.h"
+
+-extern int __nlocale_changed;
+ extern const char *__fix_locale_grouping_str(const char *);
+
+ #define LCNUMERIC_SIZE (sizeof(struct lc_numeric_T) / sizeof(char *))
+@@ -45,49 +47,85 @@
+ numempty /* grouping */
+ };
+
+-static struct lc_numeric_T _numeric_locale;
+-static int _numeric_using_locale;
+-static char *_numeric_locale_buf;
+-
+-int
+-__numeric_load_locale(const char *name)
++__private_extern__ int
++__numeric_load_locale(const char *name, locale_t loc)
+ {
int ret;
++ struct __xlocale_st_numeric *xp;
++ static struct __xlocale_st_numeric *cache = NULL;
++
++ /* 'name' must be already checked. */
++ if (strcmp(name, "C") == 0 || strcmp(name, "POSIX") == 0) {
++ if (!loc->_numeric_using_locale)
++ return (_LDP_CACHE);
++ loc->_numeric_using_locale = 0;
++ XL_RELEASE(loc->__lc_numeric);
++ loc->__lc_numeric = NULL;
++ loc->__nlocale_changed = 1;
++ return (_LDP_CACHE);
++ }
++
++ if (loc->_numeric_using_locale && strcmp(name, loc->__lc_numeric->_numeric_locale_buf) == 0)
++ return (_LDP_CACHE);
++ /*
++ * If the locale name is the same as our cache, use the cache.
++ */
++ if (cache && cache->_numeric_locale_buf && strcmp(name, cache->_numeric_locale_buf) == 0) {
++ loc->_numeric_using_locale = 1;
++ XL_RELEASE(loc->__lc_numeric);
++ loc->__lc_numeric = cache;
++ XL_RETAIN(loc->__lc_numeric);
++ loc->__nlocale_changed = 1;
++ return (_LDP_CACHE);
++ }
++ if ((xp = (struct __xlocale_st_numeric *)malloc(sizeof(*xp))) == NULL)
++ return _LDP_ERROR;
++ xp->__refcount = 1;
++ xp->__free_extra = (__free_extra_t)__ldpart_free_extra;
++ xp->_numeric_locale_buf = NULL;
- ret = __part_load_locale(name, &_numeric_using_locale,
-- _numeric_locale_buf, "LC_NUMERIC",
-+ &_numeric_locale_buf, "LC_NUMERIC",
+- ret = __part_load_locale(name, &_numeric_using_locale,
+- &_numeric_locale_buf, "LC_NUMERIC",
++ ret = __part_load_locale(name, &loc->_numeric_using_locale,
++ &xp->_numeric_locale_buf, "LC_NUMERIC",
LCNUMERIC_SIZE, LCNUMERIC_SIZE,
- (const char **)&_numeric_locale);
+- (const char **)&_numeric_locale);
++ (const char **)&xp->_numeric_locale);
if (ret != _LDP_ERROR)
+- __nlocale_changed = 1;
++ loc->__nlocale_changed = 1;
++ else
++ free(xp);
+ if (ret == _LDP_LOADED) {
+ /* Can't be empty according to C99 */
+- if (*_numeric_locale.decimal_point == '\0')
+- _numeric_locale.decimal_point =
++ if (*xp->_numeric_locale.decimal_point == '\0')
++ xp->_numeric_locale.decimal_point =
+ _C_numeric_locale.decimal_point;
+- _numeric_locale.grouping =
+- __fix_locale_grouping_str(_numeric_locale.grouping);
++ xp->_numeric_locale.grouping =
++ __fix_locale_grouping_str(xp->_numeric_locale.grouping);
++ XL_RELEASE(loc->__lc_numeric);
++ loc->__lc_numeric = xp;
++ XL_RELEASE(cache);
++ cache = xp;
++ XL_RETAIN(cache);
+ }
+ return (ret);
+ }
+
+-struct lc_numeric_T *
+-__get_current_numeric_locale(void)
++__private_extern__ struct lc_numeric_T *
++__get_current_numeric_locale(locale_t loc)
+ {
+- return (_numeric_using_locale
+- ? &_numeric_locale
++ return (loc->_numeric_using_locale
++ ? &loc->__lc_numeric->_numeric_locale
+ : (struct lc_numeric_T *)&_C_numeric_locale);
+ }
+
+ #ifdef LOCALE_DEBUG
+ void
+ numericdebug(void) {
++locale_t loc = __current_locale();
+ printf( "decimal_point = %s\n"
+ "thousands_sep = %s\n"
+ "grouping = %s\n",
+- _numeric_locale.decimal_point,
+- _numeric_locale.thousands_sep,
+- _numeric_locale.grouping
++ loc->__lc_numeric->_numeric_locale.decimal_point,
++ loc->__lc_numeric->_numeric_locale.thousands_sep,
++ loc->__lc_numeric->_numeric_locale.grouping
+ );
+ }
+ #endif /* LOCALE_DEBUG */
--- /dev/null
+--- lnumeric.h.orig 2003-05-20 15:21:44.000000000 -0700
++++ lnumeric.h 2005-02-19 14:44:29.000000000 -0800
+@@ -29,13 +29,15 @@
+ #ifndef _LNUMERIC_H_
+ #define _LNUMERIC_H_
+
++#include <xlocale.h>
++
+ struct lc_numeric_T {
+ const char *decimal_point;
+ const char *thousands_sep;
+ const char *grouping;
+ };
+
+-struct lc_numeric_T *__get_current_numeric_locale(void);
+-int __numeric_load_locale(const char *);
++struct lc_numeric_T *__get_current_numeric_locale(locale_t);
++int __numeric_load_locale(const char *, locale_t);
+
+ #endif /* !_LNUMERIC_H_ */
--- /dev/null
+.\" Copyright (c) 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Donn Seeley at BSDI.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" From @(#)setlocale.3 8.1 (Berkeley) 6/9/93
+.\" From FreeBSD: src/lib/libc/locale/setlocale.3,v 1.28 2003/11/15 02:26:04 tjr Exp
+.\" $FreeBSD: src/lib/libc/locale/localeconv.3,v 1.2 2004/07/05 06:36:36 ru Exp $
+.\"
+.Dd November 21, 2003
+.Dt LOCALECONV 3
+.Os
+.Sh NAME
+.Nm localeconv
+.Nd natural language formatting for C
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In locale.h
+.Ft struct lconv *
+.Fn localeconv "void"
+.Sh DESCRIPTION
+The
+.Fn localeconv
+function returns a pointer to a structure
+which provides parameters for formatting numbers,
+especially currency values:
+.Bd -literal -offset indent
+struct lconv {
+ char *decimal_point;
+ char *thousands_sep;
+ char *grouping;
+ char *int_curr_symbol;
+ char *currency_symbol;
+ char *mon_decimal_point;
+ char *mon_thousands_sep;
+ char *mon_grouping;
+ char *positive_sign;
+ char *negative_sign;
+ char int_frac_digits;
+ char frac_digits;
+ char p_cs_precedes;
+ char p_sep_by_space;
+ char n_cs_precedes;
+ char n_sep_by_space;
+ char p_sign_posn;
+ char n_sign_posn;
+ char int_p_cs_precedes;
+ char int_n_cs_precedes;
+ char int_p_sep_by_space;
+ char int_n_sep_by_space;
+ char int_p_sign_posn;
+ char int_n_sign_posn;
+};
+.Ed
+.Pp
+The individual fields have the following meanings:
+.Pp
+.Bl -tag -width mon_decimal_point
+.It Va decimal_point
+The decimal point character, except for currency values,
+cannot be an empty string.
+.It Va thousands_sep
+The separator between groups of digits
+before the decimal point, except for currency values.
+.It Va grouping
+The sizes of the groups of digits, except for currency values.
+This is a pointer to a vector of integers, each of size
+.Vt char ,
+representing group size from low order digit groups
+to high order (right to left).
+The list may be terminated with 0 or
+.Dv CHAR_MAX .
+If the list is terminated with 0,
+the last group size before the 0 is repeated to account for all the digits.
+If the list is terminated with
+.Dv CHAR_MAX ,
+no more grouping is performed.
+.It Va int_curr_symbol
+The standardized international currency symbol.
+.It Va currency_symbol
+The local currency symbol.
+.It Va mon_decimal_point
+The decimal point character for currency values.
+.It Va mon_thousands_sep
+The separator for digit groups in currency values.
+.It Va mon_grouping
+Like
+.Va grouping
+but for currency values.
+.It Va positive_sign
+The character used to denote nonnegative currency values,
+usually the empty string.
+.It Va negative_sign
+The character used to denote negative currency values,
+usually a minus sign.
+.It Va int_frac_digits
+The number of digits after the decimal point
+in an international-style currency value.
+.It Va frac_digits
+The number of digits after the decimal point
+in the local style for currency values.
+.It Va p_cs_precedes
+1 if the currency symbol precedes the currency value
+for nonnegative values, 0 if it follows.
+.It Va p_sep_by_space
+1 if a space is inserted between the currency symbol
+and the currency value for nonnegative values, 0 otherwise.
+.It Va n_cs_precedes
+Like
+.Va p_cs_precedes
+but for negative values.
+.It Va n_sep_by_space
+Like
+.Va p_sep_by_space
+but for negative values.
+.It Va p_sign_posn
+The location of the
+.Va positive_sign
+with respect to a nonnegative quantity and the
+.Va currency_symbol ,
+coded as follows:
+.Pp
+.Bl -tag -width 3n -compact
+.It Li 0
+Parentheses around the entire string.
+.It Li 1
+Before the string.
+.It Li 2
+After the string.
+.It Li 3
+Just before
+.Va currency_symbol .
+.It Li 4
+Just after
+.Va currency_symbol .
+.El
+.It Va n_sign_posn
+Like
+.Va p_sign_posn
+but for negative currency values.
+.It Va int_p_cs_precedes
+Same as
+.Va p_cs_precedes ,
+but for internationally formatted monetary quantities.
+.It Va int_n_cs_precedes
+Same as
+.Va n_cs_precedes ,
+but for internationally formatted monetary quantities.
+.It Va int_p_sep_by_space
+Same as
+.Va p_sep_by_space ,
+but for internationally formatted monetary quantities.
+.It Va int_n_sep_by_space
+Same as
+.Va n_sep_by_space ,
+but for internationally formatted monetary quantities.
+.It Va int_p_sign_posn
+Same as
+.Va p_sign_posn ,
+but for internationally formatted monetary quantities.
+.It Va int_n_sign_posn
+Same as
+.Va n_sign_posn ,
+but for internationally formatted monetary quantities.
+.El
+.Pp
+Unless mentioned above,
+an empty string as a value for a field
+indicates a zero length result or
+a value that is not in the current locale.
+A
+.Dv CHAR_MAX
+result similarly denotes an unavailable value.
+.Sh RETURN VALUES
+The
+.Fn localeconv
+function returns a pointer to a static object
+which may be altered by later calls to
+.Xr setlocale 3
+or
+.Fn localeconv .
+.Sh ERRORS
+No errors are defined.
+.Sh SEE ALSO
+.Xr setlocale 3 ,
+.Xr strfmon 3
+.Sh STANDARDS
+The
+.Fn localeconv
+function conforms to
+.St -isoC-99 .
+.Sh HISTORY
+The
+.Fn localeconv
+function first appeared in
+.Bx 4.4 .
--- /dev/null
+--- localeconv.3.orig Fri Mar 11 19:44:47 2005
++++ localeconv.3 Fri Mar 11 19:57:53 2005
+@@ -40,7 +40,8 @@
+ .Dt LOCALECONV 3
+ .Os
+ .Sh NAME
+-.Nm localeconv
++.Nm localeconv ,
++.Nm localeconv_l
+ .Nd natural language formatting for C
+ .Sh LIBRARY
+ .Lb libc
+@@ -48,6 +49,9 @@
+ .In locale.h
+ .Ft struct lconv *
+ .Fn localeconv "void"
++.In xlocale.h
++.Ft struct lconv *
++.Fn localeconv_l "void" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn localeconv
+@@ -201,6 +205,14 @@
+ A
+ .Dv CHAR_MAX
+ result similarly denotes an unavailable value.
++.Pp
++While the
++.Fn localeconv
++function uses the current locale, the
++.Fn localeconv_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn localeconv
+@@ -213,7 +225,8 @@
+ No errors are defined.
+ .Sh SEE ALSO
+ .Xr setlocale 3 ,
+-.Xr strfmon 3
++.Xr strfmon 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn localeconv
static char sccsid[] = "@(#)localeconv.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/localeconv.c,v 1.12 2002/10/09 09:19:28 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/localeconv.c,v 1.13 2003/06/26 10:46:16 phantom Exp $");
#include <locale.h>
+
#include "lmonetary.h"
#include "lnumeric.h"
---- localeconv.c.orig Tue May 20 15:21:44 2003
-+++ localeconv.c Thu Sep 11 13:52:19 2003
-@@ -38,10 +38,66 @@
+--- localeconv.c.orig 2004-11-25 11:38:18.000000000 -0800
++++ localeconv.c 2005-02-17 23:35:43.000000000 -0800
+@@ -38,11 +38,69 @@
#include <sys/cdefs.h>
- __FBSDID("$FreeBSD: src/lib/libc/locale/localeconv.c,v 1.12 2002/10/09 09:19:28 tjr Exp $");
+ __FBSDID("$FreeBSD: src/lib/libc/locale/localeconv.c,v 1.13 2003/06/26 10:46:16 phantom Exp $");
++#include "xlocale_private.h"
++
+#include <limits.h>
#include <locale.h>
+
#include "lmonetary.h"
#include "lnumeric.h"
/*
* The localeconv() function constructs a struct lconv from the current
* monetary and numeric locales.
-@@ -61,6 +117,13 @@
- localeconv()
+@@ -52,25 +110,37 @@
+ * lconv structure are computed only when the monetary or numeric
+ * locale has been changed.
+ */
+-int __mlocale_changed = 1;
+-int __nlocale_changed = 1;
+
+ /*
+ * Return the current locale conversion.
+ */
+ struct lconv *
+-localeconv()
++localeconv_l(locale_t loc)
{
- static struct lconv ret;
+- static struct lconv ret;
++ struct __xlocale_st_localeconv *lc;
++
++ NORMALIZE_LOCALE(loc);
++ if (loc->__lc_localeconv && !loc->__mlocale_changed && !loc->__nlocale_changed)
++ return &loc->__lc_localeconv->__ret;
++
++ lc = (struct __xlocale_st_localeconv *)malloc(sizeof(struct __xlocale_st_localeconv));
++ lc->__refcount = 1;
++ lc->__free_extra = NULL;
++ if (loc->__lc_localeconv)
++ lc->__ret = loc->__lc_localeconv->__ret;
++ else {
++ loc->__mlocale_changed = 1;
++ loc->__nlocale_changed = 1;
++ }
+
+- if (__mlocale_changed) {
++ if (loc->__mlocale_changed) {
+ /* LC_MONETARY part */
+ struct lc_monetary_T * mptr;
+
+-#define M_ASSIGN_STR(NAME) (ret.NAME = (char*)mptr->NAME)
+-#define M_ASSIGN_CHAR(NAME) (ret.NAME = mptr->NAME[0])
++#define M_ASSIGN_STR(NAME) (lc->__ret.NAME = (char*)mptr->NAME)
++#define M_ASSIGN_CHAR(NAME) (lc->__ret.NAME = mptr->NAME[0])
+
+- mptr = __get_current_monetary_locale();
++ mptr = __get_current_monetary_locale(loc);
+ M_ASSIGN_STR(int_curr_symbol);
+ M_ASSIGN_STR(currency_symbol);
+ M_ASSIGN_STR(mon_decimal_point);
+@@ -92,21 +162,39 @@
+ M_ASSIGN_CHAR(int_n_sep_by_space);
+ M_ASSIGN_CHAR(int_p_sign_posn);
+ M_ASSIGN_CHAR(int_n_sign_posn);
+- __mlocale_changed = 0;
++ loc->__mlocale_changed = 0;
+ }
+
+- if (__nlocale_changed) {
++ if (loc->__nlocale_changed) {
+ /* LC_NUMERIC part */
+ struct lc_numeric_T * nptr;
+
+-#define N_ASSIGN_STR(NAME) (ret.NAME = (char*)nptr->NAME)
++#define N_ASSIGN_STR(NAME) (lc->__ret.NAME = (char*)nptr->NAME)
+
+- nptr = __get_current_numeric_locale();
++ nptr = __get_current_numeric_locale(loc);
+ N_ASSIGN_STR(decimal_point);
+ N_ASSIGN_STR(thousands_sep);
+ N_ASSIGN_STR(grouping);
+- __nlocale_changed = 0;
++ loc->__nlocale_changed = 0;
+ }
+
+- return (&ret);
++ XL_RELEASE(loc->__lc_localeconv);
++ loc->__lc_localeconv = lc;
++
++ return (&lc->__ret);
++}
+
++/*
++ * Return the current locale conversion.
++ */
++struct lconv *
++localeconv()
++{
+ /*--------------------------------------------------------------------
+ * If _onlyClocaleconv is non-zero, just return __lconv, which is a "C"
+ * struct lconv *. Otherwise, do the normal thing.
+ *--------------------------------------------------------------------*/
+ if (_onlyClocaleconv)
+ return &_C_lconv;
-
- if (__mlocale_changed) {
- /* LC_MONETARY part */
++ return localeconv_l(__current_locale());
+ }
--- /dev/null
+.\" Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved.
+.\" Copyright (c) 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Donn Seeley of BSDI.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" From @(#)multibyte.3 8.1 (Berkeley) 6/4/93
+.\" From FreeBSD: src/lib/libc/locale/multibyte.3,v 1.22 2003/11/08 03:23:11 tjr Exp
+.\" $FreeBSD: src/lib/libc/locale/mblen.3,v 1.5 2004/07/05 06:36:36 ru Exp $
+.\"
+.Dd April 11, 2004
+.Dt MBLEN 3
+.Os
+.Sh NAME
+.Nm mblen
+.Nd get number of bytes in a character
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdlib.h
+.Ft int
+.Fn mblen "const char *mbchar" "size_t nbytes"
+.Sh DESCRIPTION
+The
+.Fn mblen
+function computes the length in bytes
+of a multibyte character
+.Fa mbchar
+according to the current conversion state.
+Up to
+.Fa nbytes
+bytes are examined.
+.Pp
+A call with a null
+.Fa mbchar
+pointer returns nonzero if the current locale requires shift states,
+zero otherwise;
+if shift states are required, the shift state is reset to the initial state.
+.Sh RETURN VALUES
+If
+.Fa mbchar
+is
+.Dv NULL ,
+the
+.Fn mblen
+function returns nonzero if shift states are supported,
+zero otherwise.
+.Pp
+Otherwise, if
+.Fa mbchar
+is not a null pointer,
+.Fn mblen
+either returns 0 if
+.Fa mbchar
+represents the null wide character, or returns
+the number of bytes processed in
+.Fa mbchar ,
+or returns \-1 if no multibyte character
+could be recognized or converted.
+In this case,
+.Fn mblen Ns 's
+internal conversion state is undefined.
+.Sh ERRORS
+The
+.Fn mblen
+function will fail if:
+.Bl -tag -width Er
+.It Bq Er EILSEQ
+An invalid multibyte sequence was detected.
+.It Bq Er EINVAL
+The internal conversion state is not valid.
+.El
+.Sh SEE ALSO
+.Xr mbrlen 3 ,
+.Xr mbtowc 3 ,
+.Xr multibyte 3
+.Sh STANDARDS
+The
+.Fn mblen
+function conforms to
+.St -isoC-99 .
--- /dev/null
+--- mblen.3.orig Fri Mar 11 19:44:47 2005
++++ mblen.3 Fri Mar 11 19:57:09 2005
+@@ -41,7 +41,8 @@
+ .Dt MBLEN 3
+ .Os
+ .Sh NAME
+-.Nm mblen
++.Nm mblen ,
++.Nm mblen_l
+ .Nd get number of bytes in a character
+ .Sh LIBRARY
+ .Lb libc
+@@ -49,6 +50,9 @@
+ .In stdlib.h
+ .Ft int
+ .Fn mblen "const char *mbchar" "size_t nbytes"
++.In xlocale.h
++.Ft int
++.Fn mblen_l "const char *mbchar" "size_t nbytes" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn mblen
+@@ -65,6 +69,14 @@
+ pointer returns nonzero if the current locale requires shift states,
+ zero otherwise;
+ if shift states are required, the shift state is reset to the initial state.
++.Pp
++While the
++.Fn mblen
++function uses the current locale, the
++.Fn mblen_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ If
+ .Fa mbchar
+@@ -102,7 +114,8 @@
+ .Sh SEE ALSO
+ .Xr mbrlen 3 ,
+ .Xr mbtowc 3 ,
+-.Xr multibyte 3
++.Xr multibyte 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn mblen
/*-
- * Copyright (c) 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Paul Borman at Krystal Technologies.
+ * Copyright (c) 2002-2004 Tim J. Robbins.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * 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 REGENTS OR CONTRIBUTORS BE LIABLE
+ * 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)
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/mblen.c,v 1.4 2002/10/28 08:24:46 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/mblen.c,v 1.9 2004/07/29 06:18:40 tjr Exp $");
-#include <errno.h>
-#include <stddef.h>
#include <stdlib.h>
-#include <rune.h>
+#include <wchar.h>
+#include "mblocal.h"
int
mblen(const char *s, size_t n)
{
- const char *e;
+ static const mbstate_t initial;
+ static mbstate_t mbs;
+ size_t rval;
- if (s == NULL)
+ if (s == NULL) {
/* No support for state dependent encodings. */
- return (0);
- if (sgetrune(s, n, &e) == _INVALID_RUNE) {
- errno = EILSEQ;
- return (-1);
+ mbs = initial;
+ return (0);
}
- return (*s == '\0' ? 0 : e - s);
+ rval = __mbrtowc(NULL, s, n, &mbs);
+ if (rval == (size_t)-1 || rval == (size_t)-2)
+ return (-1);
+ return ((int)rval);
}
--- /dev/null
+--- mblen.c.orig Thu Nov 25 11:38:18 2004
++++ mblen.c Fri Feb 18 16:55:20 2005
+@@ -27,24 +27,32 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/mblen.c,v 1.9 2004/07/29 06:18:40 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdlib.h>
+ #include <wchar.h>
+ #include "mblocal.h"
+
+ int
+-mblen(const char *s, size_t n)
++mblen_l(const char *s, size_t n, locale_t loc)
+ {
+ static const mbstate_t initial;
+- static mbstate_t mbs;
+ size_t rval;
+
++ NORMALIZE_LOCALE(loc);
+ if (s == NULL) {
+ /* No support for state dependent encodings. */
+- mbs = initial;
++ loc->__mbs_mblen = initial;
+ return (0);
+ }
+- rval = __mbrtowc(NULL, s, n, &mbs);
++ rval = loc->__lc_ctype->__mbrtowc(NULL, s, n, &loc->__mbs_mblen, loc);
+ if (rval == (size_t)-1 || rval == (size_t)-2)
+ return (-1);
+ return ((int)rval);
++}
++
++int
++mblen(const char *s, size_t n)
++{
++ return mblen_l(s, n, __current_locale());
+ }
--- /dev/null
+/*-
+ * Copyright (c) 2004 Tim J. Robbins.
+ * 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.
+ *
+ * $FreeBSD: src/lib/libc/locale/mblocal.h,v 1.4 2004/10/17 06:51:50 tjr Exp $
+ */
+
+#ifndef _MBLOCAL_H_
+#define _MBLOCAL_H_
+
+/*
+ * Conversion function pointers for current encoding.
+ */
+extern size_t (*__mbrtowc)(wchar_t * __restrict, const char * __restrict,
+ size_t, mbstate_t * __restrict);
+extern int (*__mbsinit)(const mbstate_t *);
+extern size_t (*__mbsnrtowcs)(wchar_t * __restrict, const char ** __restrict,
+ size_t, size_t, mbstate_t * __restrict);
+extern size_t (*__wcrtomb)(char * __restrict, wchar_t, mbstate_t * __restrict);
+extern size_t (*__wcsnrtombs)(char * __restrict, const wchar_t ** __restrict,
+ size_t, size_t, mbstate_t * __restrict);
+
+/*
+ * Conversion functions for "NONE"/C/POSIX encoding.
+ */
+extern size_t _none_mbrtowc(wchar_t * __restrict, const char * __restrict,
+ size_t, mbstate_t * __restrict);
+extern int _none_mbsinit(const mbstate_t *);
+extern size_t _none_mbsnrtowcs(wchar_t * __restrict, const char ** __restrict,
+ size_t, size_t, mbstate_t * __restrict);
+extern size_t _none_wcrtomb(char * __restrict, wchar_t,
+ mbstate_t * __restrict);
+extern size_t _none_wcsnrtombs(char * __restrict, const wchar_t ** __restrict,
+ size_t, size_t, mbstate_t * __restrict);
+
+extern size_t __mbsnrtowcs_std(wchar_t * __restrict, const char ** __restrict,
+ size_t, size_t, mbstate_t * __restrict);
+extern size_t __wcsnrtombs_std(char * __restrict, const wchar_t ** __restrict,
+ size_t, size_t, mbstate_t * __restrict);
+
+#endif /* _MBLOCAL_H_ */
--- /dev/null
+--- mblocal.h.orig 2004-11-25 11:38:18.000000000 -0800
++++ mblocal.h 2005-02-18 18:25:53.000000000 -0800
+@@ -30,33 +30,21 @@
+ #define _MBLOCAL_H_
+
+ /*
+- * Conversion function pointers for current encoding.
+- */
+-extern size_t (*__mbrtowc)(wchar_t * __restrict, const char * __restrict,
+- size_t, mbstate_t * __restrict);
+-extern int (*__mbsinit)(const mbstate_t *);
+-extern size_t (*__mbsnrtowcs)(wchar_t * __restrict, const char ** __restrict,
+- size_t, size_t, mbstate_t * __restrict);
+-extern size_t (*__wcrtomb)(char * __restrict, wchar_t, mbstate_t * __restrict);
+-extern size_t (*__wcsnrtombs)(char * __restrict, const wchar_t ** __restrict,
+- size_t, size_t, mbstate_t * __restrict);
+-
+-/*
+ * Conversion functions for "NONE"/C/POSIX encoding.
+ */
+ extern size_t _none_mbrtowc(wchar_t * __restrict, const char * __restrict,
+- size_t, mbstate_t * __restrict);
+-extern int _none_mbsinit(const mbstate_t *);
++ size_t, mbstate_t * __restrict, locale_t);
++extern int _none_mbsinit(const mbstate_t *, locale_t);
+ extern size_t _none_mbsnrtowcs(wchar_t * __restrict, const char ** __restrict,
+- size_t, size_t, mbstate_t * __restrict);
++ size_t, size_t, mbstate_t * __restrict, locale_t);
+ extern size_t _none_wcrtomb(char * __restrict, wchar_t,
+- mbstate_t * __restrict);
++ mbstate_t * __restrict, locale_t);
+ extern size_t _none_wcsnrtombs(char * __restrict, const wchar_t ** __restrict,
+- size_t, size_t, mbstate_t * __restrict);
++ size_t, size_t, mbstate_t * __restrict, locale_t);
+
+ extern size_t __mbsnrtowcs_std(wchar_t * __restrict, const char ** __restrict,
+- size_t, size_t, mbstate_t * __restrict);
++ size_t, size_t, mbstate_t * __restrict, locale_t);
+ extern size_t __wcsnrtombs_std(char * __restrict, const wchar_t ** __restrict,
+- size_t, size_t, mbstate_t * __restrict);
++ size_t, size_t, mbstate_t * __restrict, locale_t);
+
+ #endif /* _MBLOCAL_H_ */
-.\" Copyright (c) 2002 Tim J. Robbins
+.\" Copyright (c) 2002-2004 Tim J. Robbins
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/lib/libc/locale/mbrlen.3,v 1.6 2002/11/29 17:35:09 ru Exp $
+.\" $FreeBSD: src/lib/libc/locale/mbrlen.3,v 1.8 2004/06/30 19:32:41 ru Exp $
.\"
-.Dd November 11, 2002
+.Dd April 7, 2004
.Dt MBRLEN 3
.Os
.Sh NAME
.Sh DESCRIPTION
The
.Fn mbrlen
-function determines the number of bytes constituting the
-multibyte character sequence pointed to by
-.Fa s ,
-examining at most
+function inspects at most
.Fa n
-bytes.
+bytes pointed to by
+.Fa s
+to determine the number of bytes needed to complete the next
+multibyte character.
.Pp
The
.Vt mbstate_t
.Fn mbrlen
uses an internal, static
.Vt mbstate_t
-object.
+object, which is initialized to the initial conversion state
+at program startup.
.Pp
It is equivalent to:
.Pp
functions returns:
.Bl -tag -width indent
.It 0
-The first
+The next
.Fa n
-or fewer bytes of
-.Fa s
+or fewer bytes
represent the null wide character
.Pq Li "L'\e0'" .
.It >0
-The first
+The next
.Fa n
-or fewer bytes of
-.Fa s
+or fewer bytes
represent a valid character,
-.Fn mbrtowc
-returns the length (in bytes) of the multibyte sequence.
+.Fn mbrlen
+returns the number of bytes used to complete the multibyte character.
.It Po Vt size_t Pc Ns \-2
-The first
+The next
.Fa n
-bytes of
-.Fa s
-are an incomplete multibyte sequence.
+contribute to, but do not complete, a valid multibyte character sequence,
+and all
+.Fa n
+bytes have been processed.
.It Po Vt size_t Pc Ns \-1
-The byte sequence pointed to by
-.Fa s
-is an invalid multibyte sequence.
+An encoding error has occurred.
+The next
+.Fa n
+or fewer bytes do not contribute to a valid multibyte character.
.El
.Sh EXAMPLES
-A function which calculates the number of characters in a multibyte
+A function that calculates the number of characters in a multibyte
character string:
.Bd -literal -offset indent
size_t
.Fn mbrlen
function will fail if:
.Bl -tag -width Er
-.\".It Bq Er EINVAL
-.\"Invalid argument.
.It Bq Er EILSEQ
An invalid multibyte sequence was detected.
+.It Bq Er EINVAL
+The conversion state is invalid.
.El
.Sh SEE ALSO
.Xr mblen 3 ,
-.Xr mbrtowc 3
+.Xr mbrtowc 3 ,
+.Xr multibyte 3
.Sh STANDARDS
The
.Fn mbrlen
function conforms to
.St -isoC-99 .
-.Sh BUGS
-The current implementation does not support shift states.
--- /dev/null
+--- mbrlen.3.orig Fri Mar 11 19:44:47 2005
++++ mbrlen.3 Fri Mar 11 19:56:39 2005
+@@ -28,7 +28,8 @@
+ .Dt MBRLEN 3
+ .Os
+ .Sh NAME
+-.Nm mbrlen
++.Nm mbrlen ,
++.Nm mbrlen_l
+ .Nd "get number of bytes in a character (restartable)"
+ .Sh LIBRARY
+ .Lb libc
+@@ -36,6 +37,9 @@
+ .In wchar.h
+ .Ft size_t
+ .Fn mbrlen "const char * restrict s" "size_t n" "mbstate_t * restrict ps"
++.In xlocale.h
++.Ft size_t
++.Fn mbrlen_l "const char * restrict s" "size_t n" "mbstate_t * restrict ps" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn mbrlen
+@@ -72,6 +76,14 @@
+ uses its own static, internal
+ .Vt mbstate_t
+ object to keep track of the shift state.
++.Pp
++While the
++.Fn mbrlen
++function uses the current locale, the
++.Fn mbrlen_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn mbrlen
+@@ -137,7 +149,8 @@
+ .Sh SEE ALSO
+ .Xr mblen 3 ,
+ .Xr mbrtowc 3 ,
+-.Xr multibyte 3
++.Xr multibyte 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn mbrlen
/*-
- * Copyright (c) 2002 Tim J. Robbins.
+ * Copyright (c) 2002-2004 Tim J. Robbins.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/mbrlen.c,v 1.2 2002/09/06 11:23:45 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/mbrlen.c,v 1.4 2004/05/12 14:26:54 tjr Exp $");
#include <wchar.h>
+#include "mblocal.h"
size_t
-mbrlen(const char * __restrict s, size_t n, mbstate_t * __restrict ps __unused)
+mbrlen(const char * __restrict s, size_t n, mbstate_t * __restrict ps)
{
+ static mbstate_t mbs;
- return (mbrtowc(NULL, s, n, NULL));
+ if (ps == NULL)
+ ps = &mbs;
+ return (__mbrtowc(NULL, s, n, ps));
}
--- /dev/null
+--- mbrlen.c.orig Thu Nov 25 11:38:18 2004
++++ mbrlen.c Fri Feb 18 16:54:36 2005
+@@ -27,15 +27,23 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/mbrlen.c,v 1.4 2004/05/12 14:26:54 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <wchar.h>
+ #include "mblocal.h"
+
+ size_t
+-mbrlen(const char * __restrict s, size_t n, mbstate_t * __restrict ps)
++mbrlen_l(const char * __restrict s, size_t n, mbstate_t * __restrict ps,
++ locale_t loc)
+ {
+- static mbstate_t mbs;
+-
++ NORMALIZE_LOCALE(loc);
+ if (ps == NULL)
+- ps = &mbs;
+- return (__mbrtowc(NULL, s, n, ps));
++ ps = &loc->__mbs_mbrlen;
++ return (loc->__lc_ctype->__mbrtowc(NULL, s, n, ps, loc));
++}
++
++size_t
++mbrlen(const char * __restrict s, size_t n, mbstate_t * __restrict ps)
++{
++ return mbrlen_l(s, n, ps, __current_locale());
+ }
-.\" Copyright (c) 2002 Tim J. Robbins
+.\" Copyright (c) 2002-2004 Tim J. Robbins
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/lib/libc/locale/mbrtowc.3,v 1.3 2002/11/29 17:35:09 ru Exp $
+.\" $FreeBSD: src/lib/libc/locale/mbrtowc.3,v 1.5 2004/06/30 19:32:41 ru Exp $
.\"
-.Dd August 15, 2002
+.Dd April 8, 2004
.Dt MBRTOWC 3
.Os
.Sh NAME
.Fa n
bytes pointed to by
.Fa s
-and interprets them as a multibyte character sequence
-according to the current setting of
-.Ev LC_CTYPE .
-If
+to determine the number of bytes needed to complete the next multibyte
+character.
+If a character can be completed, and
.Fa pwc
is not
.Dv NULL ,
-the multibyte character which
+the wide character which is represented by
.Fa s
-represents is stored in the
+is stored in the
.Vt wchar_t
it points to.
.Pp
.Fn mbrtowc
uses an internal, static
.Vt mbstate_t
-object.
+object, which is initialized to the initial conversion state
+at program startup.
.Sh RETURN VALUES
The
.Fn mbrtowc
functions returns:
.Bl -tag -width indent
.It 0
-The first
+The next
.Fa n
-or fewer bytes of
-.Fa s
+or fewer bytes
represent the null wide character
.Pq Li "L'\e0'" .
.It >0
-The first
+The next
.Fa n
-or fewer bytes of
-.Fa s
+or fewer bytes
represent a valid character,
.Fn mbrtowc
-returns the length (in bytes) of the multibyte sequence.
+returns the number of bytes used to complete the multibyte character.
.It Po Vt size_t Pc Ns \-2
-The first
+The next
.Fa n
-bytes of
-.Fa s
-are an incomplete multibyte sequence.
+contribute to, but do not complete, a valid multibyte character sequence,
+and all
+.Fa n
+bytes have been processed.
.It Po Vt size_t Pc Ns \-1
-The byte sequence pointed to by
-.Fa s
-is an invalid multibyte sequence.
+An encoding error has occurred.
+The next
+.Fa n
+or fewer bytes do not contribute to a valid multibyte character.
.El
.Sh ERRORS
The
.Fn mbrtowc
function will fail if:
.Bl -tag -width Er
-.\".It Bq Er EINVAL
-.\"Invalid argument.
.It Bq Er EILSEQ
An invalid multibyte sequence was detected.
+.It Bq Er EINVAL
+The conversion state is invalid.
.El
.Sh SEE ALSO
.Xr mbtowc 3 ,
+.Xr multibyte 3 ,
.Xr setlocale 3 ,
.Xr wcrtomb 3
.Sh STANDARDS
.Fn mbrtowc
function conforms to
.St -isoC-99 .
-.Sh BUGS
-The current implementation does not support shift states.
--- /dev/null
+--- mbrtowc.3.orig Fri Mar 11 19:44:47 2005
++++ mbrtowc.3 Fri Mar 11 19:55:59 2005
+@@ -28,7 +28,8 @@
+ .Dt MBRTOWC 3
+ .Os
+ .Sh NAME
+-.Nm mbrtowc
++.Nm mbrtowc ,
++.Nm mbrtowc_l
+ .Nd "convert a character to a wide-character code (restartable)"
+ .Sh LIBRARY
+ .Lb libc
+@@ -39,6 +40,12 @@
+ .Fa "wchar_t * restrict pwc" "const char * restrict s" "size_t n"
+ .Fa "mbstate_t * restrict ps"
+ .Fc
++.In xlocale.h
++.Ft size_t
++.Fo mbrtowc_l
++.Fa "wchar_t * restrict pwc" "const char * restrict s" "size_t n"
++.Fa "mbstate_t * restrict ps" "locale_t loc"
++.Fc
+ .Sh DESCRIPTION
+ The
+ .Fn mbrtowc
+@@ -86,6 +93,14 @@
+ .Vt mbstate_t
+ object, which is initialized to the initial conversion state
+ at program startup.
++.Pp
++While the
++.Fn mbrtowc
++function uses the current locale, the
++.Fn mbrtowc_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn mbrtowc
+@@ -131,7 +146,8 @@
+ .Xr mbtowc 3 ,
+ .Xr multibyte 3 ,
+ .Xr setlocale 3 ,
+-.Xr wcrtomb 3
++.Xr wcrtomb 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn mbrtowc
/*-
- * Copyright (c) 2002 Tim J. Robbins.
+ * Copyright (c) 2002-2004 Tim J. Robbins.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/mbrtowc.c,v 1.3 2002/11/10 10:49:14 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/mbrtowc.c,v 1.7 2004/05/12 14:09:04 tjr Exp $");
-#include <errno.h>
-#include <rune.h>
-#include <stdlib.h>
#include <wchar.h>
+#include "mblocal.h"
size_t
-mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
- mbstate_t * __restrict ps __unused)
+mbrtowc(wchar_t * __restrict pwc, const char * __restrict s,
+ size_t n, mbstate_t * __restrict ps)
{
- const char *e;
- rune_t r;
+ static mbstate_t mbs;
- if (s == NULL) {
- pwc = NULL;
- s = "";
- n = 1;
- }
-
- if ((r = sgetrune(s, n, &e)) == _INVALID_RUNE) {
- /*
- * The design of sgetrune() doesn't give us any way to tell
- * between incomplete and invalid multibyte sequences.
- */
-
- if (n >= (size_t)MB_CUR_MAX) {
- /*
- * If we have been supplied with at least MB_CUR_MAX
- * bytes and still cannot find a valid character, the
- * data must be invalid.
- */
- errno = EILSEQ;
- return ((size_t)-1);
- }
-
- /*
- * .. otherwise, it's an incomplete character or an invalid
- * character we cannot detect yet.
- */
- return ((size_t)-2);
- }
-
- if (pwc != NULL)
- *pwc = (wchar_t)r;
-
- return (r != 0 ? (size_t)(e - s) : 0);
+ if (ps == NULL)
+ ps = &mbs;
+ return (__mbrtowc(pwc, s, n, ps));
}
--- /dev/null
+--- mbrtowc.c.orig 2004-11-25 11:38:18.000000000 -0800
++++ mbrtowc.c 2005-02-18 18:21:18.000000000 -0800
+@@ -27,16 +27,24 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/mbrtowc.c,v 1.7 2004/05/12 14:09:04 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <wchar.h>
+ #include "mblocal.h"
+
+ size_t
++mbrtowc_l(wchar_t * __restrict pwc, const char * __restrict s,
++ size_t n, mbstate_t * __restrict ps, locale_t loc)
++{
++ NORMALIZE_LOCALE(loc);
++ if (ps == NULL)
++ ps = &loc->__mbs_mbrtowc;
++ return (loc->__lc_ctype->__mbrtowc(pwc, s, n, ps, loc));
++}
++
++size_t
+ mbrtowc(wchar_t * __restrict pwc, const char * __restrict s,
+ size_t n, mbstate_t * __restrict ps)
+ {
+- static mbstate_t mbs;
+-
+- if (ps == NULL)
+- ps = &mbs;
+- return (__mbrtowc(pwc, s, n, ps));
++ return mbrtowc_l(pwc, s, n, ps, __current_locale());
+ }
+++ /dev/null
-.\" Copyright (c) 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" This code is derived from software contributed to Berkeley by
-.\" Paul Borman at Krystal Technologies.
-.\"
-.\" 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.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
-.\"
-.\" @(#)mbrune.3 8.2 (Berkeley) 4/19/94
-.\" $FreeBSD: src/lib/libc/locale/mbrune.3,v 1.15 2003/02/06 11:04:46 charnier Exp $
-.\"
-.Dd April 19, 1994
-.Dt MBRUNE 3
-.Os
-.Sh NAME
-.Nm mbrune ,
-.Nm mbrrune ,
-.Nm mbmb
-.Nd multibyte rune support for C
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In rune.h
-.Ft char *
-.Fn mbrune "const char *string" "rune_t rune"
-.Ft char *
-.Fn mbrrune "const char *string" "rune_t rune"
-.Ft char *
-.Fn mbmb "const char *string" "char *pattern"
-.Sh DESCRIPTION
-.Bf Em
-The
-.Bx 4.4
-.Dq rune
-functions have been deprecated in favour of the
-.Tn ISO
-C99 extended multibyte and wide character facilities
-and should not be used in new applications.
-.Ef
-Consider working with wide characters instead, and using
-.Xr wcschr 3 ,
-.Xr wcsrchr 3 ,
-and
-.Xr wcsstr 3
-instead of these functions.
-.Pp
-These routines provide the corresponding functionality of
-.Fn strchr ,
-.Fn strrchr
-and
-.Fn strstr
-for multibyte strings.
-.Pp
-The
-.Fn mbrune
-function locates the first occurrence of
-.Fn rune
-in the string pointed to by
-.Fa string .
-The terminating
-.Dv NUL
-character is considered part of the string.
-If
-.Fa rune
-is
-.Ql \e0 ,
-.Fn mbrune
-locates the terminating
-.Ql \e0 .
-.Pp
-The
-.Fn mbrrune
-function
-locates the last occurrence of
-.Fa rune
-in the string
-.Fa string .
-If
-.Fa rune
-is
-.Ql \e0 ,
-.Fn mbrune
-locates the terminating
-.Ql \e0 .
-.Pp
-The
-.Fn mbmb
-function locates the first occurrence of the null-terminated string
-.Fa pattern
-in the null-terminated string
-.Fa string .
-If
-.Fa pattern
-is the empty string,
-.Fn mbmb
-returns
-.Fa string ;
-if
-.Fa pattern
-occurs nowhere in
-.Fa string ,
-.Fn mbmb
-returns
-.Dv NULL ;
-otherwise
-.Fn mbmb
-returns a pointer to the first character of the first occurrence of
-.Fa pattern .
-.Sh RETURN VALUES
-The function
-.Fn mbrune
-returns a pointer to the located character, or
-.Dv NULL
-if the character does not appear in the string.
-.Pp
-The
-.Fn mbrrune
-function
-returns a pointer to the character, or
-.Dv NULL
-if the character does not appear in the string.
-.Pp
-The
-.Fn mbmb
-function
-returns a pointer to the
-.Fa pattern ,
-or
-.Dv NULL
-if the
-.Fa pattern
-does not appear in the string.
-.Sh SEE ALSO
-.Xr rune 3 ,
-.Xr setlocale 3 ,
-.Xr euc 4 ,
-.Xr utf2 4 ,
-.Xr utf8 5
-.Sh HISTORY
-The
-.Fn mbrune ,
-.Fn mbrrune ,
-and
-.Fn mbmb
-functions
-first appeared in Plan 9 from Bell Labs as
-.Fn utfrune ,
-.Fn utfrrune ,
-and
-.Fn utfutf .
+++ /dev/null
-/*-
- * Copyright (c) 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Paul Borman at Krystal Technologies.
- *
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)mbrune.c 8.1 (Berkeley) 6/27/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/mbrune.c,v 1.3 2002/09/18 06:11:21 tjr Exp $");
-
-#include <limits.h>
-#include <rune.h>
-#include <stddef.h>
-#include <string.h>
-
-__warn_references(mbrune, "warning: mbrune() is deprecated. See mbrune(3).");
-char *
-mbrune(string, c)
- const char *string;
- rune_t c;
-{
- char const *result;
- rune_t r;
-
- while ((r = sgetrune(string, MB_LEN_MAX, &result))) {
- if (r == c)
- return ((char *)string);
- string = result == string ? string + 1 : result;
- }
-
- return (c == *string ? (char *)string : NULL);
-}
-
-__warn_references(mbrrune, "warning: mbrrune() is deprecated. See mbrrune(3).");
-char *
-mbrrune(string, c)
- const char *string;
- rune_t c;
-{
- const char *last = 0;
- char const *result;
- rune_t r;
-
- while ((r = sgetrune(string, MB_LEN_MAX, &result))) {
- if (r == c)
- last = string;
- string = result == string ? string + 1 : result;
- }
- return (c == *string ? (char *)string : (char *)last);
-}
-
-__warn_references(mbmb, "warning: mbmb() is deprecated. See mbmb(3).");
-char *
-mbmb(string, pattern)
- const char *string;
- char *pattern;
-{
- rune_t first, r;
- size_t plen, slen;
- char const *result;
-
- plen = strlen(pattern);
- slen = strlen(string);
- if (plen > slen)
- return (0);
-
- first = sgetrune(pattern, plen, &result);
- if (result == string)
- return (0);
-
- while (slen >= plen && (r = sgetrune(string, slen, &result))) {
- if (r == first) {
- if (strncmp(string, pattern, slen) == 0)
- return ((char *) string);
- }
- if (result == string) {
- --slen;
- ++string;
- } else {
- slen -= result - string;
- string = result;
- }
- }
- return (0);
-}
-.\" Copyright (c) 2002 Tim J. Robbins
+.\" Copyright (c) 2002-2004 Tim J. Robbins
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/lib/libc/locale/mbsinit.3,v 1.2 2002/11/29 17:35:09 ru Exp $
+.\" $FreeBSD: src/lib/libc/locale/mbsinit.3,v 1.3 2004/04/08 09:59:02 tjr Exp $
.\"
-.Dd August 16, 2002
+.Dd April 8, 2004
.Dt MBSINIT 3
.Os
.Sh NAME
.Dv NULL
or describes an initial conversion state,
otherwise it returns zero.
+.Sh SEE ALSO
+.Xr mbrlen 3 ,
+.Xr mbrtowc 3 ,
+.Xr mbsrtowcs 3 ,
+.Xr multibyte 3 ,
+.Xr wcrtomb 3 ,
+.Xr wcsrtombs 3
.Sh STANDARDS
The
.Fn mbsinit
function conforms to
.St -isoC-99 .
-.Sh BUGS
-The current implementation does not support shift states;
-.Fn mbsinit
-always returns non-zero.
--- /dev/null
+--- mbsinit.3.orig Fri Mar 11 19:44:47 2005
++++ mbsinit.3 Fri Mar 11 19:55:14 2005
+@@ -28,7 +28,8 @@
+ .Dt MBSINIT 3
+ .Os
+ .Sh NAME
+-.Nm mbsinit
++.Nm mbsinit ,
++.Nm mbsinit_l
+ .Nd "determine conversion object status"
+ .Sh LIBRARY
+ .Lb libc
+@@ -36,6 +37,9 @@
+ .In wchar.h
+ .Ft int
+ .Fn mbsinit "const mbstate_t *ps"
++.In xlocale.h
++.Ft int
++.Fn mbsinit_l "const mbstate_t *ps" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn mbsinit
+@@ -44,6 +48,14 @@
+ object pointed to by
+ .Fa ps
+ describes an initial conversion state.
++.Pp
++While the
++.Fn mbsinit
++function uses the current locale, the
++.Fn mbsinit_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn mbsinit
+@@ -59,7 +71,8 @@
+ .Xr mbsrtowcs 3 ,
+ .Xr multibyte 3 ,
+ .Xr wcrtomb 3 ,
+-.Xr wcsrtombs 3
++.Xr wcsrtombs 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn mbsinit
/*-
- * Copyright (c) 2002 Tim J. Robbins.
+ * Copyright (c) 2002-2004 Tim J. Robbins.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/mbsinit.c,v 1.1 2002/08/18 06:30:10 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/mbsinit.c,v 1.3 2004/05/12 14:09:04 tjr Exp $");
#include <wchar.h>
+#include "mblocal.h"
int
-mbsinit(const mbstate_t *ps __unused)
+mbsinit(const mbstate_t *ps)
{
- /*
- * Stateful multibyte conversion is not supported; there are no
- * states other than the initial state.
- */
-
- return (1);
+ return (__mbsinit(ps));
}
--- /dev/null
+--- mbsinit.c.orig Thu Nov 25 11:38:18 2004
++++ mbsinit.c Fri Feb 18 16:12:33 2005
+@@ -27,12 +27,21 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/mbsinit.c,v 1.3 2004/05/12 14:09:04 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <wchar.h>
+ #include "mblocal.h"
+
+ int
+-mbsinit(const mbstate_t *ps)
++mbsinit_l(const mbstate_t *ps, locale_t loc)
+ {
+
+- return (__mbsinit(ps));
++ NORMALIZE_LOCALE(loc);
++ return (loc->__lc_ctype->__mbsinit(ps, loc));
++}
++
++int
++mbsinit(const mbstate_t *ps)
++{
++ return mbsinit_l(ps, __current_locale());
+ }
--- /dev/null
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins.
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/libc/locale/mbsnrtowcs.c,v 1.1 2004/07/21 10:54:57 tjr Exp $");
+
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include "mblocal.h"
+
+size_t
+mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src,
+ size_t nms, size_t len, mbstate_t * __restrict ps)
+{
+ static mbstate_t mbs;
+
+ if (ps == NULL)
+ ps = &mbs;
+ return (__mbsnrtowcs(dst, src, nms, len, ps));
+}
+
+size_t
+__mbsnrtowcs_std(wchar_t * __restrict dst, const char ** __restrict src,
+ size_t nms, size_t len, mbstate_t * __restrict ps)
+{
+ const char *s;
+ size_t nchr;
+ wchar_t wc;
+ size_t nb;
+
+ s = *src;
+ nchr = 0;
+
+ if (dst == NULL) {
+ for (;;) {
+ if ((nb = __mbrtowc(&wc, s, nms, ps)) == (size_t)-1)
+ /* Invalid sequence - mbrtowc() sets errno. */
+ return ((size_t)-1);
+ else if (nb == 0 || nb == (size_t)-2)
+ return (nchr);
+ s += nb;
+ nms -= nb;
+ nchr++;
+ }
+ /*NOTREACHED*/
+ }
+
+ while (len-- > 0) {
+ if ((nb = __mbrtowc(dst, s, nms, ps)) == (size_t)-1) {
+ *src = s;
+ return ((size_t)-1);
+ } else if (nb == (size_t)-2) {
+ *src = s + nms;
+ return (nchr);
+ } else if (nb == 0) {
+ *src = NULL;
+ return (nchr);
+ }
+ s += nb;
+ nms -= nb;
+ nchr++;
+ dst++;
+ }
+ *src = s;
+ return (nchr);
+}
--- /dev/null
+--- mbsnrtowcs.c.orig Thu Nov 25 11:38:18 2004
++++ mbsnrtowcs.c Fri Feb 18 16:57:14 2005
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/mbsnrtowcs.c,v 1.1 2004/07/21 10:54:57 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <errno.h>
+ #include <limits.h>
+ #include <stdlib.h>
+@@ -34,31 +36,40 @@
+ #include "mblocal.h"
+
+ size_t
+-mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src,
+- size_t nms, size_t len, mbstate_t * __restrict ps)
++mbsnrtowcs_l(wchar_t * __restrict dst, const char ** __restrict src,
++ size_t nms, size_t len, mbstate_t * __restrict ps, locale_t loc)
+ {
+- static mbstate_t mbs;
+-
++ NORMALIZE_LOCALE(loc);
+ if (ps == NULL)
+- ps = &mbs;
+- return (__mbsnrtowcs(dst, src, nms, len, ps));
++ ps = &loc->__mbs_mbsnrtowcs;
++ return (loc->__lc_ctype->__mbsnrtowcs(dst, src, nms, len, ps, loc));
+ }
+
+ size_t
+-__mbsnrtowcs_std(wchar_t * __restrict dst, const char ** __restrict src,
++mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src,
+ size_t nms, size_t len, mbstate_t * __restrict ps)
+ {
++ return mbsnrtowcs_l(dst, src, nms, len, ps, __current_locale());
++}
++
++__private_extern__ size_t
++__mbsnrtowcs_std(wchar_t * __restrict dst, const char ** __restrict src,
++ size_t nms, size_t len, mbstate_t * __restrict ps, locale_t loc)
++{
+ const char *s;
+ size_t nchr;
+ wchar_t wc;
+ size_t nb;
++ size_t (*__mbrtowc)(wchar_t * __restrict, const char * __restrict,
++ size_t, mbstate_t * __restrict, locale_t)
++ = loc->__lc_ctype->__mbrtowc;
+
+ s = *src;
+ nchr = 0;
+
+ if (dst == NULL) {
+ for (;;) {
+- if ((nb = __mbrtowc(&wc, s, nms, ps)) == (size_t)-1)
++ if ((nb = __mbrtowc(&wc, s, nms, ps, loc)) == (size_t)-1)
+ /* Invalid sequence - mbrtowc() sets errno. */
+ return ((size_t)-1);
+ else if (nb == 0 || nb == (size_t)-2)
+@@ -71,7 +82,7 @@
+ }
+
+ while (len-- > 0) {
+- if ((nb = __mbrtowc(dst, s, nms, ps)) == (size_t)-1) {
++ if ((nb = __mbrtowc(dst, s, nms, ps, loc)) == (size_t)-1) {
+ *src = s;
+ return ((size_t)-1);
+ } else if (nb == (size_t)-2) {
-.\" Copyright (c) 2002 Tim J. Robbins
+.\" Copyright (c) 2002-2004 Tim J. Robbins
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/lib/libc/locale/mbsrtowcs.3,v 1.3 2002/11/29 17:35:09 ru Exp $
-.Dd August 16, 2002
+.\" $FreeBSD: src/lib/libc/locale/mbsrtowcs.3,v 1.5 2004/07/21 10:54:57 tjr Exp $
+.Dd July 21, 2004
.Dt MBSRTOWCS 3
.Os
.Sh NAME
-.Nm mbsrtowcs
+.Nm mbsrtowcs ,
+.Nm mbsnrtowcs
.Nd "convert a character string to a wide-character string (restartable)"
.Sh LIBRARY
.Lb libc
.Fa "wchar_t * restrict dst" "const char ** restrict src" "size_t len"
.Fa "mbstate_t * restrict ps"
.Fc
+.Ft size_t
+.Fo mbsnrtowcs
+.Fa "wchar_t * restrict dst" "const char ** restrict src" "size_t nms"
+.Fa "size_t len" "mbstate_t * restrict ps"
+.Fc
.Sh DESCRIPTION
The
.Fn mbsrtowcs
.Fn mbsrtowcs
uses an internal, static
.Vt mbstate_t
-object.
+object, which is initialized to the initial conversion state
+at program startup.
+.Pp
+The
+.Fn mbsnrtowcs
+function behaves identically to
+.Fn mbsrtowcs ,
+except that conversion stops after reading at most
+.Fa nms
+bytes from the buffer pointed to by
+.Fa src .
.Sh RETURN VALUES
The
.Fn mbsrtowcs
-function returns the number of wide characters stored in
+and
+.Fn mbsnrtowcs
+functions return the number of wide characters stored in
the array pointed to by
.Fa dst
if successful, otherwise it returns
.Sh ERRORS
The
.Fn mbsrtowcs
-function will fail if:
+and
+.Fn mbsnrtowcs
+functions will fail if:
.Bl -tag -width Er
.It Bq Er EILSEQ
An invalid multibyte character sequence was encountered.
+.It Bq Er EINVAL
+The conversion state is invalid.
.El
.Sh SEE ALSO
.Xr mbrtowc 3 ,
.Xr mbstowcs 3 ,
+.Xr multibyte 3 ,
.Xr wcsrtombs 3
.Sh STANDARDS
The
.Fn mbsrtowcs
function conforms to
.St -isoC-99 .
-.Sh BUGS
-The current implementation does not support shift states.
+.Pp
+The
+.Fn mbsnrtowcs
+function is an extension to the standard.
--- /dev/null
+--- mbsrtowcs.3.orig Fri Mar 11 18:09:42 2005
++++ mbsrtowcs.3 Fri Mar 11 18:11:17 2005
+@@ -28,7 +28,9 @@
+ .Os
+ .Sh NAME
+ .Nm mbsrtowcs ,
+-.Nm mbsnrtowcs
++.Nm mbsnrtowcs ,
++.Nm mbsrtowcs_l ,
++.Nm mbsnrtowcs_l
+ .Nd "convert a character string to a wide-character string (restartable)"
+ .Sh LIBRARY
+ .Lb libc
+@@ -44,6 +46,17 @@
+ .Fa "wchar_t * restrict dst" "const char ** restrict src" "size_t nms"
+ .Fa "size_t len" "mbstate_t * restrict ps"
+ .Fc
++.In xlocale.h
++.Ft size_t
++.Fo mbsrtowcs_l
++.Fa "wchar_t * restrict dst" "const char ** restrict src" "size_t len"
++.Fa "mbstate_t * restrict ps" "locale_t loc"
++.Fc
++.Ft size_t
++.Fo mbsnrtowcs_l
++.Fa "wchar_t * restrict dst" "const char ** restrict src" "size_t nms"
++.Fa "size_t len" "mbstate_t * restrict ps" "locale_t loc"
++.Fc
+ .Sh DESCRIPTION
+ The
+ .Fn mbsrtowcs
+@@ -97,6 +110,18 @@
+ .Fa nms
+ bytes from the buffer pointed to by
+ .Fa src .
++.Pp
++While the
++.Fn mbsrtowcs
++and
++.Fn mbsnrtowcs
++functions use the current locale, the
++.Fn mbsrtowcs_l
++and
++.Fn mbsnrtowcs_l
++functions may be passed locales directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn mbsrtowcs
+@@ -123,7 +148,8 @@
+ .Xr mbrtowc 3 ,
+ .Xr mbstowcs 3 ,
+ .Xr multibyte 3 ,
+-.Xr wcsrtombs 3
++.Xr wcsrtombs 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn mbsrtowcs
/*-
- * Copyright (c) 2002 Tim J. Robbins.
+ * Copyright (c) 2002-2004 Tim J. Robbins.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/mbsrtowcs.c,v 1.2 2002/09/06 11:23:45 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/mbsrtowcs.c,v 1.6 2004/07/21 10:54:57 tjr Exp $");
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <wchar.h>
+#include "mblocal.h"
size_t
mbsrtowcs(wchar_t * __restrict dst, const char ** __restrict src, size_t len,
- mbstate_t * __restrict ps __unused)
+ mbstate_t * __restrict ps)
{
- const char *s;
- size_t nchr;
- wchar_t wc;
- int nb;
+ static mbstate_t mbs;
- s = *src;
- nchr = 0;
-
- if (dst == NULL) {
- for (;;) {
- if ((nb = (int)mbrtowc(&wc, s, MB_CUR_MAX, NULL)) < 0)
- /* Invalid sequence - mbrtowc() sets errno. */
- return ((size_t)-1);
- else if (nb == 0)
- return (nchr);
- s += nb;
- nchr++;
- }
- /*NOTREACHED*/
- }
-
- while (len-- > 0) {
- if ((nb = (int)mbrtowc(dst, s, MB_CUR_MAX, NULL)) < 0) {
- *src = s;
- return ((size_t)-1);
- } else if (nb == 0) {
- *src = NULL;
- return (nchr);
- }
- s += nb;
- nchr++;
- dst++;
- }
- *src = s;
- return (nchr);
+ if (ps == NULL)
+ ps = &mbs;
+ return (__mbsnrtowcs(dst, src, SIZE_T_MAX, len, ps));
}
--- /dev/null
+--- mbsrtowcs.c.orig 2004-11-25 11:38:18.000000000 -0800
++++ mbsrtowcs.c 2005-02-18 18:28:00.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/mbsrtowcs.c,v 1.6 2004/07/21 10:54:57 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <errno.h>
+ #include <limits.h>
+ #include <stdlib.h>
+@@ -34,12 +36,18 @@
+ #include "mblocal.h"
+
+ size_t
++mbsrtowcs_l(wchar_t * __restrict dst, const char ** __restrict src, size_t len,
++ mbstate_t * __restrict ps, locale_t loc)
++{
++ NORMALIZE_LOCALE(loc);
++ if (ps == NULL)
++ ps = &loc->__mbs_mbsrtowcs;
++ return (loc->__lc_ctype->__mbsnrtowcs(dst, src, SIZE_T_MAX, len, ps, loc));
++}
++
++size_t
+ mbsrtowcs(wchar_t * __restrict dst, const char ** __restrict src, size_t len,
+ mbstate_t * __restrict ps)
+ {
+- static mbstate_t mbs;
+-
+- if (ps == NULL)
+- ps = &mbs;
+- return (__mbsnrtowcs(dst, src, SIZE_T_MAX, len, ps));
++ return mbsrtowcs_l(dst, src, len, ps, __current_locale());
+ }
--- /dev/null
+.\" Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved.
+.\" Copyright (c) 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Donn Seeley of BSDI.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" From @(#)multibyte.3 8.1 (Berkeley) 6/4/93
+.\" From FreeBSD: src/lib/libc/locale/multibyte.3,v 1.22 2003/11/08 03:23:11 tjr Exp
+.\" $FreeBSD: src/lib/libc/locale/mbstowcs.3,v 1.4 2004/07/05 06:36:36 ru Exp $
+.\"
+.Dd April 8, 2004
+.Dt MBSTOWCS 3
+.Os
+.Sh NAME
+.Nm mbstowcs
+.Nd convert a character string to a wide-character string
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdlib.h
+.Ft size_t
+.Fo mbstowcs
+.Fa "wchar_t * restrict wcstring" "const char * restrict mbstring"
+.Fa "size_t nwchars"
+.Fc
+.Sh DESCRIPTION
+The
+.Fn mbstowcs
+function converts a multibyte character string
+.Fa mbstring
+beginning in the initial conversion state
+into a wide character string
+.Fa wcstring .
+No more than
+.Fa nwchars
+wide characters are stored.
+A terminating null wide character is appended if there is room.
+.Sh RETURN VALUES
+The
+.Fn mbstowcs
+function returns the number of wide characters converted,
+not counting any terminating null wide character, or \-1
+if an invalid multibyte character was encountered.
+.Sh ERRORS
+The
+.Fn mbstowcs
+function will fail if:
+.Bl -tag -width Er
+.It Bq Er EILSEQ
+An invalid multibyte sequence was detected.
+.It Bq Er EINVAL
+The conversion state is invalid.
+.El
+.Sh SEE ALSO
+.Xr mbsrtowcs 3 ,
+.Xr mbtowc 3 ,
+.Xr multibyte 3
+.Sh STANDARDS
+The
+.Fn mbstowcs
+function conforms to
+.St -isoC-99 .
--- /dev/null
+--- mbstowcs.3.orig Fri Mar 11 19:44:47 2005
++++ mbstowcs.3 Fri Mar 11 20:01:09 2005
+@@ -41,7 +41,8 @@
+ .Dt MBSTOWCS 3
+ .Os
+ .Sh NAME
+-.Nm mbstowcs
++.Nm mbstowcs ,
++.Nm mbstowcs_l
+ .Nd convert a character string to a wide-character string
+ .Sh LIBRARY
+ .Lb libc
+@@ -52,6 +53,12 @@
+ .Fa "wchar_t * restrict wcstring" "const char * restrict mbstring"
+ .Fa "size_t nwchars"
+ .Fc
++.In xlocale.h
++.Ft size_t
++.Fo mbstowcs_l
++.Fa "wchar_t * restrict wcstring" "const char * restrict mbstring"
++.Fa "size_t nwchars" "locale_t loc"
++.Fc
+ .Sh DESCRIPTION
+ The
+ .Fn mbstowcs
+@@ -64,6 +71,14 @@
+ .Fa nwchars
+ wide characters are stored.
+ A terminating null wide character is appended if there is room.
++.Pp
++While the
++.Fn mbstowcs
++function uses the current locale, the
++.Fn mbstowcs_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn mbstowcs
+@@ -83,7 +98,8 @@
+ .Sh SEE ALSO
+ .Xr mbsrtowcs 3 ,
+ .Xr mbtowc 3 ,
+-.Xr multibyte 3
++.Xr multibyte 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn mbstowcs
/*-
- * Copyright (c) 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Paul Borman at Krystal Technologies.
+ * Copyright (c) 2002-2004 Tim J. Robbins.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * 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 REGENTS OR CONTRIBUTORS BE LIABLE
+ * 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)
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/mbstowcs.c,v 1.6 2002/11/09 04:13:26 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/mbstowcs.c,v 1.11 2004/07/21 10:54:57 tjr Exp $");
-#include <errno.h>
-#include <stdlib.h>
#include <limits.h>
-#include <stddef.h>
-#include <rune.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include "mblocal.h"
size_t
mbstowcs(wchar_t * __restrict pwcs, const char * __restrict s, size_t n)
{
- const char *e;
- int cnt;
- rune_t r;
-
- if (s == NULL) {
- errno = EINVAL;
- return (-1);
- }
-
- if (pwcs == NULL) {
- /* Convert and count only, do not store. */
- cnt = 0;
- while ((r = sgetrune(s, MB_LEN_MAX, &e)) != _INVALID_RUNE &&
- r != 0) {
- s = e;
- cnt++;
- }
- if (r == _INVALID_RUNE) {
- errno = EILSEQ;
- return (-1);
- }
- return (cnt);
- }
-
- /* Convert, store and count characters. */
- cnt = 0;
- while (n-- > 0) {
- *pwcs = sgetrune(s, MB_LEN_MAX, &e);
- if (*pwcs == _INVALID_RUNE) {
- errno = EILSEQ;
- return (-1);
- }
- if (*pwcs++ == L'\0')
- break;
- s = e;
- ++cnt;
- }
+ static const mbstate_t initial;
+ mbstate_t mbs;
- return (cnt);
+ mbs = initial;
+ return (__mbsnrtowcs(pwcs, &s, SIZE_T_MAX, n, &mbs));
}
--- /dev/null
+--- mbstowcs.c.orig Thu Nov 25 11:38:18 2004
++++ mbstowcs.c Fri Feb 18 17:02:15 2005
+@@ -27,17 +27,27 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/mbstowcs.c,v 1.11 2004/07/21 10:54:57 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <limits.h>
+ #include <stdlib.h>
+ #include <wchar.h>
+ #include "mblocal.h"
+
+ size_t
+-mbstowcs(wchar_t * __restrict pwcs, const char * __restrict s, size_t n)
++mbstowcs_l(wchar_t * __restrict pwcs, const char * __restrict s, size_t n,
++ locale_t loc)
+ {
+ static const mbstate_t initial;
+ mbstate_t mbs;
+
++ NORMALIZE_LOCALE(loc);
+ mbs = initial;
+- return (__mbsnrtowcs(pwcs, &s, SIZE_T_MAX, n, &mbs));
++ return (loc->__lc_ctype->__mbsnrtowcs(pwcs, &s, SIZE_T_MAX, n, &mbs, loc));
++}
++
++size_t
++mbstowcs(wchar_t * __restrict pwcs, const char * __restrict s, size_t n)
++{
++ return mbstowcs_l(pwcs, s, n, __current_locale());
+ }
--- /dev/null
+.\" Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved.
+.\" Copyright (c) 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Donn Seeley of BSDI.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" From @(#)multibyte.3 8.1 (Berkeley) 6/4/93
+.\" From FreeBSD: src/lib/libc/locale/multibyte.3,v 1.22 2003/11/08 03:23:11 tjr Exp
+.\" $FreeBSD: src/lib/libc/locale/mbtowc.3,v 1.4 2004/07/05 06:36:36 ru Exp $
+.\"
+.Dd April 11, 2004
+.Dt MBTOWC 3
+.Os
+.Sh NAME
+.Nm mbtowc
+.Nd convert a character to a wide-character code
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdlib.h
+.Ft int
+.Fo mbtowc
+.Fa "wchar_t * restrict wcharp" "const char * restrict mbchar"
+.Fa "size_t nbytes"
+.Fc
+.Sh DESCRIPTION
+The
+.Fn mbtowc
+function converts a multibyte character
+.Fa mbchar
+into a wide character according to the current conversion state,
+and stores the result
+in the object pointed to by
+.Fa wcharp .
+Up to
+.Fa nbytes
+bytes are examined.
+.Pp
+A call with a null
+.Fa mbchar
+pointer returns nonzero if the current encoding requires shift states,
+zero otherwise;
+if shift states are required, the shift state is reset to the initial state.
+.Sh RETURN VALUES
+If
+.Fa mbchar
+is
+.Dv NULL ,
+the
+.Fn mbtowc
+function returns nonzero if shift states are supported,
+zero otherwise.
+.Pp
+Otherwise, if
+.Fa mbchar
+is not a null pointer,
+.Fn mbtowc
+either returns 0 if
+.Fa mbchar
+represents the null wide character, or returns
+the number of bytes processed in
+.Fa mbchar ,
+or returns \-1 if no multibyte character
+could be recognized or converted.
+In this case,
+.Fn mbtowc Ns 's
+internal conversion state is undefined.
+.Sh ERRORS
+The
+.Fn mbtowc
+function will fail if:
+.Bl -tag -width Er
+.It Bq Er EILSEQ
+An invalid multibyte sequence was detected.
+.It Bq Er EINVAL
+The internal conversion state is invalid.
+.El
+.Sh SEE ALSO
+.Xr btowc 3 ,
+.Xr mblen 3 ,
+.Xr mbrtowc 3 ,
+.Xr mbstowcs 3 ,
+.Xr multibyte 3 ,
+.Xr wctomb 3
+.Sh STANDARDS
+The
+.Fn mbtowc
+function conforms to
+.St -isoC-99 .
--- /dev/null
+--- mbtowc.3.orig Fri Mar 11 19:44:47 2005
++++ mbtowc.3 Fri Mar 11 19:54:09 2005
+@@ -41,7 +41,8 @@
+ .Dt MBTOWC 3
+ .Os
+ .Sh NAME
+-.Nm mbtowc
++.Nm mbtowc ,
++.Nm mbtowc_l
+ .Nd convert a character to a wide-character code
+ .Sh LIBRARY
+ .Lb libc
+@@ -52,6 +53,12 @@
+ .Fa "wchar_t * restrict wcharp" "const char * restrict mbchar"
+ .Fa "size_t nbytes"
+ .Fc
++.In xlocale.h
++.Ft int
++.Fo mbtowc_l
++.Fa "wchar_t * restrict wcharp" "const char * restrict mbchar"
++.Fa "size_t nbytes" "locale_t loc"
++.Fc
+ .Sh DESCRIPTION
+ The
+ .Fn mbtowc
+@@ -70,6 +77,14 @@
+ pointer returns nonzero if the current encoding requires shift states,
+ zero otherwise;
+ if shift states are required, the shift state is reset to the initial state.
++.Pp
++While the
++.Fn mbtowc
++function uses the current locale, the
++.Fn mbtowc_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ If
+ .Fa mbchar
+@@ -110,7 +125,8 @@
+ .Xr mbrtowc 3 ,
+ .Xr mbstowcs 3 ,
+ .Xr multibyte 3 ,
+-.Xr wctomb 3
++.Xr wctomb 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn mbtowc
/*-
- * Copyright (c) 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Paul Borman at Krystal Technologies.
+ * Copyright (c) 2002-2004 Tim J. Robbins.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * 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 REGENTS OR CONTRIBUTORS BE LIABLE
+ * 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)
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/mbtowc.c,v 1.6 2002/10/28 08:24:46 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/mbtowc.c,v 1.11 2004/07/29 06:18:40 tjr Exp $");
-#include <errno.h>
#include <stdlib.h>
-#include <stddef.h>
-#include <rune.h>
+#include <wchar.h>
+#include "mblocal.h"
int
mbtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n)
{
- const char *e;
- rune_t r;
+ static const mbstate_t initial;
+ static mbstate_t mbs;
+ size_t rval;
- if (s == NULL)
+ if (s == NULL) {
/* No support for state dependent encodings. */
- return (0);
- if ((r = sgetrune(s, n, &e)) == _INVALID_RUNE) {
- errno = EILSEQ;
- return (-1);
+ mbs = initial;
+ return (0);
}
- if (pwc != NULL)
- *pwc = r;
- return (r == 0 ? 0 : e - s);
+ rval = __mbrtowc(pwc, s, n, &mbs);
+ if (rval == (size_t)-1 || rval == (size_t)-2)
+ return (-1);
+ return ((int)rval);
}
--- /dev/null
+--- mbtowc.c.orig Thu Nov 25 11:38:18 2004
++++ mbtowc.c Fri Feb 18 17:12:35 2005
+@@ -27,24 +27,33 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/mbtowc.c,v 1.11 2004/07/29 06:18:40 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdlib.h>
+ #include <wchar.h>
+ #include "mblocal.h"
+
+ int
+-mbtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n)
++mbtowc_l(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
++ locale_t loc)
+ {
+ static const mbstate_t initial;
+- static mbstate_t mbs;
+ size_t rval;
+
++ NORMALIZE_LOCALE(loc);
+ if (s == NULL) {
+ /* No support for state dependent encodings. */
+- mbs = initial;
++ loc->__mbs_mbtowc = initial;
+ return (0);
+ }
+- rval = __mbrtowc(pwc, s, n, &mbs);
++ rval = loc->__lc_ctype->__mbrtowc(pwc, s, n, &loc->__mbs_mbtowc, loc);
+ if (rval == (size_t)-1 || rval == (size_t)-2)
+ return (-1);
+ return ((int)rval);
++}
++
++int
++mbtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n)
++{
++ return mbtowc_l(pwc, s, n, __current_locale());
+ }
--- /dev/null
+.\" Copyright (c) 2002, 2003 Tim J. Robbins
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/locale/mskanji.5,v 1.4 2004/07/05 06:36:36 ru Exp $
+.\"
+.Dd August 7, 2003
+.Dt MSKANJI 5
+.Os
+.Sh NAME
+.Nm mskanji
+.Nd "Shift-JIS (MS Kanji) encoding for Japanese text"
+.Sh SYNOPSIS
+.Nm ENCODING
+.Qq MSKanji
+.Sh DESCRIPTION
+Shift-JIS, also known as MS Kanji or SJIS, is an encoding system for
+Japanese characters, developed by Microsoft Corporation.
+It encodes the characters from the
+.Tn JIS
+X 0201 (ASCII/JIS-Roman) and
+.Tn JIS
+X 0208 (Japanese) character sets as sequences of either one or two bytes.
+.Pp
+Characters from the
+.Tn ASCII Ns
+/JIS-Roman character set are encoded as single bytes between 0x00 and 0x7F
+(ASCII) or 0xA1 and 0xDF (Half-width katakana).
+.Pp
+Characters from the
+.Tn JIS
+X 0208 character set are encoded as two bytes.
+The first ranges from
+0x81 - 0x9F, 0xE0 - 0xEA, 0xED - 0xEE (not
+.Tn JIS :
+.Tn NEC Ns - Ns
+selected
+.Tn IBM
+extended characters),
+0xF0 - 0xF9 (not
+.Tn JIS :
+user defined),
+or 0xFA - 0xFC (not
+.Tn JIS :
+.Tn IBM
+extended characters).
+The second byte ranges from 0x40 - 0xFC, excluding 0x7F (delete).
+.Sh SEE ALSO
+.Xr euc 5 ,
+.Xr utf8 5
/*
+ * Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved.
+ *
* ja_JP.SJIS locale table for BSD4.4/rune
* version 1.0
* (C) Sin'ichiro MIYATANI / Phase One, Inc
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)mskanji.c 1.0 (Phase One) 5/5/95";
#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/mskanji.c,v 1.8 2002/10/14 01:50:45 tjr Exp $");
-
-#include <sys/types.h>
+#include <sys/param.h>
+__FBSDID("$FreeBSD: src/lib/libc/locale/mskanji.c,v 1.16 2004/05/14 15:40:47 tjr Exp $");
-#include <rune.h>
-#include <stddef.h>
-#include <stdio.h>
+#include <errno.h>
+#include <runetype.h>
#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include "mblocal.h"
+
+int _MSKanji_init(_RuneLocale *);
+size_t _MSKanji_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
+ mbstate_t * __restrict);
+int _MSKanji_mbsinit(const mbstate_t *);
+size_t _MSKanji_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
-rune_t _MSKanji_sgetrune(const char *, size_t, char const **);
-int _MSKanji_sputrune(rune_t, char *, size_t, char **);
+typedef struct {
+ wchar_t ch;
+} _MSKanjiState;
int
-_MSKanji_init(rl)
- _RuneLocale *rl;
+_MSKanji_init(_RuneLocale *rl)
{
- rl->sgetrune = _MSKanji_sgetrune;
- rl->sputrune = _MSKanji_sputrune;
+ __mbrtowc = _MSKanji_mbrtowc;
+ __wcrtomb = _MSKanji_wcrtomb;
+ __mbsinit = _MSKanji_mbsinit;
_CurrentRuneLocale = rl;
__mb_cur_max = 2;
return (0);
}
-rune_t
-_MSKanji_sgetrune(string, n, result)
- const char *string;
- size_t n;
- char const **result;
+int
+_MSKanji_mbsinit(const mbstate_t *ps)
{
- rune_t rune = 0;
- if (n < 1) {
- if (result != NULL)
- *result = string;
- return (_INVALID_RUNE);
+ return (ps == NULL || ((const _MSKanjiState *)ps)->ch == 0);
+}
+
+size_t
+_MSKanji_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
+ mbstate_t * __restrict ps)
+{
+ _MSKanjiState *ms;
+ wchar_t wc;
+
+ ms = (_MSKanjiState *)ps;
+
+ if ((ms->ch & ~0xFF) != 0) {
+ /* Bad conversion state. */
+ errno = EINVAL;
+ return ((size_t)-1);
}
- rune = *string++ & 0xff;
- if ((rune > 0x80 && rune < 0xa0) ||
- (rune >= 0xe0 && rune < 0xfd)) {
- if (n < 2) {
- rune = _INVALID_RUNE;
- --string;
- } else
- rune = (rune << 8) | (*string++ & 0xff);
+ if (s == NULL) {
+ s = "";
+ n = 1;
+ pwc = NULL;
}
- if (result != NULL)
- *result = string;
- return (rune);
+ if (n == 0)
+ /* Incomplete multibyte sequence */
+ return ((size_t)-2);
+
+ if (ms->ch != 0) {
+ if (*s == '\0') {
+ errno = EILSEQ;
+ return ((size_t)-1);
+ }
+ wc = (ms->ch << 8) | (*s & 0xFF);
+ if (pwc != NULL)
+ *pwc = wc;
+ ms->ch = 0;
+ return (1);
+ }
+ wc = *s++ & 0xff;
+ if ((wc > 0x80 && wc < 0xa0) || (wc >= 0xe0 && wc < 0xfd)) {
+ if (n < 2) {
+ /* Incomplete multibyte sequence */
+ ms->ch = wc;
+ return ((size_t)-2);
+ }
+ if (*s == '\0') {
+ errno = EILSEQ;
+ return ((size_t)-1);
+ }
+ wc = (wc << 8) | (*s++ & 0xff);
+ if (pwc != NULL)
+ *pwc = wc;
+ return (2);
+ } else {
+ if (pwc != NULL)
+ *pwc = wc;
+ return (wc == L'\0' ? 0 : 1);
+ }
}
-int
-_MSKanji_sputrune(c, string, n, result)
- rune_t c;
- char *string, **result;
- size_t n;
+size_t
+_MSKanji_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
{
+ _MSKanjiState *ms;
int len, i;
- len = (c > 0x100) ? 2 : 1;
- if (n < len) {
- if (result != NULL)
- *result = NULL;
- } else {
- if (result != NULL)
- *result = string + len;
- for (i = len; i-- > 0; )
- *string++ = c >> (i << 3);
+ ms = (_MSKanjiState *)ps;
+
+ if (ms->ch != 0) {
+ errno = EINVAL;
+ return ((size_t)-1);
}
+ if (s == NULL)
+ /* Reset to initial shift state (no-op) */
+ return (1);
+ len = (wc > 0x100) ? 2 : 1;
+ for (i = len; i-- > 0; )
+ *s++ = wc >> (i << 3);
return (len);
}
---- mskanji.c.orig Tue May 20 15:21:44 2003
-+++ mskanji.c Wed Jun 18 12:02:06 2003
-@@ -43,6 +43,7 @@
- #include <stddef.h>
- #include <stdio.h>
+--- mskanji.c.orig Thu Nov 25 11:38:18 2004
++++ mskanji.c Fri Feb 18 15:49:37 2005
+@@ -36,9 +36,12 @@
+ #if defined(LIBC_SCCS) && !defined(lint)
+ static char sccsid[] = "@(#)mskanji.c 1.0 (Phase One) 5/5/95";
+ #endif /* LIBC_SCCS and not lint */
+-#include <sys/param.h>
++#include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/mskanji.c,v 1.16 2004/05/14 15:40:47 tjr Exp $");
+
++#include "xlocale_private.h"
++
++#include <sys/param.h>
+ #include <errno.h>
+ #include <runetype.h>
#include <stdlib.h>
-+#include <ctype.h>
+@@ -46,38 +49,37 @@
+ #include <wchar.h>
+ #include "mblocal.h"
+
+-int _MSKanji_init(_RuneLocale *);
+-size_t _MSKanji_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
+- mbstate_t * __restrict);
+-int _MSKanji_mbsinit(const mbstate_t *);
+-size_t _MSKanji_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
++__private_extern__ int _MSKanji_init(struct __xlocale_st_runelocale *);
++static size_t _MSKanji_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
++ mbstate_t * __restrict, locale_t);
++static int _MSKanji_mbsinit(const mbstate_t *, locale_t);
++static size_t _MSKanji_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict, locale_t);
+
+ typedef struct {
+ wchar_t ch;
+ } _MSKanjiState;
+
+-int
+-_MSKanji_init(_RuneLocale *rl)
++__private_extern__ int
++_MSKanji_init(struct __xlocale_st_runelocale *xrl)
+ {
+
+- __mbrtowc = _MSKanji_mbrtowc;
+- __wcrtomb = _MSKanji_wcrtomb;
+- __mbsinit = _MSKanji_mbsinit;
+- _CurrentRuneLocale = rl;
+- __mb_cur_max = 2;
++ xrl->__mbrtowc = _MSKanji_mbrtowc;
++ xrl->__wcrtomb = _MSKanji_wcrtomb;
++ xrl->__mbsinit = _MSKanji_mbsinit;
++ xrl->__mb_cur_max = 2;
+ return (0);
+ }
- rune_t _MSKanji_sgetrune(const char *, size_t, char const **);
- int _MSKanji_sputrune(rune_t, char *, size_t, char **);
-@@ -67,20 +68,23 @@
+-int
+-_MSKanji_mbsinit(const mbstate_t *ps)
++static int
++_MSKanji_mbsinit(const mbstate_t *ps, locale_t loc)
{
- rune_t rune = 0;
-
-- if (n < 1) {
-- if (result != NULL)
-- *result = string;
-+ if (result != NULL)
-+ *result = string;
-+ if (n < 1)
- return (_INVALID_RUNE);
-- }
-
- rune = *string++ & 0xff;
- if ((rune > 0x80 && rune < 0xa0) ||
- (rune >= 0xe0 && rune < 0xfd)) {
-- if (n < 2) {
-- rune = _INVALID_RUNE;
-- --string;
-- } else
-+ if (n < 2)
-+ return (_INVALID_RUNE);
-+ else
- rune = (rune << 8) | (*string++ & 0xff);
-+ }
-+ if (!isrune(rune)) {
-+ if (result != NULL)
-+ (*result)++;
-+ return (_INVALID_RUNE);
+
+ return (ps == NULL || ((const _MSKanjiState *)ps)->ch == 0);
+ }
+
+-size_t
++static size_t
+ _MSKanji_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
+- mbstate_t * __restrict ps)
++ mbstate_t * __restrict ps, locale_t loc)
+ {
+ _MSKanjiState *ms;
+ wchar_t wc;
+@@ -133,8 +135,8 @@
}
- if (result != NULL)
- *result = string;
+ }
+
+-size_t
+-_MSKanji_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
++static size_t
++_MSKanji_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps, locale_t loc)
+ {
+ _MSKanjiState *ms;
+ int len, i;
+.\" Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved.
.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" SUCH DAMAGE.
.\"
.\" @(#)multibyte.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/locale/multibyte.3,v 1.19 2003/02/06 11:04:46 charnier Exp $
+.\" $FreeBSD: src/lib/libc/locale/multibyte.3,v 1.27 2004/10/17 02:29:15 tjr Exp $
.\"
-.Dd October 6, 2002
+.Dd April 8, 2004
.Dt MULTIBYTE 3
.Os
.Sh NAME
-.Nm mblen ,
-.Nm mbstowcs ,
-.Nm mbtowc ,
-.Nm wcstombs ,
-.Nm wctomb
-.Nd multibyte character support for C
+.Nm multibyte
+.Nd multibyte and wide character manipulation functions
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
+.In limits.h
.In stdlib.h
-.Ft int
-.Fn mblen "const char *mbchar" "size_t nbytes"
-.Ft size_t
-.Fn mbstowcs "wchar_t * restrict wcstring" "const char * restrict mbstring" "size_t nwchars"
-.Ft int
-.Fn mbtowc "wchar_t * restrict wcharp" "const char * restrict mbchar" "size_t nbytes"
-.Ft size_t
-.Fn wcstombs "char * restrict mbstring" "const wchar_t * restrict wcstring" "size_t nbytes"
-.Ft int
-.Fn wctomb "char *mbchar" "wchar_t wchar"
+.In wchar.h
.Sh DESCRIPTION
-The basic elements of some written natural languages such as Chinese
+The basic elements of some written natural languages, such as Chinese,
cannot be represented uniquely with single C
-.Va char Ns s .
+.Vt char Ns s .
The C standard supports two different ways of dealing with
-extended natural language encodings,
-.Em wide
-characters and
-.Em multibyte
-characters.
+extended natural language encodings:
+wide characters and
+multibyte characters.
Wide characters are an internal representation
which allows each basic element to map
to a single object of type
-.Va wchar_t .
+.Vt wchar_t .
Multibyte characters are used for input and output
and code each basic element as a sequence of C
-.Va char Ns s .
+.Vt char Ns s .
Individual basic elements may map into one or more
(up to
.Dv MB_LEN_MAX )
.Dv LC_CTYPE
specifically controls this interpretation.
The
-.Va wchar_t
+.Vt wchar_t
type is wide enough to hold the largest value
in the wide character representations for all locales.
.Pp
There is always a distinguished
.Sq initial
shift state.
-The
-.Fn mbstowcs
-and
-.Fn wcstombs
-functions assume that multibyte strings are interpreted
-starting from the initial shift state.
-The
-.Fn mblen ,
-.Fn mbtowc
+Some functions (e.g.,
+.Xr mblen 3 ,
+.Xr mbtowc 3
and
-.Fn wctomb
-functions maintain static shift state internally.
-A call with a null
-.Fa mbchar
-pointer returns nonzero if the current locale requires shift states,
-zero otherwise;
-if shift states are required, the shift state is reset to the initial state.
-The internal shift states are undefined after a call to
-.Fn setlocale
+.Xr wctomb 3 )
+maintain static shift state internally, whereas
+others store it in an
+.Vt mbstate_t
+object passed by the caller.
+Shift states are undefined after a call to
+.Xr setlocale 3
with the
.Dv LC_CTYPE
or
is recognized as the multibyte character string terminator.
Null bytes are not permitted within multibyte characters.
.Pp
-The
-.Fn mblen
-function computes the length in bytes
-of a multibyte character
-.Fa mbchar .
-Up to
-.Fa nbytes
-bytes are examined.
-.Pp
-The
-.Fn mbtowc
-function converts a multibyte character
-.Fa mbchar
-into a wide character and stores the result
-in the object pointed to by
-.Fa wcharp .
-Up to
-.Fa nbytes
-bytes are examined.
-.Pp
-The
-.Fn wctomb
-function converts a wide character
-.Fa wchar
-into a multibyte character and stores
-the result in
-.Fa mbchar .
-The object pointed to by
-.Fa mbchar
-must be large enough to accommodate the multibyte character.
-.Pp
-The
-.Fn mbstowcs
-function converts a multibyte character string
-.Fa mbstring
-into a wide character string
-.Fa wcstring .
-No more than
-.Fa nwchars
-wide characters are stored.
-A terminating null wide character is appended if there is room.
-.Pp
-The
-.Fn wcstombs
-function converts a wide character string
-.Fa wcstring
-into a multibyte character string
-.Fa mbstring .
-Up to
-.Fa nbytes
-bytes are stored in
-.Fa mbstring .
-Partial multibyte characters at the end of the string are not stored.
-The multibyte character string is null terminated if there is room.
-.Sh "RETURN VALUES
-If
-.Fa mbchar
-is
-.Dv NULL ,
-the
-.Fn mblen ,
-.Fn mbtowc
-and
-.Fn wctomb
-functions return nonzero if shift states are supported,
-zero otherwise.
-If
-.Fa mbchar
-is valid,
-then these functions return
-the number of bytes processed in
-.Fa mbchar ,
-or \-1 if no multibyte character
-could be recognized or converted.
-.Pp
-The
-.Fn mbstowcs
-function returns the number of wide characters converted,
-not counting any terminating null wide character.
-The
-.Fn wcstombs
-function returns the number of bytes converted,
-not counting any terminating null byte.
-If any invalid multibyte characters are encountered,
-both functions return \-1.
+The C library provides the following functions for dealing with
+multibyte characters:
+.Bl -column "Description"
+.It Sy "Function Description"
+.It Xr mblen 3 Ta "get number of bytes in a character"
+.It Xr mbrlen 3 Ta "get number of bytes in a character (restartable)"
+.It Xr mbrtowc 3 Ta "convert a character to a wide-character code (restartable)"
+.It Xr mbsrtowcs 3 Ta "convert a character string to a wide-character string (restartable)"
+.It Xr mbstowcs 3 Ta "convert a character string to a wide-character string"
+.It Xr mbtowc 3 Ta "convert a character to a wide-character code"
+.It Xr wcrtomb 3 Ta "convert a wide-character code to a character (restartable)"
+.It Xr wcstombs 3 Ta "convert a wide-character string to a character string"
+.It Xr wcsrtombs 3 Ta "convert a wide-character string to a character string (restartable)"
+.It Xr wctomb 3 Ta "convert a wide-character code to a character"
+.El
.Sh SEE ALSO
-.Xr btowc 3 ,
-.Xr mbrlen 3 ,
-.Xr mbrtowc 3 ,
-.Xr mbrune 3 ,
-.Xr mbsrtowcs 3 ,
-.Xr rune 3 ,
+.Xr mklocale 1 ,
.Xr setlocale 3 ,
-.Xr wcrtomb 3 ,
-.Xr wcsrtombs 3 ,
-.Xr euc 4 ,
-.Xr utf2 4 ,
+.Xr stdio 3 ,
+.Xr big5 5 ,
+.Xr euc 5 ,
+.Xr gb18030 5 ,
+.Xr gb2312 5 ,
+.Xr gbk 5 ,
+.Xr mskanji 5 ,
.Xr utf8 5
.Sh STANDARDS
-The
-.Fn mblen ,
-.Fn mbstowcs ,
-.Fn mbtowc ,
-.Fn wcstombs
-and
-.Fn wctomb
-functions conform to
-.St -isoC .
-.Sh BUGS
-The current implementation does not support shift states.
+These functions conform to
+.St -isoC-99 .
--- /dev/null
+.\"
+.\" Copyright (c) 2004 Tim J. Robbins
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/locale/nextwctype.3,v 1.1 2004/07/08 06:43:37 tjr Exp $
+.\"
+.Dd July 8, 2004
+.Dt NEXTWCTYPE 3
+.Os
+.Sh NAME
+.Nm nextwctype
+.Nd "iterate through character classes"
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In wctype.h
+.Ft wint_t
+.Fo nextwctype
+.Fa "wint_t ch" "wctype_t wct"
+.Fc
+.Sh DESCRIPTION
+The
+.Fn nextwctype
+function determines the next character after
+.Fa ch
+that is a member of character class
+.Fa wct .
+If
+.Fa ch
+is \-1, the search begins at the first member of
+.Fa wct .
+.Sh RETURN VALUES
+The
+.Fn nextwctype
+functions returns the next character, or \-1 if there are no more.
+.Sh SEE ALSO
+.Xr wctype 3
--- /dev/null
+--- nextwctype.3.orig Fri Mar 11 19:44:47 2005
++++ nextwctype.3 Fri Mar 11 19:53:29 2005
+@@ -29,7 +29,8 @@
+ .Dt NEXTWCTYPE 3
+ .Os
+ .Sh NAME
+-.Nm nextwctype
++.Nm nextwctype ,
++.Nm nextwctype_l
+ .Nd "iterate through character classes"
+ .Sh LIBRARY
+ .Lb libc
+@@ -39,6 +40,11 @@
+ .Fo nextwctype
+ .Fa "wint_t ch" "wctype_t wct"
+ .Fc
++.In xlocale.h
++.Ft wint_t
++.Fo nextwctype_l
++.Fa "wint_t ch" "wctype_t wct" "locale_t loc"
++.Fc
+ .Sh DESCRIPTION
+ The
+ .Fn nextwctype
+@@ -50,9 +56,18 @@
+ .Fa ch
+ is \-1, the search begins at the first member of
+ .Fa wct .
++.Pp
++While the
++.Fn nextwctype
++function uses the current locale, the
++.Fn nextwctype_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn nextwctype
+ functions returns the next character, or \-1 if there are no more.
+ .Sh SEE ALSO
+-.Xr wctype 3
++.Xr wctype 3 ,
++.Xr xlocale 3
--- /dev/null
+/*-
+ * Copyright (c) 2004 Tim J. Robbins.
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/libc/locale/nextwctype.c,v 1.1 2004/07/08 06:43:37 tjr Exp $");
+
+#include <runetype.h>
+#include <wchar.h>
+#include <wctype.h>
+
+wint_t
+nextwctype(wint_t wc, wctype_t wct)
+{
+ size_t lim;
+ _RuneRange *rr = &_CurrentRuneLocale->__runetype_ext;
+ _RuneEntry *base, *re;
+ int noinc;
+
+ noinc = 0;
+ if (wc < _CACHED_RUNES) {
+ wc++;
+ while (wc < _CACHED_RUNES) {
+ if (_CurrentRuneLocale->__runetype[wc] & wct)
+ return (wc);
+ wc++;
+ }
+ wc--;
+ }
+ if (rr->__ranges != NULL && wc < rr->__ranges[0].__min) {
+ wc = rr->__ranges[0].__min;
+ noinc = 1;
+ }
+
+ /* Binary search -- see bsearch.c for explanation. */
+ base = rr->__ranges;
+ for (lim = rr->__nranges; lim != 0; lim >>= 1) {
+ re = base + (lim >> 1);
+ if (re->__min <= wc && wc <= re->__max)
+ goto found;
+ else if (wc > re->__max) {
+ base = re + 1;
+ lim--;
+ }
+ }
+ return (-1);
+found:
+ if (!noinc)
+ wc++;
+ if (re->__min <= wc && wc <= re->__max) {
+ if (re->__types != NULL) {
+ for (; wc <= re->__max; wc++)
+ if (re->__types[wc - re->__min] & wct)
+ return (wc);
+ } else if (re->__map & wct)
+ return (wc);
+ }
+ while (++re < rr->__ranges + rr->__nranges) {
+ wc = re->__min;
+ if (re->__types != NULL) {
+ for (; wc <= re->__max; wc++)
+ if (re->__types[wc - re->__min] & wct)
+ return (wc);
+ } else if (re->__map & wct)
+ return (wc);
+ }
+ return (-1);
+}
--- /dev/null
+--- nextwctype.c.orig 2004-11-25 11:38:19.000000000 -0800
++++ nextwctype.c 2005-02-19 03:44:49.000000000 -0800
+@@ -27,28 +27,32 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/nextwctype.c,v 1.1 2004/07/08 06:43:37 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <runetype.h>
+ #include <wchar.h>
+ #include <wctype.h>
+
+ wint_t
+-nextwctype(wint_t wc, wctype_t wct)
++nextwctype_l(wint_t wc, wctype_t wct, locale_t loc)
+ {
+ size_t lim;
+- _RuneRange *rr = &_CurrentRuneLocale->__runetype_ext;
++ _RuneRange *rr;
+ _RuneEntry *base, *re;
+ int noinc;
++ _RuneLocale *rl = &loc->__lc_ctype->_CurrentRuneLocale;
+
+ noinc = 0;
+ if (wc < _CACHED_RUNES) {
+ wc++;
+ while (wc < _CACHED_RUNES) {
+- if (_CurrentRuneLocale->__runetype[wc] & wct)
++ if (rl->__runetype[wc] & wct)
+ return (wc);
+ wc++;
+ }
+ wc--;
+ }
++ rr = &rl->__runetype_ext;
+ if (rr->__ranges != NULL && wc < rr->__ranges[0].__min) {
+ wc = rr->__ranges[0].__min;
+ noinc = 1;
+@@ -88,3 +92,9 @@
+ }
+ return (-1);
+ }
++
++wint_t
++nextwctype(wint_t wc, wctype_t wct)
++{
++ return nextwctype_l(wc, wct, __current_locale());
++}
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/lib/libc/locale/nl_langinfo.3,v 1.4 2002/04/13 04:25:56 dd Exp $
+.\" $FreeBSD: src/lib/libc/locale/nl_langinfo.3,v 1.5 2003/09/08 19:57:14 ru Exp $
.\"
.Dd May 3, 2001
.Dt NL_LANGINFO 3
The manifest constant names and values of
.Fa item
are defined in
-.Aq Pa langinfo.h .
+.In langinfo.h .
.Pp
Calls to
.Fn setlocale
--- /dev/null
+--- nl_langinfo.3.orig Fri Mar 11 19:44:47 2005
++++ nl_langinfo.3 Fri Mar 11 19:52:50 2005
+@@ -28,7 +28,8 @@
+ .Dt NL_LANGINFO 3
+ .Os
+ .Sh NAME
+-.Nm nl_langinfo
++.Nm nl_langinfo ,
++.Nm nl_langinfo_l
+ .Nd language information
+ .Sh LIBRARY
+ .Lb libc
+@@ -36,6 +37,9 @@
+ .In langinfo.h
+ .Ft char *
+ .Fn nl_langinfo "nl_item item"
++.In xlocale.h
++.Ft char *
++.Fn nl_langinfo_l "nl_item item" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn nl_langinfo
+@@ -65,6 +69,14 @@
+ Portuguese, and
+ .Qq Li Sun
+ if the identified language was English.
++.Pp
++While the
++.Fn nl_langinfo
++function uses the current locale, the
++.Fn nl_langinfo_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ In a locale where langinfo data is not defined,
+ .Fn nl_langinfo
+@@ -77,7 +89,8 @@
+ .Fa item
+ contains an invalid setting.
+ .Sh SEE ALSO
+-.Xr setlocale 3
++.Xr setlocale 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn nl_langinfo
/*-
- * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
+ * Copyright (c) 2001, 2003 Alexey Zelkin <phantom@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/nl_langinfo.c,v 1.15 2002/03/22 21:52:18 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/nl_langinfo.c,v 1.17 2003/06/26 10:46:16 phantom Exp $");
-#include <locale.h>
#include <langinfo.h>
#include <limits.h>
+#include <locale.h>
#include <stdlib.h>
#include <string.h>
-#include "../stdtime/timelocal.h"
#include "lnumeric.h"
-#include "lmonetary.h"
#include "lmessages.h"
-
-#define TRANSITION_PERIOD_HACK
+#include "lmonetary.h"
+#include "../stdtime/timelocal.h"
#define _REL(BASE) ((int)item-BASE)
char *
-nl_langinfo(nl_item item) {
-
+nl_langinfo(nl_item item)
+{
char *ret, *s, *cs;
static char *csym = NULL;
-#ifdef TRANSITION_PERIOD_HACK
- static char *cset = NULL;
-#endif /* TRANSITION_PERIOD_HACK */
switch (item) {
case CODESET:
ret = "";
if ((s = setlocale(LC_CTYPE, NULL)) != NULL) {
- if ((cs = strchr(s, '.')) != NULL) {
+ if ((cs = strchr(s, '.')) != NULL)
ret = cs + 1;
-#ifdef TRANSITION_PERIOD_HACK
- if (strncmp(ret, "ISO_", 4) == 0) {
- int slen = strlen(ret);
-
- if ((cset = reallocf(cset, slen)) != NULL) {
- strcpy(cset, "ISO");
- strcat(cset, ret + 4);
- ret = cset;
- } else
- ret = "";
- } else if (strcmp(ret, "EUC") == 0) {
- if (strncmp(s, "ja_JP", 5) == 0)
- ret = "eucJP";
- else if (strncmp(s, "ko_KR", 5) == 0)
- ret = "eucKR";
- else if (strncmp(s, "zh_CN", 5) == 0)
- ret = "eucCN";
- } else if (strcmp(ret, "ASCII") == 0)
- ret = "US-ASCII";
-#endif /* TRANSITION_PERIOD_HACK */
- } else if (strcmp(s, "C") == 0 ||
- strcmp(s, "POSIX") == 0
-#ifdef TRANSITION_PERIOD_HACK
- || strstr(s, "ASCII") != NULL
-#endif /* TRANSITION_PERIOD_HACK */
- )
+ else if (strcmp(s, "C") == 0 ||
+ strcmp(s, "POSIX") == 0)
ret = "US-ASCII";
}
break;
ret = (char*) __get_current_messages_locale()->noexpr;
break;
/*
- * All items marked with LEGACY are available, but not recomended
- * by SUSv2 to be used in portable applications since they're subject
- * to remove in future specification editions
+ * YESSTR and NOSTR items marked with LEGACY are available, but not
+ * recomended by SUSv2 to be used in portable applications since
+ * they're subject to remove in future specification editions.
*/
case YESSTR: /* LEGACY */
ret = (char*) __get_current_messages_locale()->yesstr;
case NOSTR: /* LEGACY */
ret = (char*) __get_current_messages_locale()->nostr;
break;
+ /*
+ * SUSv2 special formatted currency string
+ */
case CRNCYSTR:
ret = "";
cs = (char*) __get_current_monetary_locale()->currency_symbol;
}
}
break;
- case D_MD_ORDER: /* local extension */
+ case D_MD_ORDER: /* FreeBSD local extension */
ret = (char *) __get_current_time_locale()->md_order;
break;
default:
---- nl_langinfo.c.orig Fri Mar 22 13:52:18 2002
-+++ nl_langinfo.c Sat May 3 14:14:55 2003
-@@ -33,7 +33,7 @@
- #include <stdlib.h>
- #include <string.h>
+--- nl_langinfo.c.orig 2004-11-25 11:38:19.000000000 -0800
++++ nl_langinfo.c 2005-02-18 22:22:41.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/nl_langinfo.c,v 1.17 2003/06/26 10:46:16 phantom Exp $");
--#include "../stdtime/timelocal.h"
-+#include "timelocal.h"
++#include "xlocale_private.h"
++
+ #include <langinfo.h>
+ #include <limits.h>
+ #include <locale.h>
+@@ -36,20 +38,22 @@
#include "lnumeric.h"
- #include "lmonetary.h"
#include "lmessages.h"
+ #include "lmonetary.h"
+-#include "../stdtime/timelocal.h"
++#include "timelocal.h"
+
+ #define _REL(BASE) ((int)item-BASE)
+
+ char *
+-nl_langinfo(nl_item item)
++nl_langinfo_l(nl_item item, locale_t loc)
+ {
+- char *ret, *s, *cs;
++ char *ret, *cs;
++ const char *s;
+ static char *csym = NULL;
+
++ NORMALIZE_LOCALE(loc);
+ switch (item) {
+ case CODESET:
+ ret = "";
+- if ((s = setlocale(LC_CTYPE, NULL)) != NULL) {
++ if ((s = querylocale(LC_CTYPE_MASK, loc)) != NULL) {
+ if ((cs = strchr(s, '.')) != NULL)
+ ret = cs + 1;
+ else if (strcmp(s, "C") == 0 ||
+@@ -58,40 +62,40 @@
+ }
+ break;
+ case D_T_FMT:
+- ret = (char *) __get_current_time_locale()->c_fmt;
++ ret = (char *) __get_current_time_locale(loc)->c_fmt;
+ break;
+ case D_FMT:
+- ret = (char *) __get_current_time_locale()->x_fmt;
++ ret = (char *) __get_current_time_locale(loc)->x_fmt;
+ break;
+ case T_FMT:
+- ret = (char *) __get_current_time_locale()->X_fmt;
++ ret = (char *) __get_current_time_locale(loc)->X_fmt;
+ break;
+ case T_FMT_AMPM:
+- ret = (char *) __get_current_time_locale()->ampm_fmt;
++ ret = (char *) __get_current_time_locale(loc)->ampm_fmt;
+ break;
+ case AM_STR:
+- ret = (char *) __get_current_time_locale()->am;
++ ret = (char *) __get_current_time_locale(loc)->am;
+ break;
+ case PM_STR:
+- ret = (char *) __get_current_time_locale()->pm;
++ ret = (char *) __get_current_time_locale(loc)->pm;
+ break;
+ case DAY_1: case DAY_2: case DAY_3:
+ case DAY_4: case DAY_5: case DAY_6: case DAY_7:
+- ret = (char*) __get_current_time_locale()->weekday[_REL(DAY_1)];
++ ret = (char*) __get_current_time_locale(loc)->weekday[_REL(DAY_1)];
+ break;
+ case ABDAY_1: case ABDAY_2: case ABDAY_3:
+ case ABDAY_4: case ABDAY_5: case ABDAY_6: case ABDAY_7:
+- ret = (char*) __get_current_time_locale()->wday[_REL(ABDAY_1)];
++ ret = (char*) __get_current_time_locale(loc)->wday[_REL(ABDAY_1)];
+ break;
+ case MON_1: case MON_2: case MON_3: case MON_4:
+ case MON_5: case MON_6: case MON_7: case MON_8:
+ case MON_9: case MON_10: case MON_11: case MON_12:
+- ret = (char*) __get_current_time_locale()->month[_REL(MON_1)];
++ ret = (char*) __get_current_time_locale(loc)->month[_REL(MON_1)];
+ break;
+ case ABMON_1: case ABMON_2: case ABMON_3: case ABMON_4:
+ case ABMON_5: case ABMON_6: case ABMON_7: case ABMON_8:
+ case ABMON_9: case ABMON_10: case ABMON_11: case ABMON_12:
+- ret = (char*) __get_current_time_locale()->mon[_REL(ABMON_1)];
++ ret = (char*) __get_current_time_locale(loc)->mon[_REL(ABMON_1)];
+ break;
+ case ERA:
+ /* XXX: need to be implemented */
+@@ -114,16 +118,16 @@
+ ret = "";
+ break;
+ case RADIXCHAR:
+- ret = (char*) __get_current_numeric_locale()->decimal_point;
++ ret = (char*) __get_current_numeric_locale(loc)->decimal_point;
+ break;
+ case THOUSEP:
+- ret = (char*) __get_current_numeric_locale()->thousands_sep;
++ ret = (char*) __get_current_numeric_locale(loc)->thousands_sep;
+ break;
+ case YESEXPR:
+- ret = (char*) __get_current_messages_locale()->yesexpr;
++ ret = (char*) __get_current_messages_locale(loc)->yesexpr;
+ break;
+ case NOEXPR:
+- ret = (char*) __get_current_messages_locale()->noexpr;
++ ret = (char*) __get_current_messages_locale(loc)->noexpr;
+ break;
+ /*
+ * YESSTR and NOSTR items marked with LEGACY are available, but not
+@@ -131,25 +135,25 @@
+ * they're subject to remove in future specification editions.
+ */
+ case YESSTR: /* LEGACY */
+- ret = (char*) __get_current_messages_locale()->yesstr;
++ ret = (char*) __get_current_messages_locale(loc)->yesstr;
+ break;
+ case NOSTR: /* LEGACY */
+- ret = (char*) __get_current_messages_locale()->nostr;
++ ret = (char*) __get_current_messages_locale(loc)->nostr;
+ break;
+ /*
+ * SUSv2 special formatted currency string
+ */
+ case CRNCYSTR:
+ ret = "";
+- cs = (char*) __get_current_monetary_locale()->currency_symbol;
++ cs = (char*) __get_current_monetary_locale(loc)->currency_symbol;
+ if (*cs != '\0') {
+- char pos = localeconv()->p_cs_precedes;
++ char pos = localeconv_l(loc)->p_cs_precedes;
+
+- if (pos == localeconv()->n_cs_precedes) {
++ if (pos == localeconv_l(loc)->n_cs_precedes) {
+ char psn = '\0';
+
+ if (pos == CHAR_MAX) {
+- if (strcmp(cs, __get_current_monetary_locale()->mon_decimal_point) == 0)
++ if (strcmp(cs, __get_current_monetary_locale(loc)->mon_decimal_point) == 0)
+ psn = '.';
+ } else
+ psn = pos ? '-' : '+';
+@@ -166,10 +170,16 @@
+ }
+ break;
+ case D_MD_ORDER: /* FreeBSD local extension */
+- ret = (char *) __get_current_time_locale()->md_order;
++ ret = (char *) __get_current_time_locale(loc)->md_order;
+ break;
+ default:
+ ret = "";
+ }
+ return (ret);
+ }
++
++char *
++nl_langinfo(nl_item item)
++{
++ return (nl_langinfo_l(item, __current_locale()));
++}
/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved.
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
*
static char sccsid[] = "@(#)none.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/none.c,v 1.6 2002/10/16 11:37:38 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/none.c,v 1.12 2004/07/21 10:54:57 tjr Exp $");
+#include <errno.h>
#include <limits.h>
+#include <runetype.h>
#include <stddef.h>
#include <stdio.h>
-#include <rune.h>
#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include "mblocal.h"
-rune_t _none_sgetrune(const char *, size_t, char const **);
-int _none_sputrune(rune_t, char *, size_t, char **);
+int _none_init(_RuneLocale *);
+size_t _none_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
+ mbstate_t * __restrict);
+int _none_mbsinit(const mbstate_t *);
+size_t _none_mbsnrtowcs(wchar_t * __restrict dst,
+ const char ** __restrict src, size_t nms, size_t len,
+ mbstate_t * __restrict ps __unused);
+size_t _none_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
+size_t _none_wcsnrtombs(char * __restrict, const wchar_t ** __restrict,
+ size_t, size_t, mbstate_t * __restrict);
int
-_none_init(rl)
- _RuneLocale *rl;
+_none_init(_RuneLocale *rl)
{
- rl->sgetrune = _none_sgetrune;
- rl->sputrune = _none_sputrune;
+
+ __mbrtowc = _none_mbrtowc;
+ __mbsinit = _none_mbsinit;
+ __mbsnrtowcs = _none_mbsnrtowcs;
+ __wcrtomb = _none_wcrtomb;
+ __wcsnrtombs = _none_wcsnrtombs;
_CurrentRuneLocale = rl;
__mb_cur_max = 1;
return(0);
}
-rune_t
-_none_sgetrune(string, n, result)
- const char *string;
- size_t n;
- char const **result;
+int
+_none_mbsinit(const mbstate_t *ps __unused)
{
- if (n < 1) {
- if (result)
- *result = string;
- return(_INVALID_RUNE);
+
+ /*
+ * Encoding is not state dependent - we are always in the
+ * initial state.
+ */
+ return (1);
+}
+
+size_t
+_none_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
+ mbstate_t * __restrict ps __unused)
+{
+
+ if (s == NULL)
+ /* Reset to initial shift state (no-op) */
+ return (0);
+ if (n == 0)
+ /* Incomplete multibyte sequence */
+ return ((size_t)-2);
+ if (pwc != NULL)
+ *pwc = (unsigned char)*s;
+ return (*s == '\0' ? 0 : 1);
+}
+
+size_t
+_none_wcrtomb(char * __restrict s, wchar_t wc,
+ mbstate_t * __restrict ps __unused)
+{
+
+ if (s == NULL)
+ /* Reset to initial shift state (no-op) */
+ return (1);
+ if (wc < 0 || wc > UCHAR_MAX) {
+ errno = EILSEQ;
+ return ((size_t)-1);
}
- if (result)
- *result = string + 1;
- return(*string & 0xff);
+ *s = (unsigned char)wc;
+ return (1);
}
-int
-_none_sputrune(c, string, n, result)
- rune_t c;
- char *string, **result;
- size_t n;
+size_t
+_none_mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src,
+ size_t nms, size_t len, mbstate_t * __restrict ps __unused)
+{
+ const char *s;
+ size_t nchr;
+
+ if (dst == NULL) {
+ s = memchr(*src, '\0', nms);
+ return (s != NULL ? s - *src : nms);
+ }
+
+ s = *src;
+ nchr = 0;
+ while (len-- > 0 && nms-- > 0) {
+ if ((*dst++ = (unsigned char)*s++) == L'\0') {
+ *src = NULL;
+ return (nchr);
+ }
+ nchr++;
+ }
+ *src = s;
+ return (nchr);
+}
+
+size_t
+_none_wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src,
+ size_t nwc, size_t len, mbstate_t * __restrict ps __unused)
{
- if (n >= 1) {
- if (string) {
- if (c < 0 || c > UCHAR_MAX) {
- if (result)
- *result = NULL;
- return (0);
+ const wchar_t *s;
+ size_t nchr;
+
+ if (dst == NULL) {
+ for (s = *src; nwc > 0 && *s != L'\0'; s++, nwc--) {
+ if (*s < 0 || *s > UCHAR_MAX) {
+ errno = EILSEQ;
+ return ((size_t)-1);
}
- *string = c;
}
- if (result)
- *result = string + 1;
- } else if (result)
- *result = (char *)0;
- return(1);
+ return (s - *src);
+ }
+
+ s = *src;
+ nchr = 0;
+ while (len-- > 0 && nwc-- > 0) {
+ if (*s < 0 || *s > UCHAR_MAX) {
+ errno = EILSEQ;
+ return ((size_t)-1);
+ }
+ if ((*dst++ = *s++) == '\0') {
+ *src = NULL;
+ return (nchr);
+ }
+ nchr++;
+ }
+ *src = s;
+ return (nchr);
}
--- /dev/null
+--- none.c.orig Fri Feb 18 15:34:30 2005
++++ none.c Fri Feb 18 15:37:15 2005
+@@ -41,6 +41,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/none.c,v 1.12 2004/07/21 10:54:57 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <errno.h>
+ #include <limits.h>
+ #include <runetype.h>
+@@ -51,33 +53,32 @@
+ #include <wchar.h>
+ #include "mblocal.h"
+
+-int _none_init(_RuneLocale *);
+-size_t _none_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
+- mbstate_t * __restrict);
+-int _none_mbsinit(const mbstate_t *);
+-size_t _none_mbsnrtowcs(wchar_t * __restrict dst,
++__private_extern__ int _none_init(struct __xlocale_st_runelocale *);
++__private_extern__ size_t _none_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
++ mbstate_t * __restrict, locale_t);
++__private_extern__ int _none_mbsinit(const mbstate_t *, locale_t);
++__private_extern__ size_t _none_mbsnrtowcs(wchar_t * __restrict dst,
+ const char ** __restrict src, size_t nms, size_t len,
+- mbstate_t * __restrict ps __unused);
+-size_t _none_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
+-size_t _none_wcsnrtombs(char * __restrict, const wchar_t ** __restrict,
+- size_t, size_t, mbstate_t * __restrict);
++ mbstate_t * __restrict ps __unused, locale_t);
++__private_extern__ size_t _none_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict, locale_t);
++__private_extern__ size_t _none_wcsnrtombs(char * __restrict, const wchar_t ** __restrict,
++ size_t, size_t, mbstate_t * __restrict, locale_t);
+
+-int
+-_none_init(_RuneLocale *rl)
++__private_extern__ int
++_none_init(struct __xlocale_st_runelocale *xrl)
+ {
+
+- __mbrtowc = _none_mbrtowc;
+- __mbsinit = _none_mbsinit;
+- __mbsnrtowcs = _none_mbsnrtowcs;
+- __wcrtomb = _none_wcrtomb;
+- __wcsnrtombs = _none_wcsnrtombs;
+- _CurrentRuneLocale = rl;
+- __mb_cur_max = 1;
++ xrl->__mbrtowc = _none_mbrtowc;
++ xrl->__mbsinit = _none_mbsinit;
++ xrl->__mbsnrtowcs = _none_mbsnrtowcs;
++ xrl->__wcrtomb = _none_wcrtomb;
++ xrl->__wcsnrtombs = _none_wcsnrtombs;
++ xrl->__mb_cur_max = 1;
+ return(0);
+ }
+
+-int
+-_none_mbsinit(const mbstate_t *ps __unused)
++__private_extern__ int
++_none_mbsinit(const mbstate_t *ps __unused, locale_t loc)
+ {
+
+ /*
+@@ -87,9 +88,9 @@
+ return (1);
+ }
+
+-size_t
++__private_extern__ size_t
+ _none_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
+- mbstate_t * __restrict ps __unused)
++ mbstate_t * __restrict ps __unused, locale_t loc)
+ {
+
+ if (s == NULL)
+@@ -103,9 +104,9 @@
+ return (*s == '\0' ? 0 : 1);
+ }
+
+-size_t
++__private_extern__ size_t
+ _none_wcrtomb(char * __restrict s, wchar_t wc,
+- mbstate_t * __restrict ps __unused)
++ mbstate_t * __restrict ps __unused, locale_t loc)
+ {
+
+ if (s == NULL)
+@@ -119,9 +120,9 @@
+ return (1);
+ }
+
+-size_t
++__private_extern__ size_t
+ _none_mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src,
+- size_t nms, size_t len, mbstate_t * __restrict ps __unused)
++ size_t nms, size_t len, mbstate_t * __restrict ps __unused, locale_t loc)
+ {
+ const char *s;
+ size_t nchr;
+@@ -144,9 +145,9 @@
+ return (nchr);
+ }
+
+-size_t
++__private_extern__ size_t
+ _none_wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src,
+- size_t nwc, size_t len, mbstate_t * __restrict ps __unused)
++ size_t nwc, size_t len, mbstate_t * __restrict ps __unused, locale_t loc)
+ {
+ const wchar_t *s;
+ size_t nchr;
+++ /dev/null
-.\" Copyright (c) 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" This code is derived from software contributed to Berkeley by
-.\" Paul Borman at Krystal Technologies.
-.\"
-.\" 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.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
-.\"
-.\" @(#)rune.3 8.2 (Berkeley) 12/11/93
-.\" $FreeBSD: src/lib/libc/locale/rune.3,v 1.22 2002/12/19 09:40:22 ru Exp $
-.\"
-.Dd October 6, 2002
-.Dt RUNE 3
-.Os
-.Sh NAME
-.Nm setrunelocale ,
-.Nm setinvalidrune ,
-.Nm sgetrune ,
-.Nm sputrune ,
-.Nm fgetrune ,
-.Nm fungetrune ,
-.Nm fputrune
-.Nd rune support for C
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In rune.h
-.In errno.h
-.Ft int
-.Fn setrunelocale "char *locale"
-.Ft void
-.Fn setinvalidrune "rune_t rune"
-.Ft rune_t
-.Fn sgetrune "const char *string" "size_t n" "char const **result"
-.Ft int
-.Fn sputrune "rune_t rune" "char *string" "size_t n" "char **result"
-.Pp
-.In stdio.h
-.Ft long
-.Fn fgetrune "FILE *stream"
-.Ft int
-.Fn fungetrune "rune_t rune" "FILE *stream"
-.Ft int
-.Fn fputrune "rune_t rune" "FILE *stream"
-.Sh DESCRIPTION
-.Bf Em
-The
-.Bx 4.4
-.Dq rune
-functions have been deprecated in favour of the
-.Tn ISO
-C99 extended multibyte and wide character facilities
-and should not be used in new applications.
-.Ef
-Consider using
-.Xr setlocale 3 ,
-.Xr mbrtowc 3 ,
-.Xr wcrtomb 3 ,
-.Xr fgetwc 3 ,
-.Xr ungetwc 3 ,
-and
-.Xr fputwc 3
-instead.
-.Pp
-The
-.Fn setrunelocale
-controls the type of encoding used to represent runes as multibyte strings
-as well as the properties of the runes as defined in
-.Aq Pa ctype.h .
-The
-.Fa locale
-argument indicates which locale to load.
-If the locale is successfully loaded,
-.Dv 0
-is returned, otherwise an errno value is returned to indicate the
-type of error.
-.Pp
-The
-.Fn setinvalidrune
-function sets the value of the global value
-.Dv _INVALID_RUNE
-to be
-.Fa rune .
-.Pp
-The
-.Fn sgetrune
-function tries to read a single multibyte character from
-.Fa string ,
-which is at most
-.Fa n
-bytes long.
-If
-.Fn sgetrune
-is successful, the rune is returned.
-If
-.Fa result
-is not
-.Dv NULL ,
-.Fa *result
-will point to the first byte which was not converted in
-.Fa string .
-If the first
-.Fa n
-bytes of
-.Fa string
-do not describe a full multibyte character,
-.Dv _INVALID_RUNE
-is returned and
-.Fa *result
-will point to
-.Fa string .
-If there is an encoding error at the start of
-.Fa string ,
-.Dv _INVALID_RUNE
-is returned and
-.Fa *result
-will point to the second character of
-.Fa string .
-.Pp
-the
-.Fn sputrune
-function tries to encode
-.Fa rune
-as a multibyte string and store it at
-.Fa string ,
-but no more than
-.Fa n
-bytes will be stored.
-If
-.Fa result
-is not
-.Dv NULL ,
-.Fa *result
-will be set to point to the first byte in string following the new
-multibyte character.
-If
-.Fa string
-is
-.Dv NULL ,
-.Fa *result
-will point to
-.Dv "(char *)0 +"
-.Fa x ,
-where
-.Fa x
-is the number of bytes that would be needed to store the multibyte value.
-If the multibyte character would consist of more than
-.Fa n
-bytes and
-.Fa result
-is not
-.Dv NULL ,
-.Fa *result
-will be set to
-.Dv NULL .
-In all cases,
-.Fn sputrune
-will return the number of bytes which would be needed to store
-.Fa rune
-as a multibyte character.
-.Pp
-The
-.Fn fgetrune
-function operates the same as
-.Fn sgetrune
-with the exception that it attempts to read enough bytes from
-.Fa stream
-to decode a single rune. It returns either
-.Dv EOF
-on end of file,
-.Dv _INVALID_RUNE
-on an encoding error, or the rune decoded if all went well.
-.Pp
-The
-.Fn fungetrune
-function pushes the multibyte encoding, as provided by
-.Fn sputrune ,
-of
-.Fa rune
-onto
-.Fa stream
-such that the next
-.Fn fgetrune
-call will return
-.Fa rune .
-It returns
-.Dv EOF
-if it fails and
-.Dv 0
-on success.
-.Pp
-The
-.Fn fputrune
-function writes the multibyte encoding of
-.Fa rune ,
-as provided by
-.Fn sputrune ,
-onto
-.Fa stream .
-It returns
-.Dv EOF
-on failure and
-.Dv 0
-on success.
-.Sh RETURN VALUES
-The
-.Fn setrunelocale
-function returns one of the following values:
-.Bl -tag -width Er
-.It Er 0
-The
-.Fn setrunelocale
-function
-was successful.
-.It Bq Er EINVAL
-The
-.Fa locale
-name was incorrect.
-.It Bq Er ENOENT
-The locale could not be found.
-.It Bq Er EFTYPE
-The file found was not a valid file.
-.El
-.Pp
-The
-.Fn sgetrune
-function either returns the rune read or
-.Dv _INVALID_RUNE .
-The
-.Fn sputrune
-function returns the number of bytes needed to store
-.Fa rune
-as a multibyte string.
-.Sh FILES
-.Bl -tag -width /usr/share/locale/locale/LC_CTYPE -compact
-.It Pa $PATH_LOCALE/ Ns Em locale Ns /LC_CTYPE
-.It Pa /usr/share/locale/ Ns Em locale Ns /LC_CTYPE
-binary LC_CTYPE file for the locale
-.Em locale .
-.El
-.Sh SEE ALSO
-.Xr mbrune 3 ,
-.Xr setlocale 3 ,
-.Xr euc 4 ,
-.Xr utf2 4 ,
-.Xr utf8 5
-.Sh HISTORY
-These functions first appeared in
-.Bx 4.4 .
-.Pp
-The
-.Fn setrunelocale
-function and the other non-ANSI rune functions were inspired by
-.Sy "Plan 9 from Bell Labs" .
-.\"They were conceived at the San Diego 1993 Summer USENIX conference by
-.\"Paul Borman of Krystal Technologies, Keith Bostic of CSRG and Andrew Hume
-.\"of Bell Labs.
static char sccsid[] = "@(#)rune.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/rune.c,v 1.10 2002/08/09 08:22:29 ache Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/rune.c,v 1.12 2004/07/29 06:16:19 tjr Exp $");
#include "namespace.h"
#include <arpa/inet.h>
#include <errno.h>
-#include <rune.h>
+#include <runetype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
rl = (_RuneLocale *)data;
lastp = data + sb.st_size;
- rl->variable = rl + 1;
+ rl->__variable = rl + 1;
- if (memcmp(rl->magic, _RUNE_MAGIC_1, sizeof(rl->magic))) {
+ if (memcmp(rl->__magic, _RUNE_MAGIC_1, sizeof(rl->__magic))) {
free(data);
errno = EFTYPE;
return (NULL);
}
- rl->invalid_rune = ntohl(rl->invalid_rune);
- rl->variable_len = ntohl(rl->variable_len);
- rl->runetype_ext.nranges = ntohl(rl->runetype_ext.nranges);
- rl->maplower_ext.nranges = ntohl(rl->maplower_ext.nranges);
- rl->mapupper_ext.nranges = ntohl(rl->mapupper_ext.nranges);
+ rl->__invalid_rune = ntohl(rl->__invalid_rune);
+ rl->__variable_len = ntohl(rl->__variable_len);
+ rl->__runetype_ext.__nranges = ntohl(rl->__runetype_ext.__nranges);
+ rl->__maplower_ext.__nranges = ntohl(rl->__maplower_ext.__nranges);
+ rl->__mapupper_ext.__nranges = ntohl(rl->__mapupper_ext.__nranges);
for (x = 0; x < _CACHED_RUNES; ++x) {
- rl->runetype[x] = ntohl(rl->runetype[x]);
- rl->maplower[x] = ntohl(rl->maplower[x]);
- rl->mapupper[x] = ntohl(rl->mapupper[x]);
+ rl->__runetype[x] = ntohl(rl->__runetype[x]);
+ rl->__maplower[x] = ntohl(rl->__maplower[x]);
+ rl->__mapupper[x] = ntohl(rl->__mapupper[x]);
}
- rl->runetype_ext.ranges = (_RuneEntry *)rl->variable;
- rl->variable = rl->runetype_ext.ranges + rl->runetype_ext.nranges;
- if (rl->variable > lastp) {
+ rl->__runetype_ext.__ranges = (_RuneEntry *)rl->__variable;
+ rl->__variable = rl->__runetype_ext.__ranges +
+ rl->__runetype_ext.__nranges;
+ if (rl->__variable > lastp) {
free(data);
errno = EFTYPE;
return (NULL);
}
- rl->maplower_ext.ranges = (_RuneEntry *)rl->variable;
- rl->variable = rl->maplower_ext.ranges + rl->maplower_ext.nranges;
- if (rl->variable > lastp) {
+ rl->__maplower_ext.__ranges = (_RuneEntry *)rl->__variable;
+ rl->__variable = rl->__maplower_ext.__ranges +
+ rl->__maplower_ext.__nranges;
+ if (rl->__variable > lastp) {
free(data);
errno = EFTYPE;
return (NULL);
}
- rl->mapupper_ext.ranges = (_RuneEntry *)rl->variable;
- rl->variable = rl->mapupper_ext.ranges + rl->mapupper_ext.nranges;
- if (rl->variable > lastp) {
+ rl->__mapupper_ext.__ranges = (_RuneEntry *)rl->__variable;
+ rl->__variable = rl->__mapupper_ext.__ranges +
+ rl->__mapupper_ext.__nranges;
+ if (rl->__variable > lastp) {
free(data);
errno = EFTYPE;
return (NULL);
}
- for (x = 0; x < rl->runetype_ext.nranges; ++x) {
- rr = rl->runetype_ext.ranges;
+ for (x = 0; x < rl->__runetype_ext.__nranges; ++x) {
+ rr = rl->__runetype_ext.__ranges;
- rr[x].min = ntohl(rr[x].min);
- rr[x].max = ntohl(rr[x].max);
- if ((rr[x].map = ntohl(rr[x].map)) == 0) {
- int len = rr[x].max - rr[x].min + 1;
- rr[x].types = rl->variable;
- rl->variable = rr[x].types + len;
- if (rl->variable > lastp) {
+ rr[x].__min = ntohl(rr[x].__min);
+ rr[x].__max = ntohl(rr[x].__max);
+ if ((rr[x].__map = ntohl(rr[x].__map)) == 0) {
+ int len = rr[x].__max - rr[x].__min + 1;
+ rr[x].__types = rl->__variable;
+ rl->__variable = rr[x].__types + len;
+ if (rl->__variable > lastp) {
free(data);
errno = EFTYPE;
return (NULL);
}
while (len-- > 0)
- rr[x].types[len] = ntohl(rr[x].types[len]);
+ rr[x].__types[len] = ntohl(rr[x].__types[len]);
} else
- rr[x].types = 0;
+ rr[x].__types = 0;
}
- for (x = 0; x < rl->maplower_ext.nranges; ++x) {
- rr = rl->maplower_ext.ranges;
+ for (x = 0; x < rl->__maplower_ext.__nranges; ++x) {
+ rr = rl->__maplower_ext.__ranges;
- rr[x].min = ntohl(rr[x].min);
- rr[x].max = ntohl(rr[x].max);
- rr[x].map = ntohl(rr[x].map);
+ rr[x].__min = ntohl(rr[x].__min);
+ rr[x].__max = ntohl(rr[x].__max);
+ rr[x].__map = ntohl(rr[x].__map);
}
- for (x = 0; x < rl->mapupper_ext.nranges; ++x) {
- rr = rl->mapupper_ext.ranges;
+ for (x = 0; x < rl->__mapupper_ext.__nranges; ++x) {
+ rr = rl->__mapupper_ext.__ranges;
- rr[x].min = ntohl(rr[x].min);
- rr[x].max = ntohl(rr[x].max);
- rr[x].map = ntohl(rr[x].map);
+ rr[x].__min = ntohl(rr[x].__min);
+ rr[x].__max = ntohl(rr[x].__max);
+ rr[x].__map = ntohl(rr[x].__map);
}
- if (((char *)rl->variable) + rl->variable_len > (char *)lastp) {
+ if (((char *)rl->__variable) + rl->__variable_len > (char *)lastp) {
free(data);
errno = EFTYPE;
return (NULL);
/*
* Go out and zero pointers that should be zero.
*/
- if (!rl->variable_len)
- rl->variable = 0;
+ if (!rl->__variable_len)
+ rl->__variable = 0;
- if (!rl->runetype_ext.nranges)
- rl->runetype_ext.ranges = 0;
+ if (!rl->__runetype_ext.__nranges)
+ rl->__runetype_ext.__ranges = 0;
- if (!rl->maplower_ext.nranges)
- rl->maplower_ext.ranges = 0;
+ if (!rl->__maplower_ext.__nranges)
+ rl->__maplower_ext.__ranges = 0;
- if (!rl->mapupper_ext.nranges)
- rl->mapupper_ext.ranges = 0;
+ if (!rl->__mapupper_ext.__nranges)
+ rl->__mapupper_ext.__ranges = 0;
return (rl);
}
---- rune.c.orig Fri Aug 9 01:22:29 2002
-+++ rune.c Sat May 3 14:15:04 2003
-@@ -41,7 +41,6 @@
- __FBSDID("$FreeBSD: src/lib/libc/locale/rune.c,v 1.10 2002/08/09 08:22:29 ache Exp $");
+--- rune.c.orig 2004-11-25 11:38:19.000000000 -0800
++++ rune.c 2005-02-14 19:25:48.000000000 -0800
+@@ -34,28 +34,96 @@
+ * SUCH DAMAGE.
+ */
++#ifndef RUNEOFF32
+ #if defined(LIBC_SCCS) && !defined(lint)
+ static char sccsid[] = "@(#)rune.c 8.1 (Berkeley) 6/4/93";
+ #endif /* LIBC_SCCS and not lint */
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/rune.c,v 1.12 2004/07/29 06:16:19 tjr Exp $");
+
++#include "xlocale_private.h"
++
#include "namespace.h"
--#include <arpa/inet.h>
+ #include <arpa/inet.h>
#include <errno.h>
- #include <rune.h>
++#endif /* !RUNEOFF32 */
+ #include <runetype.h>
#include <stdio.h>
++#ifndef RUNEOFF32
+ #include <string.h>
+ #include <stdlib.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include "un-namespace.h"
++#endif /* !RUNEOFF32 */
++
++#if defined(__LP64__) || defined(RUNEOFF32)
++/*
++ * Because the LC_CTYPE files were created with a 32-bit program, we need
++ * to adjust for the larger pointers in LP64 (the longs have already been
++ * replaced by 32-bit equivalents). Also, natural alignment will pad
++ * 64-bit types to 8-byte boundaries, and make structures containing
++ * 64-bit types sized to 8-byte boundaries.
++ */
++#include <stddef.h>
++#ifndef RUNEOFF32
++#include "rune32.h"
++#define BYTES32BITS 4
++#define BYTES64BITS 8
++/* whether to skip over a pointer or not (one-to-one with off64) */
++static int skip[] = {
++ 1,
++ 1,
++ 0,
++ 1,
++ 0,
++ 1,
++ 0,
++ 1,
++ 1,
++ 0
++};
++#endif /* !RUNEOFF32 */
++static int off64[] = {
++ offsetof(_RuneLocale, __sgetrune),
++ offsetof(_RuneLocale, __sputrune),
++ offsetof(_RuneLocale, __runetype_ext),
++ offsetof(_RuneLocale, __runetype_ext) + offsetof(_RuneRange, __ranges),
++ offsetof(_RuneLocale, __maplower_ext),
++ offsetof(_RuneLocale, __maplower_ext) + offsetof(_RuneRange, __ranges),
++ offsetof(_RuneLocale, __mapupper_ext),
++ offsetof(_RuneLocale, __mapupper_ext) + offsetof(_RuneRange, __ranges),
++ offsetof(_RuneLocale, __variable),
++ sizeof(_RuneLocale)
++};
++#define NOFF (sizeof(off64) / sizeof(int))
++#ifdef RUNEOFF32
++/*
++ * This program generates a header file (on stdout) that containes the 32-bit
++ * offsets, plus some 32-bit sizes
++ */
++main()
++{
++ int i;
++ printf("#define SIZEOF32_RUNEENTRY %d\n", sizeof(_RuneEntry));
++ printf("#define SIZEOF32_RUNELOCALE %d\n", sizeof(_RuneLocale));
++ printf("static int off32[] = {\n");
++ for(i = 0; i < NOFF; i++)
++ printf("\t%d,\n", off64[i]);
++ printf("};\n");
++ return 0;
++}
++#endif /* RUNEOFF32 */
++#else /* !__LP64__ && !RUNEOFF32 */
++#define SIZEOF32_RUNELOCALE sizeof(_RuneLocale)
++#endif /* __LP64__ || RUNEOFF32 */
+
+-_RuneLocale *
++#ifndef RUNEOFF32
++struct __xlocale_st_runelocale *
+ _Read_RuneMagi(fp)
+ FILE *fp;
+ {
+- char *data;
++ struct __xlocale_st_runelocale *data;
+ void *lastp;
+ _RuneLocale *rl;
+ _RuneEntry *rr;
+@@ -65,13 +133,20 @@
+ if (_fstat(fileno(fp), &sb) < 0)
+ return (NULL);
+
+- if (sb.st_size < sizeof(_RuneLocale)) {
++ if (sb.st_size < SIZEOF32_RUNELOCALE) {
+ errno = EFTYPE;
+ return (NULL);
+ }
+
+- if ((data = malloc(sb.st_size)) == NULL)
++#ifdef __LP64__
++ /* will adjust later */
++ if ((data = (struct __xlocale_st_runelocale *)malloc(sizeof(struct __xlocale_st_runelocale))) == NULL)
++#else /* !__LP64__ */
++ if ((data = (struct __xlocale_st_runelocale *)malloc(sizeof(struct __xlocale_st_runelocale) - sizeof(_RuneLocale) + sb.st_size)) == NULL)
++#endif /* __LP64__ */
+ return (NULL);
++ data->__refcount = 1;
++ data->__free_extra = NULL;
+
+ errno = 0;
+ rewind(fp); /* Someone might have read the magic number once already */
+@@ -82,17 +157,25 @@
+ return (NULL);
+ }
+
+- if (fread(data, sb.st_size, 1, fp) != 1) {
++ rl = &data->_CurrentRuneLocale;
++
++#ifdef __LP64__
++ if (fread(rl, SIZEOF32_RUNELOCALE, 1, fp) != 1)
++#else /* !__LP64__ */
++ if (fread(rl, sb.st_size, 1, fp) != 1)
++#endif /* __LP64__ */
++ {
+ saverr = errno;
+ free(data);
+ errno = saverr;
+ return (NULL);
+ }
+
+- rl = (_RuneLocale *)data;
+- lastp = data + sb.st_size;
++#ifndef __LP64__
++ lastp = (char *)rl + sb.st_size;
+
+ rl->__variable = rl + 1;
++#endif /* __LP64__ */
+
+ if (memcmp(rl->__magic, _RUNE_MAGIC_1, sizeof(rl->__magic))) {
+ free(data);
+@@ -100,6 +183,14 @@
+ return (NULL);
+ }
+
++#ifdef __LP64__
++ /* shift things into the right position */
++ for (x = NOFF - 2; x >= 0; x--)
++ memmove((char *)rl + off64[x] + (skip[x] ? BYTES64BITS : 0),
++ (char *)rl + off32[x] + (skip[x] ? BYTES32BITS : 0),
++ off32[x + 1] - off32[x] - (skip[x] ? BYTES32BITS : 0));
++#endif /* __LP64__ */
++#if __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN
+ rl->__invalid_rune = ntohl(rl->__invalid_rune);
+ rl->__variable_len = ntohl(rl->__variable_len);
+ rl->__runetype_ext.__nranges = ntohl(rl->__runetype_ext.__nranges);
+@@ -111,7 +202,43 @@
+ rl->__maplower[x] = ntohl(rl->__maplower[x]);
+ rl->__mapupper[x] = ntohl(rl->__mapupper[x]);
+ }
++#endif /* __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN */
++
++#ifdef __LP64__
++ {
++ int count = rl->__runetype_ext.__nranges + rl->__maplower_ext.__nranges
++ + rl->__mapupper_ext.__nranges;
++ int extra = sb.st_size - SIZEOF32_RUNELOCALE - count * SIZEOF32_RUNEENTRY;
++ _RuneEntry *rp;
+
++ if (extra < 0) {
++ saverr = errno;
++ free(data);
++ errno = saverr;
++ return (NULL);
++ }
++ if ((data = (struct __xlocale_st_runelocale *)reallocf(data, sizeof(struct __xlocale_st_runelocale) +
++ count * sizeof(_RuneEntry) + extra)) == NULL)
++ return (NULL);
++ rl = &data->_CurrentRuneLocale;
++ rl->__variable = rl + 1;
++ rp = (_RuneEntry *)rl->__variable;
++ for (x = 0; x < count; x++, rp++)
++ if (fread(rp, SIZEOF32_RUNEENTRY, 1, fp) != 1) {
++ saverr = errno;
++ free(data);
++ errno = saverr;
++ return (NULL);
++ }
++ if (extra > 0 && fread(rp, extra, 1, fp) != 1) {
++ saverr = errno;
++ free(data);
++ errno = saverr;
++ return (NULL);
++ }
++ lastp = (char *)rp + extra;
++ }
++#endif /* __LP64__ */
+ rl->__runetype_ext.__ranges = (_RuneEntry *)rl->__variable;
+ rl->__variable = rl->__runetype_ext.__ranges +
+ rl->__runetype_ext.__nranges;
+@@ -142,8 +269,10 @@
+ for (x = 0; x < rl->__runetype_ext.__nranges; ++x) {
+ rr = rl->__runetype_ext.__ranges;
+
++#if __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN
+ rr[x].__min = ntohl(rr[x].__min);
+ rr[x].__max = ntohl(rr[x].__max);
++#endif /* __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN */
+ if ((rr[x].__map = ntohl(rr[x].__map)) == 0) {
+ int len = rr[x].__max - rr[x].__min + 1;
+ rr[x].__types = rl->__variable;
+@@ -153,12 +282,15 @@
+ errno = EFTYPE;
+ return (NULL);
+ }
++#if __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN
+ while (len-- > 0)
+ rr[x].__types[len] = ntohl(rr[x].__types[len]);
++#endif /* __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN */
+ } else
+ rr[x].__types = 0;
+ }
+
++#if __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN
+ for (x = 0; x < rl->__maplower_ext.__nranges; ++x) {
+ rr = rl->__maplower_ext.__ranges;
+
+@@ -174,6 +306,7 @@
+ rr[x].__max = ntohl(rr[x].__max);
+ rr[x].__map = ntohl(rr[x].__map);
+ }
++#endif /* __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN */
+ if (((char *)rl->__variable) + rl->__variable_len > (char *)lastp) {
+ free(data);
+ errno = EFTYPE;
+@@ -195,5 +328,7 @@
+ if (!rl->__mapupper_ext.__nranges)
+ rl->__mapupper_ext.__ranges = 0;
+
+- return (rl);
++ data->__datasize = lastp - (void *)data;
++ return (data);
+ }
++#endif /* !RUNEOFF32 */
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/runetype.c,v 1.8 2002/08/21 16:19:56 mike Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/runetype.c,v 1.11 2004/07/29 06:16:19 tjr Exp $");
#include <stdio.h>
-#include <rune.h>
+#include <runetype.h>
unsigned long
___runetype(c)
__ct_rune_t c;
{
- int x;
- _RuneRange *rr = &_CurrentRuneLocale->runetype_ext;
- _RuneEntry *re = rr->ranges;
+ size_t lim;
+ _RuneRange *rr = &_CurrentRuneLocale->__runetype_ext;
+ _RuneEntry *base, *re;
if (c < 0 || c == EOF)
return(0L);
- for (x = 0; x < rr->nranges; ++x, ++re) {
- if (c < re->min)
- return(0L);
- if (c <= re->max) {
- if (re->types)
- return(re->types[c - re->min]);
+ /* Binary search -- see bsearch.c for explanation. */
+ base = rr->__ranges;
+ for (lim = rr->__nranges; lim != 0; lim >>= 1) {
+ re = base + (lim >> 1);
+ if (re->__min <= c && c <= re->__max) {
+ if (re->__types)
+ return(re->__types[c - re->__min]);
else
- return(re->map);
+ return(re->__map);
+ } else if (c > re->__max) {
+ base = re + 1;
+ lim--;
}
}
---- runetype.c.orig Tue May 20 15:21:44 2003
-+++ runetype.c Tue Jun 17 17:50:43 2003
-@@ -39,27 +39,39 @@
+--- runetype.c.orig 2004-11-25 11:38:19.000000000 -0800
++++ runetype.c 2005-02-16 22:43:53.000000000 -0800
+@@ -37,20 +37,25 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/runetype.c,v 1.11 2004/07/29 06:16:19 tjr Exp $");
- #include <stdio.h>
- #include <rune.h>
-+#include <stdlib.h>
-+
-+__private_extern__ int
-+__compRuneEntry(const void *rune, const void *range)
-+{
-+ __ct_rune_t c = *(__ct_rune_t *)rune;
-+ _RuneEntry *re = (_RuneEntry *)range;
++#include "xlocale_private.h"
+
-+ if (c < re->min)
-+ return(-1);
-+ if (c > re->max)
-+ return(1);
-+ return(0);
-+}
+ #include <stdio.h>
+ #include <runetype.h>
unsigned long
- ___runetype(c)
+-___runetype(c)
++___runetype_l(c, loc)
__ct_rune_t c;
++ locale_t loc;
{
-- int x;
- _RuneRange *rr = &_CurrentRuneLocale->runetype_ext;
-- _RuneEntry *re = rr->ranges;
-+ _RuneEntry *re;
+ size_t lim;
+- _RuneRange *rr = &_CurrentRuneLocale->__runetype_ext;
++ _RuneRange *rr;
+ _RuneEntry *base, *re;
if (c < 0 || c == EOF)
return(0L);
-- for (x = 0; x < rr->nranges; ++x, ++re) {
-- if (c < re->min)
-- return(0L);
-- if (c <= re->max) {
-- if (re->types)
-- return(re->types[c - re->min]);
-- else
-- return(re->map);
-- }
-+ re = (_RuneEntry *)bsearch(&c, rr->ranges, rr->nranges,
-+ sizeof(_RuneEntry), __compRuneEntry);
-+
-+ if (re) {
-+ if (re->types)
-+ return(re->types[c - re->min]);
-+ else
-+ return(re->map);
- }
++ NORMALIZE_LOCALE(loc);
++ rr = &loc->__lc_ctype->_CurrentRuneLocale.__runetype_ext;
+ /* Binary search -- see bsearch.c for explanation. */
+ base = rr->__ranges;
+ for (lim = rr->__nranges; lim != 0; lim >>= 1) {
+@@ -68,3 +73,10 @@
return(0L);
+ }
++
++unsigned long
++___runetype(c)
++ __ct_rune_t c;
++{
++ return ___runetype_l(c, __current_locale());
++}
+++ /dev/null
-/*-
- * Copyright (c) 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Paul Borman at Krystal Technologies.
- *
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/setinvalidrune.c,v 1.3 2002/09/24 09:25:37 tjr Exp $");
-
-#include <rune.h>
-
-__warn_references(setinvalidrune, "warning: setinvalidrune() is deprecated. See setinvalidrune(3).");
-void
-setinvalidrune(ir)
- rune_t ir;
-{
- _INVALID_RUNE = ir;
-}
.\" SUCH DAMAGE.
.\"
.\" @(#)setlocale.3 8.1 (Berkeley) 6/9/93
-.\" $FreeBSD: src/lib/libc/locale/setlocale.3,v 1.26 2003/03/20 08:13:34 ache Exp $
+.\" $FreeBSD: src/lib/libc/locale/setlocale.3,v 1.33 2004/10/17 06:51:50 tjr Exp $
.\"
-.Dd October 5, 2002
+.Dd November 21, 2003
.Dt SETLOCALE 3
.Os
.Sh NAME
-.Nm setlocale ,
-.Nm localeconv
+.Nm setlocale
.Nd natural language formatting for C
.Sh LIBRARY
.Lb libc
.In locale.h
.Ft char *
.Fn setlocale "int category" "const char *locale"
-.Ft struct lconv *
-.Fn localeconv "void"
.Sh DESCRIPTION
The
.Fn setlocale
Each such style is called a
.Sq locale
and is invoked using an appropriate name passed as a C string.
-The
-.Fn localeconv
-routine returns the current locale's parameters
-for formatting numbers.
.Pp
The
.Fn setlocale
.Fn strxfrm .
.It Dv LC_CTYPE
Set a locale for the
-.Xr ctype 3 ,
-.Xr mbrune 3 ,
-.Xr multibyte 3
+.Xr ctype 3
and
-.Xr rune 3
+.Xr multibyte 3
functions.
This controls recognition of upper and lower case,
alphabetic or non-alphabetic characters,
-and so on. The real work is done by the
-.Fn setrunelocale
-function.
+and so on.
.It Dv LC_MESSAGES
Set a locale for message catalogs, see
.Xr catopen 3
The only function in the library that sets the locale is
.Fn setlocale ;
the locale is never changed as a side effect of some other routine.
-.Pp
-The
-.Fn localeconv
-function returns a pointer to a structure
-which provides parameters for formatting numbers,
-especially currency values:
-.Bd -literal -offset indent
-struct lconv {
- char *decimal_point;
- char *thousands_sep;
- char *grouping;
- char *int_curr_symbol;
- char *currency_symbol;
- char *mon_decimal_point;
- char *mon_thousands_sep;
- char *mon_grouping;
- char *positive_sign;
- char *negative_sign;
- char int_frac_digits;
- char frac_digits;
- char p_cs_precedes;
- char p_sep_by_space;
- char n_cs_precedes;
- char n_sep_by_space;
- char p_sign_posn;
- char n_sign_posn;
- char int_p_cs_precedes;
- char int_n_cs_precedes;
- char int_p_sep_by_space;
- char int_n_sep_by_space;
- char int_p_sign_posn;
- char int_n_sign_posn;
-};
-.Ed
-.Pp
-The individual fields have the following meanings:
-.Pp
-.Bl -tag -width mon_decimal_point
-.It Fa decimal_point
-The decimal point character, except for currency values,
-can't be the empty string.
-.It Fa thousands_sep
-The separator between groups of digits
-before the decimal point, except for currency values.
-.It Fa grouping
-The sizes of the groups of digits, except for currency values.
-This is a pointer to a vector of integers, each of size
-.Va char ,
-representing group size from low order digit groups
-to high order (right to left).
-The list may be terminated with 0 or
-.Dv CHAR_MAX .
-If the list is terminated with 0,
-the last group size before the 0 is repeated to account for all the digits.
-If the list is terminated with
-.Dv CHAR_MAX ,
-no more grouping is performed.
-.It Fa int_curr_symbol
-The standardized international currency symbol.
-.It Fa currency_symbol
-The local currency symbol.
-.It Fa mon_decimal_point
-The decimal point character for currency values.
-.It Fa mon_thousands_sep
-The separator for digit groups in currency values.
-.It Fa mon_grouping
-Like
-.Fa grouping
-but for currency values.
-.It Fa positive_sign
-The character used to denote nonnegative currency values,
-usually the empty string.
-.It Fa negative_sign
-The character used to denote negative currency values,
-usually a minus sign.
-.It Fa int_frac_digits
-The number of digits after the decimal point
-in an international-style currency value.
-.It Fa frac_digits
-The number of digits after the decimal point
-in the local style for currency values.
-.It Fa p_cs_precedes
-1 if the currency symbol precedes the currency value
-for nonnegative values, 0 if it follows.
-.It Fa p_sep_by_space
-1 if a space is inserted between the currency symbol
-and the currency value for nonnegative values, 0 otherwise.
-.It Fa n_cs_precedes
-Like
-.Fa p_cs_precedes
-but for negative values.
-.It Fa n_sep_by_space
-Like
-.Fa p_sep_by_space
-but for negative values.
-.It Fa p_sign_posn
-The location of the
-.Fa positive_sign
-with respect to a nonnegative quantity and the
-.Fa currency_symbol ,
-coded as follows:
-.Bl -tag -width 3n -compact
-.It Li 0
-Parentheses around the entire string.
-.It Li 1
-Before the string.
-.It Li 2
-After the string.
-.It Li 3
-Just before
-.Fa currency_symbol .
-.It Li 4
-Just after
-.Fa currency_symbol .
-.El
-.It Fa n_sign_posn
-Like
-.Fa p_sign_posn
-but for negative currency values.
-.It Fa int_p_cs_precedes
-Same as
-.Fa p_cs_precedes ,
-but for internationally formatted monetary quantities.
-.It Fa int_n_cs_precedes
-Same as
-.Fa n_cs_precedes ,
-but for internationally formatted monetary quantities.
-.It Fa int_p_sep_by_space
-Same as
-.Fa p_sep_by_space ,
-but for internationally formatted monetary quantities.
-.It Fa int_n_sep_by_space
-Same as
-.Fa n_sep_by_space ,
-but for internationally formatted monetary quantities.
-.It Fa int_p_sign_posn
-Same as
-.Fa p_sign_posn ,
-but for internationally formatted monetary quantities.
-.It Fa int_n_sign_posn
-Same as
-.Fa n_sign_posn ,
-but for internationally formatted monetary quantities.
-.El
-.Pp
-Unless mentioned above,
-an empty string as a value for a field
-indicates a zero length result or
-a value that is not in the current locale.
-A
-.Dv CHAR_MAX
-result similarly denotes an unavailable value.
.Sh RETURN VALUES
Upon successful completion,
.Fn setlocale
and
.Fa locale
makes no sense.
-The
-.Fn localeconv
-function returns a pointer to a static object
-which may be altered by later calls to
-.Fn setlocale
-or
-.Fn localeconv .
.Sh ERRORS
No errors are defined.
.Sh FILES
.Xr mklocale 1 ,
.Xr catopen 3 ,
.Xr ctype 3 ,
-.Xr mbrune 3 ,
+.Xr localeconv 3 ,
.Xr multibyte 3 ,
-.Xr rune 3 ,
.Xr strcoll 3 ,
.Xr strxfrm 3 ,
-.Xr euc 4 ,
-.Xr utf2 4 ,
-.Xr utf8 5
+.Xr euc 5 ,
+.Xr utf8 5 ,
+.Xr environ 7
.Sh STANDARDS
The
.Fn setlocale
-and
-.Fn localeconv
-functions conform to
+function conforms to
.St -isoC-99 .
.Sh HISTORY
The
.Fn setlocale
-and
-.Fn localeconv
-functions first appeared in
+function first appeared in
.Bx 4.4 .
static char sccsid[] = "@(#)setlocale.c 8.1 (Berkeley) 7/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/setlocale.c,v 1.41 2002/08/08 05:51:54 ache Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/setlocale.c,v 1.50 2004/01/31 19:15:32 ache Exp $");
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <limits.h>
#include <locale.h>
-#include <rune.h>
+#include <paths.h> /* for _PATH_LOCALE */
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
"C",
};
+/*
+ * Path to locale storage directory
+ */
+char *_PathLocale;
+
/*
* The locales we are going to try and load
*/
static char current_locale_string[_LC_LAST * (ENCODING_LEN + 1/*"/"*/ + 1)];
static char *currentlocale(void);
-static int wrap_setrunelocale(const char *);
static char *loadlocale(int);
+static const char *__get_locale_env(int);
char *
setlocale(category, locale)
const char *locale;
{
int i, j, len, saverr;
- char *env, *r;
+ const char *env, *r;
if (category < LC_ALL || category >= _LC_LAST) {
errno = EINVAL;
* Now go fill up new_categories from the locale argument
*/
if (!*locale) {
- env = getenv("LC_ALL");
-
- if (category != LC_ALL && (env == NULL || !*env))
- env = getenv(categories[category]);
-
- if (env == NULL || !*env)
- env = getenv("LANG");
-
- if (env == NULL || !*env)
- env = "C";
-
- if (strlen(env) > ENCODING_LEN) {
- errno = EINVAL;
- return (NULL);
- }
- (void)strcpy(new_categories[category], env);
-
if (category == LC_ALL) {
for (i = 1; i < _LC_LAST; ++i) {
- if ((env = getenv(categories[i])) == NULL ||
- !*env)
- env = new_categories[LC_ALL];
- else if (strlen(env) > ENCODING_LEN) {
+ env = __get_locale_env(i);
+ if (strlen(env) > ENCODING_LEN) {
errno = EINVAL;
return (NULL);
}
(void)strcpy(new_categories[i], env);
}
+ } else {
+ env = __get_locale_env(category);
+ if (strlen(env) > ENCODING_LEN) {
+ errno = EINVAL;
+ return (NULL);
+ }
+ (void)strcpy(new_categories[category], env);
}
} else if (category != LC_ALL) {
if (strlen(locale) > ENCODING_LEN) {
(void)strlcpy(new_categories[i], locale,
len + 1);
i++;
+ while (*r == '/')
+ r++;
locale = r;
- while (*locale == '/')
- ++locale;
- while (*++r && *r != '/')
- ;
+ while (*r && *r != '/')
+ r++;
} while (*locale);
while (i < _LC_LAST) {
(void)strcpy(new_categories[i],
return (current_locale_string);
}
-static int
-wrap_setrunelocale(const char *locale)
-{
- int ret = setrunelocale((char *)locale);
-
- if (ret != 0) {
- errno = ret;
- return (_LDP_ERROR);
- }
- return (_LDP_LOADED);
-}
-
static char *
loadlocale(category)
int category;
char *new = new_categories[category];
char *old = current_categories[category];
int (*func)(const char *);
+ int saved_errno;
if ((new[0] == '.' &&
(new[1] == '\0' || (new[1] == '.' && new[2] == '\0'))) ||
return (NULL);
}
- if (_PathLocale == NULL) {
- char *p = getenv("PATH_LOCALE");
-
- if (p != NULL
-#ifndef __NETBSD_SYSCALLS
- && !issetugid()
-#endif
- ) {
- if (strlen(p) + 1/*"/"*/ + ENCODING_LEN +
- 1/*"/"*/ + CATEGORY_LEN >= PATH_MAX) {
- errno = ENAMETOOLONG;
- return (NULL);
- }
- _PathLocale = strdup(p);
- if (_PathLocale == NULL) {
- errno = ENOMEM;
- return (NULL);
- }
- } else
- _PathLocale = _PATH_LOCALE;
- }
+ saved_errno = errno;
+ errno = __detect_path_locale();
+ if (errno != 0)
+ return (NULL);
+ errno = saved_errno;
switch (category) {
case LC_CTYPE:
- func = wrap_setrunelocale;
+ func = __wrap_setrunelocale;
break;
case LC_COLLATE:
func = __collate_load_tables;
return (NULL);
}
+static const char *
+__get_locale_env(category)
+ int category;
+{
+ const char *env;
+
+ /* 1. check LC_ALL. */
+ env = getenv(categories[0]);
+
+ /* 2. check LC_* */
+ if (env == NULL || !*env)
+ env = getenv(categories[category]);
+
+ /* 3. check LANG */
+ if (env == NULL || !*env)
+ env = getenv("LANG");
+
+ /* 4. if none is set, fall to "C" */
+ if (env == NULL || !*env)
+ env = "C";
+
+ return (env);
+}
+
+/*
+ * Detect locale storage location and store its value to _PathLocale variable
+ */
+int
+__detect_path_locale(void)
+{
+ if (_PathLocale == NULL) {
+ char *p = getenv("PATH_LOCALE");
+
+ if (p != NULL && !issetugid()) {
+ if (strlen(p) + 1/*"/"*/ + ENCODING_LEN +
+ 1/*"/"*/ + CATEGORY_LEN >= PATH_MAX)
+ return (ENAMETOOLONG);
+ _PathLocale = strdup(p);
+ if (_PathLocale == NULL)
+ return (errno == 0 ? ENOMEM : errno);
+ } else
+ _PathLocale = _PATH_LOCALE;
+ }
+ return (0);
+}
+
---- setlocale.c.orig Wed Aug 7 22:51:54 2002
-+++ setlocale.c Sat May 3 14:15:25 2003
-@@ -56,7 +56,7 @@
+--- setlocale.c.orig 2004-11-25 11:38:19.000000000 -0800
++++ setlocale.c 2005-02-17 12:42:40.000000000 -0800
+@@ -41,6 +41,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/setlocale.c,v 1.50 2004/01/31 19:15:32 ache Exp $");
+
++#include "xlocale_private.h"
++
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <errno.h>
+@@ -56,7 +58,7 @@
#include "lmessages.h" /* for __messages_load_locale() */
#include "setlocale.h"
#include "ldpart.h"
/*
* Category names for getenv()
+@@ -99,7 +101,7 @@
+
+ static char *currentlocale(void);
+ static char *loadlocale(int);
+-static const char *__get_locale_env(int);
++__private_extern__ const char *__get_locale_env(int);
+
+ char *
+ setlocale(category, locale)
+@@ -237,7 +239,7 @@
+ {
+ char *new = new_categories[category];
+ char *old = current_categories[category];
+- int (*func)(const char *);
++ int (*func)(const char *, locale_t);
+ int saved_errno;
+
+ if ((new[0] == '.' &&
+@@ -280,7 +282,7 @@
+ if (strcmp(new, old) == 0)
+ return (old);
+
+- if (func(new) != _LDP_ERROR) {
++ if (func(new, &__global_locale) != _LDP_ERROR) {
+ (void)strcpy(old, new);
+ return (old);
+ }
+@@ -288,7 +290,7 @@
+ return (NULL);
+ }
+
+-static const char *
++__private_extern__ const char *
+ __get_locale_env(category)
+ int category;
+ {
+@@ -315,7 +317,7 @@
+ /*
+ * Detect locale storage location and store its value to _PathLocale variable
+ */
+-int
++__private_extern__ int
+ __detect_path_locale(void)
+ {
+ if (_PathLocale == NULL) {
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: src/lib/libc/locale/setlocale.h,v 1.4 2001/12/20 18:28:52 phantom Exp $
+ * $FreeBSD: src/lib/libc/locale/setlocale.h,v 1.6 2003/07/06 02:03:37 ache Exp $
*/
#ifndef _SETLOCALE_H_
extern char *_PathLocale;
+int __detect_path_locale(void);
+int __wrap_setrunelocale(const char *);
+
#endif /* !_SETLOCALE_H_ */
--- /dev/null
+--- setlocale.h.orig 2004-11-25 11:38:19.000000000 -0800
++++ setlocale.h 2005-02-19 14:45:55.000000000 -0800
+@@ -29,12 +29,14 @@
+ #ifndef _SETLOCALE_H_
+ #define _SETLOCALE_H_
+
++#include <xlocale.h>
++
+ #define ENCODING_LEN 31
+ #define CATEGORY_LEN 11
+
+ extern char *_PathLocale;
+
+ int __detect_path_locale(void);
+-int __wrap_setrunelocale(const char *);
++int __wrap_setrunelocale(const char *, locale_t);
+
+ #endif /* !_SETLOCALE_H_ */
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/setrunelocale.c,v 1.26 2002/10/10 22:56:18 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/setrunelocale.c,v 1.44 2004/10/18 02:06:18 ache Exp $");
-#include <rune.h>
+#include <runetype.h>
#include <errno.h>
#include <limits.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <wchar.h>
+#include "ldpart.h"
+#include "mblocal.h"
#include "setlocale.h"
extern int _none_init(_RuneLocale *);
-extern int _UTF2_init(_RuneLocale *);
extern int _UTF8_init(_RuneLocale *);
extern int _EUC_init(_RuneLocale *);
+extern int _GB18030_init(_RuneLocale *);
+extern int _GB2312_init(_RuneLocale *);
+extern int _GBK_init(_RuneLocale *);
extern int _BIG5_init(_RuneLocale *);
extern int _MSKanji_init(_RuneLocale *);
-extern _RuneLocale *_Read_RuneMagi(FILE *);
+extern _RuneLocale *_Read_RuneMagi(FILE *);
-int
-setrunelocale(char *encoding)
+static int __setrunelocale(const char *);
+
+static int
+__setrunelocale(const char *encoding)
{
FILE *fp;
char name[PATH_MAX];
static char ctype_encoding[ENCODING_LEN + 1];
static _RuneLocale *CachedRuneLocale;
static int Cached__mb_cur_max;
-
- if (!encoding || !*encoding || strlen(encoding) > ENCODING_LEN ||
- (encoding[0] == '.' &&
- (encoding[1] == '\0' ||
- (encoding[1] == '.' && encoding[2] == '\0'))) ||
- strchr(encoding, '/') != NULL)
- return (EINVAL);
+ static size_t (*Cached__mbrtowc)(wchar_t * __restrict,
+ const char * __restrict, size_t, mbstate_t * __restrict);
+ static size_t (*Cached__wcrtomb)(char * __restrict, wchar_t,
+ mbstate_t * __restrict);
+ static int (*Cached__mbsinit)(const mbstate_t *);
+ static size_t (*Cached__mbsnrtowcs)(wchar_t * __restrict,
+ const char ** __restrict, size_t, size_t, mbstate_t * __restrict);
+ static size_t (*Cached__wcsnrtombs)(char * __restrict,
+ const wchar_t ** __restrict, size_t, size_t,
+ mbstate_t * __restrict);
/*
* The "C" and "POSIX" locale are always here.
if (strcmp(encoding, "C") == 0 || strcmp(encoding, "POSIX") == 0) {
_CurrentRuneLocale = &_DefaultRuneLocale;
__mb_cur_max = 1;
+ __mbrtowc = _none_mbrtowc;
+ __mbsinit = _none_mbsinit;
+ __mbsnrtowcs = _none_mbsnrtowcs;
+ __wcrtomb = _none_wcrtomb;
+ __wcsnrtombs = _none_wcsnrtombs;
return (0);
}
strcmp(encoding, ctype_encoding) == 0) {
_CurrentRuneLocale = CachedRuneLocale;
__mb_cur_max = Cached__mb_cur_max;
+ __mbrtowc = Cached__mbrtowc;
+ __mbsinit = Cached__mbsinit;
+ __mbsnrtowcs = Cached__mbsnrtowcs;
+ __wcrtomb = Cached__wcrtomb;
+ __wcsnrtombs = Cached__wcsnrtombs;
return (0);
}
/*
* Slurp the locale file into the cache.
*/
- if (_PathLocale == NULL) {
- char *p = getenv("PATH_LOCALE");
-
- if (p != NULL
-#ifndef __NETBSD_SYSCALLS
- && !issetugid()
-#endif
- ) {
- if (strlen(p) + 1/*"/"*/ + ENCODING_LEN +
- 1/*"/"*/ + CATEGORY_LEN >= PATH_MAX)
- return (ENAMETOOLONG);
- _PathLocale = strdup(p);
- if (_PathLocale == NULL)
- return (errno == 0 ? ENOMEM : errno);
- } else
- _PathLocale = _PATH_LOCALE;
- }
- /* Range checking not needed, encoding length already checked above */
+
+ /* Range checking not needed, encoding length already checked before */
(void) strcpy(name, _PathLocale);
(void) strcat(name, "/");
(void) strcat(name, encoding);
}
(void)fclose(fp);
- if (strcmp(rl->encoding, "NONE") == 0)
+ __mbrtowc = NULL;
+ __mbsinit = NULL;
+ __mbsnrtowcs = __mbsnrtowcs_std;
+ __wcrtomb = NULL;
+ __wcsnrtombs = __wcsnrtombs_std;
+ rl->__sputrune = NULL;
+ rl->__sgetrune = NULL;
+ if (strcmp(rl->__encoding, "NONE") == 0)
ret = _none_init(rl);
- else if (strcmp(rl->encoding, "UTF2") == 0)
- ret = _UTF2_init(rl);
- else if (strcmp(rl->encoding, "UTF-8") == 0)
+ else if (strcmp(rl->__encoding, "UTF-8") == 0)
ret = _UTF8_init(rl);
- else if (strcmp(rl->encoding, "EUC") == 0)
+ else if (strcmp(rl->__encoding, "EUC") == 0)
ret = _EUC_init(rl);
- else if (strcmp(rl->encoding, "BIG5") == 0)
+ else if (strcmp(rl->__encoding, "GB18030") == 0)
+ ret = _GB18030_init(rl);
+ else if (strcmp(rl->__encoding, "GB2312") == 0)
+ ret = _GB2312_init(rl);
+ else if (strcmp(rl->__encoding, "GBK") == 0)
+ ret = _GBK_init(rl);
+ else if (strcmp(rl->__encoding, "BIG5") == 0)
ret = _BIG5_init(rl);
- else if (strcmp(rl->encoding, "MSKanji") == 0)
+ else if (strcmp(rl->__encoding, "MSKanji") == 0)
ret = _MSKanji_init(rl);
else
ret = EFTYPE;
if (ret == 0) {
if (CachedRuneLocale != NULL) {
/* See euc.c */
- if (strcmp(CachedRuneLocale->encoding, "EUC") == 0)
- free(CachedRuneLocale->variable);
+ if (strcmp(CachedRuneLocale->__encoding, "EUC") == 0)
+ free(CachedRuneLocale->__variable);
free(CachedRuneLocale);
}
CachedRuneLocale = _CurrentRuneLocale;
Cached__mb_cur_max = __mb_cur_max;
+ Cached__mbrtowc = __mbrtowc;
+ Cached__mbsinit = __mbsinit;
+ Cached__mbsnrtowcs = __mbsnrtowcs;
+ Cached__wcrtomb = __wcrtomb;
+ Cached__wcsnrtombs = __wcsnrtombs;
(void)strcpy(ctype_encoding, encoding);
} else
free(rl);
return (ret);
}
+int
+__wrap_setrunelocale(const char *locale)
+{
+ int ret = __setrunelocale(locale);
+
+ if (ret != 0) {
+ errno = ret;
+ return (_LDP_ERROR);
+ }
+ return (_LDP_LOADED);
+}
+
--- /dev/null
+--- setrunelocale.c.orig 2004-11-25 11:38:19.000000000 -0800
++++ setrunelocale.c 2005-02-17 10:00:02.000000000 -0800
+@@ -37,6 +37,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/setrunelocale.c,v 1.44 2004/10/18 02:06:18 ache Exp $");
+
++#include "xlocale_private.h"
++
+ #include <runetype.h>
+ #include <errno.h>
+ #include <limits.h>
+@@ -49,50 +51,43 @@
+ #include "mblocal.h"
+ #include "setlocale.h"
+
+-extern int _none_init(_RuneLocale *);
+-extern int _UTF8_init(_RuneLocale *);
+-extern int _EUC_init(_RuneLocale *);
+-extern int _GB18030_init(_RuneLocale *);
+-extern int _GB2312_init(_RuneLocale *);
+-extern int _GBK_init(_RuneLocale *);
+-extern int _BIG5_init(_RuneLocale *);
+-extern int _MSKanji_init(_RuneLocale *);
+-extern _RuneLocale *_Read_RuneMagi(FILE *);
+-
+-static int __setrunelocale(const char *);
++extern int _none_init(struct __xlocale_st_runelocale *);
++extern int _UTF8_init(struct __xlocale_st_runelocale *);
++extern int _EUC_init(struct __xlocale_st_runelocale *);
++extern int _GB18030_init(struct __xlocale_st_runelocale *);
++extern int _GB2312_init(struct __xlocale_st_runelocale *);
++extern int _GBK_init(struct __xlocale_st_runelocale *);
++extern int _BIG5_init(struct __xlocale_st_runelocale *);
++extern int _MSKanji_init(struct __xlocale_st_runelocale *);
++extern int _UTF2_init(struct __xlocale_st_runelocale *); /* deprecated */
++extern struct __xlocale_st_runelocale *_Read_RuneMagi(FILE *);
++
++/* depreciated interfaces */
++rune_t sgetrune(const char *, size_t, char const **);
++int sputrune(rune_t, char *, size_t, char **);
+
+-static int
+-__setrunelocale(const char *encoding)
++__private_extern__ int
++__setrunelocale(const char *encoding, locale_t loc)
+ {
+ FILE *fp;
+ char name[PATH_MAX];
++ struct __xlocale_st_runelocale *xrl;
+ _RuneLocale *rl;
+ int saverr, ret;
+- static char ctype_encoding[ENCODING_LEN + 1];
+- static _RuneLocale *CachedRuneLocale;
+- static int Cached__mb_cur_max;
+- static size_t (*Cached__mbrtowc)(wchar_t * __restrict,
+- const char * __restrict, size_t, mbstate_t * __restrict);
+- static size_t (*Cached__wcrtomb)(char * __restrict, wchar_t,
+- mbstate_t * __restrict);
+- static int (*Cached__mbsinit)(const mbstate_t *);
+- static size_t (*Cached__mbsnrtowcs)(wchar_t * __restrict,
+- const char ** __restrict, size_t, size_t, mbstate_t * __restrict);
+- static size_t (*Cached__wcsnrtombs)(char * __restrict,
+- const wchar_t ** __restrict, size_t, size_t,
+- mbstate_t * __restrict);
++ static struct __xlocale_st_runelocale *CachedRuneLocale;
++ extern int __mb_cur_max;
+
+ /*
+ * The "C" and "POSIX" locale are always here.
+ */
+ if (strcmp(encoding, "C") == 0 || strcmp(encoding, "POSIX") == 0) {
+- _CurrentRuneLocale = &_DefaultRuneLocale;
+- __mb_cur_max = 1;
+- __mbrtowc = _none_mbrtowc;
+- __mbsinit = _none_mbsinit;
+- __mbsnrtowcs = _none_mbsnrtowcs;
+- __wcrtomb = _none_wcrtomb;
+- __wcsnrtombs = _none_wcsnrtombs;
++ XL_RELEASE(loc->__lc_ctype);
++ loc->__lc_ctype = &_DefaultRuneXLocale;
++ /* no need to retain _DefaultRuneXLocale */
++ if (loc == &__global_locale) {
++ _CurrentRuneLocale = &loc->__lc_ctype->_CurrentRuneLocale;
++ __mb_cur_max = loc->__lc_ctype->__mb_cur_max;
++ }
+ return (0);
+ }
+
+@@ -100,14 +95,14 @@
+ * If the locale name is the same as our cache, use the cache.
+ */
+ if (CachedRuneLocale != NULL &&
+- strcmp(encoding, ctype_encoding) == 0) {
+- _CurrentRuneLocale = CachedRuneLocale;
+- __mb_cur_max = Cached__mb_cur_max;
+- __mbrtowc = Cached__mbrtowc;
+- __mbsinit = Cached__mbsinit;
+- __mbsnrtowcs = Cached__mbsnrtowcs;
+- __wcrtomb = Cached__wcrtomb;
+- __wcsnrtombs = Cached__wcsnrtombs;
++ strcmp(encoding, CachedRuneLocale->__ctype_encoding) == 0) {
++ XL_RELEASE(loc->__lc_ctype);
++ loc->__lc_ctype = CachedRuneLocale;
++ XL_RETAIN(loc->__lc_ctype);
++ if (loc == &__global_locale) {
++ _CurrentRuneLocale = &loc->__lc_ctype->_CurrentRuneLocale;
++ __mb_cur_max = loc->__lc_ctype->__mb_cur_max;
++ }
+ return (0);
+ }
+
+@@ -124,63 +119,72 @@
+ if ((fp = fopen(name, "r")) == NULL)
+ return (errno == 0 ? ENOENT : errno);
+
+- if ((rl = _Read_RuneMagi(fp)) == NULL) {
++ if ((xrl = _Read_RuneMagi(fp)) == NULL) {
+ saverr = (errno == 0 ? EFTYPE : errno);
+ (void)fclose(fp);
+ return (saverr);
+ }
+ (void)fclose(fp);
+
+- __mbrtowc = NULL;
+- __mbsinit = NULL;
+- __mbsnrtowcs = __mbsnrtowcs_std;
+- __wcrtomb = NULL;
+- __wcsnrtombs = __wcsnrtombs_std;
+- rl->__sputrune = NULL;
+- rl->__sgetrune = NULL;
++ xrl->__mbrtowc = NULL;
++ xrl->__mbsinit = NULL;
++ xrl->__mbsnrtowcs = __mbsnrtowcs_std;
++ xrl->__wcrtomb = NULL;
++ xrl->__wcsnrtombs = __wcsnrtombs_std;
++
++ rl = &xrl->_CurrentRuneLocale;
++
++ /* provide backwards compatibility (depreciated interface) */
++ rl->__sputrune = sputrune;
++ rl->__sgetrune = sgetrune;
++
+ if (strcmp(rl->__encoding, "NONE") == 0)
+- ret = _none_init(rl);
++ ret = _none_init(xrl);
+ else if (strcmp(rl->__encoding, "UTF-8") == 0)
+- ret = _UTF8_init(rl);
++ ret = _UTF8_init(xrl);
+ else if (strcmp(rl->__encoding, "EUC") == 0)
+- ret = _EUC_init(rl);
++ ret = _EUC_init(xrl);
+ else if (strcmp(rl->__encoding, "GB18030") == 0)
+- ret = _GB18030_init(rl);
++ ret = _GB18030_init(xrl);
+ else if (strcmp(rl->__encoding, "GB2312") == 0)
+- ret = _GB2312_init(rl);
++ ret = _GB2312_init(xrl);
+ else if (strcmp(rl->__encoding, "GBK") == 0)
+- ret = _GBK_init(rl);
++ ret = _GBK_init(xrl);
+ else if (strcmp(rl->__encoding, "BIG5") == 0)
+- ret = _BIG5_init(rl);
++ ret = _BIG5_init(xrl);
+ else if (strcmp(rl->__encoding, "MSKanji") == 0)
+- ret = _MSKanji_init(rl);
++ ret = _MSKanji_init(xrl);
++ else if (strcmp(rl->__encoding, "UTF2") == 0)
++ ret = _UTF2_init(xrl);
+ else
+ ret = EFTYPE;
+ if (ret == 0) {
+- if (CachedRuneLocale != NULL) {
+- /* See euc.c */
+- if (strcmp(CachedRuneLocale->__encoding, "EUC") == 0)
+- free(CachedRuneLocale->__variable);
+- free(CachedRuneLocale);
++ (void)strcpy(xrl->__ctype_encoding, encoding);
++ XL_RELEASE(loc->__lc_ctype);
++ loc->__lc_ctype = xrl;
++ if (loc == &__global_locale) {
++ _CurrentRuneLocale = &loc->__lc_ctype->_CurrentRuneLocale;
++ __mb_cur_max = loc->__lc_ctype->__mb_cur_max;
+ }
+- CachedRuneLocale = _CurrentRuneLocale;
+- Cached__mb_cur_max = __mb_cur_max;
+- Cached__mbrtowc = __mbrtowc;
+- Cached__mbsinit = __mbsinit;
+- Cached__mbsnrtowcs = __mbsnrtowcs;
+- Cached__wcrtomb = __wcrtomb;
+- Cached__wcsnrtombs = __wcsnrtombs;
+- (void)strcpy(ctype_encoding, encoding);
++ XL_RELEASE(CachedRuneLocale);
++ CachedRuneLocale = xrl;
++ XL_RETAIN(CachedRuneLocale);
+ } else
+- free(rl);
++ XL_RELEASE(xrl);
+
+ return (ret);
+ }
+
+ int
+-__wrap_setrunelocale(const char *locale)
++setrunelocale(const char *encoding)
++{
++ return __setrunelocale(encoding, &__global_locale);
++}
++
++__private_extern__ int
++__wrap_setrunelocale(const char *locale, locale_t loc)
+ {
+- int ret = __setrunelocale(locale);
++ int ret = __setrunelocale(locale, loc);
+
+ if (ret != 0) {
+ errno = ret;
static char sccsid[] = "@(#)table.c 8.1 (Berkeley) 6/27/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/table.c,v 1.16 2002/03/22 21:52:18 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/table.c,v 1.26 2004/10/17 06:51:50 tjr Exp $");
#include <ctype.h>
-#include <rune.h>
-
-extern rune_t _none_sgetrune(const char *, size_t, char const **);
-extern int _none_sputrune(rune_t, char *, size_t, char **);
-extern int _none_init(char *, char **);
+#include <runetype.h>
+#include <wchar.h>
+#include "mblocal.h"
_RuneLocale _DefaultRuneLocale = {
_RUNE_MAGIC_1,
"NONE",
- _none_sgetrune,
- _none_sputrune,
+ NULL,
+ NULL,
0xFFFD,
{ /*00*/ _CTYPE_C,
_RuneLocale *_CurrentRuneLocale = &_DefaultRuneLocale;
int __mb_cur_max = 1;
-
-char *_PathLocale;
+size_t (*__mbrtowc)(wchar_t * __restrict, const char * __restrict, size_t,
+ mbstate_t * __restrict) = _none_mbrtowc;
+int (*__mbsinit)(const mbstate_t *) = _none_mbsinit;
+size_t (*__mbsnrtowcs)(wchar_t * __restrict, const char ** __restrict,
+ size_t, size_t, mbstate_t * __restrict) = _none_mbsnrtowcs;
+size_t (*__wcrtomb)(char * __restrict, wchar_t, mbstate_t * __restrict) =
+ _none_wcrtomb;
+size_t (*__wcsnrtombs)(char * __restrict, const wchar_t ** __restrict,
+ size_t, size_t, mbstate_t * __restrict) = _none_wcsnrtombs;
--- /dev/null
+--- table.c.orig 2004-11-25 11:38:19.000000000 -0800
++++ table.c 2005-02-20 16:31:30.000000000 -0800
+@@ -40,11 +40,14 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/table.c,v 1.26 2004/10/17 06:51:50 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <ctype.h>
+ #include <runetype.h>
+ #include <wchar.h>
+ #include "mblocal.h"
+
++/* _DefaultRuneLocale is depreciated; _DefaultRuneXLocale is used instead */
+ _RuneLocale _DefaultRuneLocale = {
+ _RUNE_MAGIC_1,
+ "NONE",
+@@ -249,15 +252,222 @@
+ },
+ };
+
+-_RuneLocale *_CurrentRuneLocale = &_DefaultRuneLocale;
++__private_extern__ struct __xlocale_st_runelocale _DefaultRuneXLocale = {
++ 0,
++ XPERMANENT,
++ "C",
++ 1,
++ _none_mbrtowc,
++ _none_mbsinit,
++ _none_mbsnrtowcs,
++ _none_wcrtomb,
++ _none_wcsnrtombs,
++ sizeof(struct __xlocale_st_runelocale),
++ {
++ _RUNE_MAGIC_1,
++ "NONE",
++ NULL,
++ NULL,
++ 0xFFFD,
++
++ { /*00*/ _CTYPE_C,
++ _CTYPE_C,
++ _CTYPE_C,
++ _CTYPE_C,
++ _CTYPE_C,
++ _CTYPE_C,
++ _CTYPE_C,
++ _CTYPE_C,
++ /*08*/ _CTYPE_C,
++ _CTYPE_C|_CTYPE_S|_CTYPE_B,
++ _CTYPE_C|_CTYPE_S,
++ _CTYPE_C|_CTYPE_S,
++ _CTYPE_C|_CTYPE_S,
++ _CTYPE_C|_CTYPE_S,
++ _CTYPE_C,
++ _CTYPE_C,
++ /*10*/ _CTYPE_C,
++ _CTYPE_C,
++ _CTYPE_C,
++ _CTYPE_C,
++ _CTYPE_C,
++ _CTYPE_C,
++ _CTYPE_C,
++ _CTYPE_C,
++ /*18*/ _CTYPE_C,
++ _CTYPE_C,
++ _CTYPE_C,
++ _CTYPE_C,
++ _CTYPE_C,
++ _CTYPE_C,
++ _CTYPE_C,
++ _CTYPE_C,
++ /*20*/ _CTYPE_S|_CTYPE_B|_CTYPE_R,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ /*28*/ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ /*30*/ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|0,
++ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|1,
++ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|2,
++ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|3,
++ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|4,
++ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|5,
++ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|6,
++ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|7,
++ /*38*/ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|8,
++ _CTYPE_D|_CTYPE_R|_CTYPE_G|_CTYPE_X|9,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ /*40*/ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|10,
++ _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|11,
++ _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|12,
++ _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|13,
++ _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|14,
++ _CTYPE_U|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|15,
++ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ /*48*/ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ /*50*/ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ /*58*/ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_U|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ /*60*/ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|10,
++ _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|11,
++ _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|12,
++ _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|13,
++ _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|14,
++ _CTYPE_L|_CTYPE_X|_CTYPE_R|_CTYPE_G|_CTYPE_A|15,
++ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ /*68*/ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ /*70*/ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ /*78*/ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_L|_CTYPE_R|_CTYPE_G|_CTYPE_A,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_P|_CTYPE_R|_CTYPE_G,
++ _CTYPE_C,
++ },
++ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
++ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
++ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
++ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
++ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
++ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
++ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
++ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
++ 0x40, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
++ 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
++ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
++ 'x', 'y', 'z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
++ 0x60, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
++ 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
++ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
++ 'x', 'y', 'z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
++ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
++ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
++ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
++ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
++ 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
++ 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
++ 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
++ 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
++ 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
++ 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
++ 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
++ 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
++ 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
++ 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
++ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
++ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
++ },
++ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
++ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
++ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
++ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
++ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
++ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
++ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
++ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
++ 0x40, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
++ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
++ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
++ 'X', 'Y', 'Z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
++ 0x60, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
++ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
++ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
++ 'X', 'Y', 'Z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
++ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
++ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
++ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
++ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
++ 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
++ 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
++ 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
++ 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
++ 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
++ 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
++ 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
++ 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
++ 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
++ 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
++ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
++ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
++ },
++ },
++};
++
++_RuneLocale *_CurrentRuneLocale = &_DefaultRuneXLocale._CurrentRuneLocale;
+
+ int __mb_cur_max = 1;
+-size_t (*__mbrtowc)(wchar_t * __restrict, const char * __restrict, size_t,
+- mbstate_t * __restrict) = _none_mbrtowc;
+-int (*__mbsinit)(const mbstate_t *) = _none_mbsinit;
+-size_t (*__mbsnrtowcs)(wchar_t * __restrict, const char ** __restrict,
+- size_t, size_t, mbstate_t * __restrict) = _none_mbsnrtowcs;
+-size_t (*__wcrtomb)(char * __restrict, wchar_t, mbstate_t * __restrict) =
+- _none_wcrtomb;
+-size_t (*__wcsnrtombs)(char * __restrict, const wchar_t ** __restrict,
+- size_t, size_t, mbstate_t * __restrict) = _none_wcsnrtombs;
.\" SUCH DAMAGE.
.\"
.\" @(#)tolower.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/locale/tolower.3,v 1.15 2002/10/03 11:14:00 tjr Exp $
+.\" $FreeBSD: src/lib/libc/locale/tolower.3,v 1.16 2004/08/21 07:37:08 tjr Exp $
.\"
-.Dd October 3, 2002
+.Dd August 21, 2004
.Dt TOLOWER 3
.Os
.Sh NAME
function returns the corresponding lower-case letter if there is
one; otherwise the argument is returned unchanged.
.Sh COMPATIBILITY
-Although
-.Fn tolower
-accepts arguments outside of the range of the
-.Vt "unsigned char"
-type in locales with large character sets,
-this is a
+The
.Bx 4.4
-extension and the
+extension of accepting arguments outside of the range of the
+.Vt "unsigned char"
+type in locales with large character sets is considered obsolete
+and may not be supported in future releases.
+The
.Fn towlower
-function should be used instead for maximum portability.
+function should be used instead.
.Sh SEE ALSO
.Xr ctype 3 ,
.Xr islower 3 ,
--- /dev/null
+--- tolower.3.orig Fri Mar 11 19:44:47 2005
++++ tolower.3 Fri Mar 11 19:52:07 2005
+@@ -40,7 +40,8 @@
+ .Dt TOLOWER 3
+ .Os
+ .Sh NAME
+-.Nm tolower
++.Nm tolower ,
++.Nm tolower_l
+ .Nd upper case to lower case letter conversion
+ .Sh LIBRARY
+ .Lb libc
+@@ -48,6 +49,9 @@
+ .In ctype.h
+ .Ft int
+ .Fn tolower "int c"
++.In xlocale.h
++.Ft int
++.Fn tolower_l "int c" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn tolower
+@@ -62,6 +66,14 @@
+ .Li unsigned char
+ or the value of
+ .Dv EOF .
++.Pp
++While the
++.Fn tolower
++function uses the current locale, the
++.Fn tolower_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ If the argument is an upper-case letter, the
+ .Fn tolower
+@@ -81,7 +93,8 @@
+ .Xr ctype 3 ,
+ .Xr islower 3 ,
+ .Xr multibyte 3 ,
+-.Xr towlower 3
++.Xr towlower 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn tolower
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/tolower.c,v 1.8 2002/08/21 16:19:56 mike Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/tolower.c,v 1.11 2004/07/29 06:16:19 tjr Exp $");
#include <stdio.h>
-#include <rune.h>
+#include <runetype.h>
__ct_rune_t
___tolower(c)
__ct_rune_t c;
{
- int x;
- _RuneRange *rr = &_CurrentRuneLocale->maplower_ext;
- _RuneEntry *re = rr->ranges;
+ size_t lim;
+ _RuneRange *rr = &_CurrentRuneLocale->__maplower_ext;
+ _RuneEntry *base, *re;
if (c < 0 || c == EOF)
return(c);
- for (x = 0; x < rr->nranges; ++x, ++re) {
- if (c < re->min)
- return(c);
- if (c <= re->max)
- return(re->map + c - re->min);
+ /* Binary search -- see bsearch.c for explanation. */
+ base = rr->__ranges;
+ for (lim = rr->__nranges; lim != 0; lim >>= 1) {
+ re = base + (lim >> 1);
+ if (re->__min <= c && c <= re->__max)
+ return (re->__map + c - re->__min);
+ else if (c > re->__max) {
+ base = re + 1;
+ lim--;
+ }
}
return(c);
---- tolower.c.orig Tue May 20 15:21:44 2003
-+++ tolower.c Tue Jun 17 17:45:56 2003
-@@ -39,6 +39,10 @@
+--- tolower.c.orig 2004-11-25 11:38:19.000000000 -0800
++++ tolower.c 2005-02-17 16:43:19.000000000 -0800
+@@ -37,20 +37,32 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/tolower.c,v 1.11 2004/07/29 06:16:19 tjr Exp $");
- #include <stdio.h>
- #include <rune.h>
-+#include <stdlib.h>
++#include "xlocale_private.h"
+
-+__private_extern__ int
-+__compRuneEntry(const void *, const void *); // from runetype.c
+ #include <stdio.h>
+ #include <runetype.h>
__ct_rune_t
- ___tolower(c)
-@@ -46,17 +50,16 @@
+-___tolower(c)
++___tolower_l(c, loc)
+ __ct_rune_t c;
++ locale_t loc;
{
- int x;
- _RuneRange *rr = &_CurrentRuneLocale->maplower_ext;
-- _RuneEntry *re = rr->ranges;
-+ _RuneEntry *re;
+ size_t lim;
+- _RuneRange *rr = &_CurrentRuneLocale->__maplower_ext;
++ _RuneRange *rr;
+ _RuneEntry *base, *re;
if (c < 0 || c == EOF)
return(c);
-- for (x = 0; x < rr->nranges; ++x, ++re) {
-- if (c < re->min)
-- return(c);
-- if (c <= re->max)
-- return(re->map + c - re->min);
-- }
-+ re = (_RuneEntry *)bsearch(&c, rr->ranges, rr->nranges,
-+ sizeof(_RuneEntry), __compRuneEntry);
-+
-+ if (re)
-+ return(re->map + c - re->min);
++ NORMALIZE_LOCALE(loc);
++ /*
++ * the following is not used by tolower(), but can be used by
++ * tolower_l(). This provides the oppurtunity to optimize tolower()
++ * when compatibility for Panther and lower is no longer needed
++ */
++ if (c < _CACHED_RUNES)
++ return loc->__lc_ctype->_CurrentRuneLocale.__maplower[c];
++ rr = &loc->__lc_ctype->_CurrentRuneLocale.__maplower_ext;
+ /* Binary search -- see bsearch.c for explanation. */
+ base = rr->__ranges;
+ for (lim = rr->__nranges; lim != 0; lim >>= 1) {
+@@ -65,3 +77,10 @@
return(c);
}
++
++__ct_rune_t
++___tolower(c)
++ __ct_rune_t c;
++{
++ return ___tolower_l(c, __current_locale());
++}
.\" SUCH DAMAGE.
.\"
.\" @(#)toupper.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/locale/toupper.3,v 1.15 2002/10/03 11:14:00 tjr Exp $
+.\" $FreeBSD: src/lib/libc/locale/toupper.3,v 1.16 2004/08/21 07:37:08 tjr Exp $
.\"
-.Dd October 3, 2002
+.Dd August 21, 2004
.Dt TOUPPER 3
.Os
.Sh NAME
function returns the corresponding upper-case letter if there is
one; otherwise the argument is returned unchanged.
.Sh COMPATIBILITY
-Although
-.Fn toupper
-accepts arguments outside of the range of the
-.Vt "unsigned char"
-type in locales with large character sets,
-this is a
+The
.Bx 4.4
-extension and the
+extension of accepting arguments outside of the range of the
+.Vt "unsigned char"
+type in locales with large character sets is considered obsolete
+and may not be supported in future releases.
+The
.Fn towupper
-function should be used instead for maximum portability.
+function should be used instead.
.Sh SEE ALSO
.Xr ctype 3 ,
.Xr isupper 3 ,
--- /dev/null
+--- toupper.3.orig Fri Mar 11 19:44:47 2005
++++ toupper.3 Fri Mar 11 19:51:26 2005
+@@ -40,7 +40,8 @@
+ .Dt TOUPPER 3
+ .Os
+ .Sh NAME
+-.Nm toupper
++.Nm toupper ,
++.Nm toupper_l
+ .Nd lower case to upper case letter conversion
+ .Sh LIBRARY
+ .Lb libc
+@@ -48,6 +49,9 @@
+ .In ctype.h
+ .Ft int
+ .Fn toupper "int c"
++.In xlocale.h
++.Ft int
++.Fn toupper_l "int c" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn toupper
+@@ -62,6 +66,14 @@
+ .Li unsigned char
+ or the value of
+ .Dv EOF .
++.Pp
++While the
++.Fn toupper
++function uses the current locale, the
++.Fn toupper_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ If the argument is a lower-case letter, the
+ .Fn toupper
+@@ -81,7 +93,8 @@
+ .Xr ctype 3 ,
+ .Xr isupper 3 ,
+ .Xr multibyte 3 ,
+-.Xr towupper 3
++.Xr towupper 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn toupper
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/toupper.c,v 1.8 2002/08/21 16:19:56 mike Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/toupper.c,v 1.11 2004/07/29 06:16:19 tjr Exp $");
#include <stdio.h>
-#include <rune.h>
+#include <runetype.h>
__ct_rune_t
___toupper(c)
__ct_rune_t c;
{
- int x;
- _RuneRange *rr = &_CurrentRuneLocale->mapupper_ext;
- _RuneEntry *re = rr->ranges;
+ size_t lim;
+ _RuneRange *rr = &_CurrentRuneLocale->__mapupper_ext;
+ _RuneEntry *base, *re;
if (c < 0 || c == EOF)
return(c);
- for (x = 0; x < rr->nranges; ++x, ++re) {
- if (c < re->min)
- return(c);
- if (c <= re->max)
- return(re->map + c - re->min);
+ /* Binary search -- see bsearch.c for explanation. */
+ base = rr->__ranges;
+ for (lim = rr->__nranges; lim != 0; lim >>= 1) {
+ re = base + (lim >> 1);
+ if (re->__min <= c && c <= re->__max)
+ return (re->__map + c - re->__min);
+ else if (c > re->__max) {
+ base = re + 1;
+ lim--;
+ }
}
return(c);
---- toupper.c.orig Tue May 20 15:21:44 2003
-+++ toupper.c Tue Jun 17 17:49:05 2003
-@@ -39,6 +39,10 @@
+--- toupper.c.orig 2005-02-17 16:40:25.000000000 -0800
++++ toupper.c 2005-02-17 16:42:30.000000000 -0800
+@@ -37,20 +37,32 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/toupper.c,v 1.11 2004/07/29 06:16:19 tjr Exp $");
- #include <stdio.h>
- #include <rune.h>
-+#include <stdlib.h>
++#include "xlocale_private.h"
+
-+__private_extern__ int
-+__compRuneEntry(const void *, const void *); // from runetype.c
+ #include <stdio.h>
+ #include <runetype.h>
__ct_rune_t
- ___toupper(c)
-@@ -46,17 +50,16 @@
+-___toupper(c)
++___toupper_l(c, loc)
+ __ct_rune_t c;
++ locale_t loc;
{
- int x;
- _RuneRange *rr = &_CurrentRuneLocale->mapupper_ext;
-- _RuneEntry *re = rr->ranges;
-+ _RuneEntry *re;
+ size_t lim;
+- _RuneRange *rr = &_CurrentRuneLocale->__mapupper_ext;
++ _RuneRange *rr;
+ _RuneEntry *base, *re;
if (c < 0 || c == EOF)
return(c);
-- for (x = 0; x < rr->nranges; ++x, ++re) {
-- if (c < re->min)
-- return(c);
-- if (c <= re->max)
-- return(re->map + c - re->min);
-- }
-+ re = (_RuneEntry *)bsearch(&c, rr->ranges, rr->nranges,
-+ sizeof(_RuneEntry), __compRuneEntry);
-+
-+ if (re)
-+ return(re->map + c - re->min);
++ NORMALIZE_LOCALE(loc);
++ /*
++ * the following is not used by toupper(), but can be used by
++ * toupper_l(). This provides the oppurtunity to optimize toupper()
++ * when compatibility for Panther and lower is no longer needed
++ */
++ if (c < _CACHED_RUNES)
++ return loc->__lc_ctype->_CurrentRuneLocale.__mapupper[c];
++ rr = &loc->__lc_ctype->_CurrentRuneLocale.__mapupper_ext;
+ /* Binary search -- see bsearch.c for explanation. */
+ base = rr->__ranges;
+ for (lim = rr->__nranges; lim != 0; lim >>= 1) {
+@@ -65,3 +77,10 @@
return(c);
}
++
++__ct_rune_t
++___toupper(c)
++ __ct_rune_t c;
++{
++ return ___toupper_l(c, __current_locale());
++}
--- /dev/null
+--- towlower.3.orig Fri Mar 11 19:44:47 2005
++++ towlower.3 Fri Mar 11 19:50:47 2005
+@@ -40,7 +40,8 @@
+ .Dt TOWLOWER 3
+ .Os
+ .Sh NAME
+-.Nm towlower
++.Nm towlower ,
++.Nm towlower_l
+ .Nd "upper case to lower case letter conversion (wide character version)"
+ .Sh LIBRARY
+ .Lb libc
+@@ -48,11 +49,22 @@
+ .In wctype.h
+ .Ft wint_t
+ .Fn towlower "wint_t wc"
++.In xlocale.h
++.Ft wint_t
++.Fn towlower_l "wint_t wc" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn towlower
+ function converts an upper-case letter to the corresponding lower-case
+ letter.
++.Pp
++While the
++.Fn towlower
++function uses the current locale, the
++.Fn towlower_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ If the argument is an upper-case letter, the
+ .Fn towlower
+@@ -62,7 +74,8 @@
+ .Xr iswlower 3 ,
+ .Xr tolower 3 ,
+ .Xr towupper 3 ,
+-.Xr wctrans 3
++.Xr wctrans 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn towlower
--- /dev/null
+--- towupper.3.orig Fri Mar 11 19:44:47 2005
++++ towupper.3 Fri Mar 11 19:50:09 2005
+@@ -40,7 +40,8 @@
+ .Dt TOWUPPER 3
+ .Os
+ .Sh NAME
+-.Nm towupper
++.Nm towupper ,
++.Nm towupper_l
+ .Nd "lower case to upper case letter conversion (wide character version)"
+ .Sh LIBRARY
+ .Lb libc
+@@ -48,11 +49,22 @@
+ .In wctype.h
+ .Ft wint_t
+ .Fn towupper "wint_t wc"
++.In xlocale.h
++.Ft wint_t
++.Fn towupper_l "wint_t wc" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn towupper
+ function converts a lower-case letter to the corresponding
+ upper-case letter.
++.Pp
++While the
++.Fn towupper
++function uses the current locale, the
++.Fn towupper_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ If the argument is a lower-case letter, the
+ .Fn towupper
+@@ -62,7 +74,8 @@
+ .Xr iswupper 3 ,
+ .Xr toupper 3 ,
+ .Xr towlower 3 ,
+-.Xr wctrans 3
++.Xr wctrans 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn towupper
+++ /dev/null
-.\" Copyright (c) 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" This code is derived from software contributed to Berkeley by
-.\" Paul Borman at Krystal Technologies.
-.\"
-.\" 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.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
-.\"
-.\" @(#)utf2.4 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/locale/utf2.4,v 1.10 2002/10/10 22:56:18 tjr Exp $
-.\"
-.Dd October 11, 2002
-.Dt UTF2 4
-.Os
-.Sh NAME
-.Nm utf2
-.Nd "Universal character set Transformation Format encoding of runes
-.Sh SYNOPSIS
-.Nm ENCODING
-.Qq UTF2
-.Sh DESCRIPTION
-.Bf Em
-The UTF2 encoding has been deprecated in favour of UTF-8.
-.Ef
-New applications should not use UTF2.
-.Pp
-The
-.Nm UTF2
-encoding is based on a proposed X-Open multibyte
-\s-1FSS-UCS-TF\s+1 (File System Safe Universal Character Set Transformation Format) encoding as used in
-.Sy "Plan 9 from Bell Labs" .
-Although it is capable of representing more than 16 bits,
-the current implementation is limited to 16 bits as defined by the
-Unicode Standard.
-.Pp
-.Nm UTF2
-representation is backwards compatible with ASCII, so 0x00-0x7f refer to the
-ASCII character set. The multibyte encoding of runes between 0x0080 and 0xffff
-consist entirely of bytes whose high order bit is set. The actual
-encoding is represented by the following table:
-.Bd -literal
-[0x0000 - 0x007f] [00000000.0bbbbbbb] -> 0bbbbbbb
-[0x0080 - 0x07ff] [00000bbb.bbbbbbbb] -> 110bbbbb, 10bbbbbb
-[0x0800 - 0xffff] [bbbbbbbb.bbbbbbbb] -> 1110bbbb, 10bbbbbb, 10bbbbbb
-.Ed
-.Pp
-If more than a single representation of a value exists (for example,
-0x00; 0xC0 0x80; 0xE0 0x80 0x80) the shortest representation is always
-used (but the longer ones will be correctly decoded).
-.Pp
-The final three encodings provided by X-Open:
-.Bd -literal
-[00000000.000bbbbb.bbbbbbbb.bbbbbbbb] ->
- 11110bbb, 10bbbbbb, 10bbbbbb, 10bbbbbb
-
-[000000bb.bbbbbbbb.bbbbbbbb.bbbbbbbb] ->
- 111110bb, 10bbbbbb, 10bbbbbb, 10bbbbbb, 10bbbbbb
-
-[0bbbbbbb.bbbbbbbb.bbbbbbbb.bbbbbbbb] ->
- 1111110b, 10bbbbbb, 10bbbbbb, 10bbbbbb, 10bbbbbb, 10bbbbbb
-.Ed
-.Pp
-which provides for the entire proposed ISO-10646 31 bit standard are currently
-not implemented.
-.Sh "SEE ALSO"
-.Xr mklocale 1 ,
-.Xr setlocale 3 ,
-.Xr utf8 5
+++ /dev/null
-/*-
- * Copyright (c) 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Paul Borman at Krystal Technologies.
- *
- * 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)utf2.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/utf2.c,v 1.7 2002/03/22 21:52:18 obrien Exp $");
-
-#include <rune.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-rune_t _UTF2_sgetrune(const char *, size_t, char const **);
-int _UTF2_sputrune(rune_t, char *, size_t, char **);
-
-static int _utf_count[16] = {
- 1, 1, 1, 1, 1, 1, 1, 1,
- 0, 0, 0, 0, 2, 2, 3, 0,
-};
-
-int
-_UTF2_init(rl)
- _RuneLocale *rl;
-{
- rl->sgetrune = _UTF2_sgetrune;
- rl->sputrune = _UTF2_sputrune;
- _CurrentRuneLocale = rl;
- __mb_cur_max = 3;
- return (0);
-}
-
-rune_t
-_UTF2_sgetrune(string, n, result)
- const char *string;
- size_t n;
- char const **result;
-{
- int c;
-
- if (n < 1 || (c = _utf_count[(*string >> 4) & 0xf]) > n) {
- if (result)
- *result = string;
- return (_INVALID_RUNE);
- }
- switch (c) {
- case 1:
- if (result)
- *result = string + 1;
- return (*string & 0xff);
- case 2:
- if ((string[1] & 0xC0) != 0x80)
- goto encoding_error;
- if (result)
- *result = string + 2;
- return (((string[0] & 0x1F) << 6) | (string[1] & 0x3F));
- case 3:
- if ((string[1] & 0xC0) != 0x80 || (string[2] & 0xC0) != 0x80)
- goto encoding_error;
- if (result)
- *result = string + 3;
- return (((string[0] & 0x1F) << 12) | ((string[1] & 0x3F) << 6)
- | (string[2] & 0x3F));
- default:
-encoding_error: if (result)
- *result = string + 1;
- return (_INVALID_RUNE);
- }
-}
-
-int
-_UTF2_sputrune(c, string, n, result)
- rune_t c;
- char *string, **result;
- size_t n;
-{
- if (c & 0xF800) {
- if (n >= 3) {
- if (string) {
- string[0] = 0xE0 | ((c >> 12) & 0x0F);
- string[1] = 0x80 | ((c >> 6) & 0x3F);
- string[2] = 0x80 | ((c) & 0x3F);
- }
- if (result)
- *result = string + 3;
- } else
- if (result)
- *result = NULL;
-
- return (3);
- } else
- if (c & 0x0780) {
- if (n >= 2) {
- if (string) {
- string[0] = 0xC0 | ((c >> 6) & 0x1F);
- string[1] = 0x80 | ((c) & 0x3F);
- }
- if (result)
- *result = string + 2;
- } else
- if (result)
- *result = NULL;
- return (2);
- } else {
- if (n >= 1) {
- if (string)
- string[0] = c;
- if (result)
- *result = string + 1;
- } else
- if (result)
- *result = NULL;
- return (1);
- }
-}
--- /dev/null
+--- utf2.c.orig Fri Feb 18 15:49:55 2005
++++ utf2.c Fri Feb 18 15:52:07 2005
+@@ -25,8 +25,11 @@
+ */
+
+ #include <sys/param.h>
++/* dumb down UTF-8 to do UTF2 */
+ __FBSDID("$FreeBSD: src/lib/libc/locale/utf8.c,v 1.11 2004/07/27 06:29:48 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <errno.h>
+ #include <limits.h>
+ #include <runetype.h>
+@@ -35,54 +38,55 @@
+ #include <wchar.h>
+ #include "mblocal.h"
+
+-size_t _UTF8_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
+- mbstate_t * __restrict);
+-int _UTF8_mbsinit(const mbstate_t *);
+-size_t _UTF8_mbsnrtowcs(wchar_t * __restrict, const char ** __restrict,
+- size_t, size_t, mbstate_t * __restrict);
+-size_t _UTF8_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
+-size_t _UTF8_wcsnrtombs(char * __restrict, const wchar_t ** __restrict,
+- size_t, size_t, mbstate_t * __restrict);
++#define UTF2_MB_CUR_MAX 3
++
++static size_t _UTF2_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
++ mbstate_t * __restrict, locale_t);
++static int _UTF2_mbsinit(const mbstate_t *, locale_t);
++static size_t _UTF2_mbsnrtowcs(wchar_t * __restrict, const char ** __restrict,
++ size_t, size_t, mbstate_t * __restrict, locale_t);
++static size_t _UTF2_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict, locale_t);
++static size_t _UTF2_wcsnrtombs(char * __restrict, const wchar_t ** __restrict,
++ size_t, size_t, mbstate_t * __restrict, locale_t);
+
+ typedef struct {
+ wchar_t ch;
+ int want;
+ wchar_t lbound;
+-} _UTF8State;
++} _UTF2State;
+
+-int
+-_UTF8_init(_RuneLocale *rl)
++__private_extern__ int
++_UTF2_init(struct __xlocale_st_runelocale *xrl)
+ {
+
+- __mbrtowc = _UTF8_mbrtowc;
+- __wcrtomb = _UTF8_wcrtomb;
+- __mbsinit = _UTF8_mbsinit;
+- __mbsnrtowcs = _UTF8_mbsnrtowcs;
+- __wcsnrtombs = _UTF8_wcsnrtombs;
+- _CurrentRuneLocale = rl;
+- __mb_cur_max = 6;
++ xrl->__mbrtowc = _UTF2_mbrtowc;
++ xrl->__wcrtomb = _UTF2_wcrtomb;
++ xrl->__mbsinit = _UTF2_mbsinit;
++ xrl->__mbsnrtowcs = _UTF2_mbsnrtowcs;
++ xrl->__wcsnrtombs = _UTF2_wcsnrtombs;
++ xrl->__mb_cur_max = UTF2_MB_CUR_MAX;
+
+ return (0);
+ }
+
+-int
+-_UTF8_mbsinit(const mbstate_t *ps)
++static int
++_UTF2_mbsinit(const mbstate_t *ps, locale_t loc)
+ {
+
+- return (ps == NULL || ((const _UTF8State *)ps)->want == 0);
++ return (ps == NULL || ((const _UTF2State *)ps)->want == 0);
+ }
+
+-size_t
+-_UTF8_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
+- mbstate_t * __restrict ps)
++static size_t
++_UTF2_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
++ mbstate_t * __restrict ps, locale_t loc)
+ {
+- _UTF8State *us;
++ _UTF2State *us;
+ int ch, i, mask, want;
+ wchar_t lbound, wch;
+
+- us = (_UTF8State *)ps;
++ us = (_UTF2State *)ps;
+
+- if (us->want < 0 || us->want > 6) {
++ if (us->want < 0 || us->want > 3) {
+ errno = EINVAL;
+ return ((size_t)-1);
+ }
+@@ -130,21 +134,9 @@
+ mask = 0x0f;
+ want = 3;
+ lbound = 0x800;
+- } else if ((ch & 0xf8) == 0xf0) {
+- mask = 0x07;
+- want = 4;
+- lbound = 0x10000;
+- } else if ((ch & 0xfc) == 0xf8) {
+- mask = 0x03;
+- want = 5;
+- lbound = 0x200000;
+- } else if ((ch & 0xfc) == 0xfc) {
+- mask = 0x01;
+- want = 6;
+- lbound = 0x4000000;
+ } else {
+ /*
+- * Malformed input; input is not UTF-8.
++ * Malformed input; input is not UTF2.
+ */
+ errno = EILSEQ;
+ return ((size_t)-1);
+@@ -194,17 +186,17 @@
+ return (wch == L'\0' ? 0 : want);
+ }
+
+-size_t
+-_UTF8_mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src,
+- size_t nms, size_t len, mbstate_t * __restrict ps)
++static size_t
++_UTF2_mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src,
++ size_t nms, size_t len, mbstate_t * __restrict ps, locale_t loc)
+ {
+- _UTF8State *us;
++ _UTF2State *us;
+ const char *s;
+ size_t nchr;
+ wchar_t wc;
+ size_t nb;
+
+- us = (_UTF8State *)ps;
++ us = (_UTF2State *)ps;
+
+ s = *src;
+ nchr = 0;
+@@ -226,7 +218,7 @@
+ * excluding NUL.
+ */
+ nb = 1;
+- else if ((nb = _UTF8_mbrtowc(&wc, s, nms, ps)) ==
++ else if ((nb = _UTF2_mbrtowc(&wc, s, nms, ps, loc)) ==
+ (size_t)-1)
+ /* Invalid sequence - mbrtowc() sets errno. */
+ return ((size_t)-1);
+@@ -256,7 +248,7 @@
+ */
+ *dst = (wchar_t)*s;
+ nb = 1;
+- } else if ((nb = _UTF8_mbrtowc(dst, s, nms, ps)) ==
++ } else if ((nb = _UTF2_mbrtowc(dst, s, nms, ps, loc)) ==
+ (size_t)-1) {
+ *src = s;
+ return ((size_t)-1);
+@@ -276,14 +268,14 @@
+ return (nchr);
+ }
+
+-size_t
+-_UTF8_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
++static size_t
++_UTF2_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps, locale_t loc)
+ {
+- _UTF8State *us;
++ _UTF2State *us;
+ unsigned char lead;
+ int i, len;
+
+- us = (_UTF8State *)ps;
++ us = (_UTF2State *)ps;
+
+ if (us->want != 0) {
+ errno = EINVAL;
+@@ -315,15 +307,6 @@
+ } else if ((wc & ~0xffff) == 0) {
+ lead = 0xe0;
+ len = 3;
+- } else if ((wc & ~0x1fffff) == 0) {
+- lead = 0xf0;
+- len = 4;
+- } else if ((wc & ~0x3ffffff) == 0) {
+- lead = 0xf8;
+- len = 5;
+- } else if ((wc & ~0x7fffffff) == 0) {
+- lead = 0xfc;
+- len = 6;
+ } else {
+ errno = EILSEQ;
+ return ((size_t)-1);
+@@ -344,17 +327,17 @@
+ return (len);
+ }
+
+-size_t
+-_UTF8_wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src,
+- size_t nwc, size_t len, mbstate_t * __restrict ps)
++static size_t
++_UTF2_wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src,
++ size_t nwc, size_t len, mbstate_t * __restrict ps, locale_t loc)
+ {
+- _UTF8State *us;
++ _UTF2State *us;
+ char buf[MB_LEN_MAX];
+ const wchar_t *s;
+ size_t nbytes;
+ size_t nb;
+
+- us = (_UTF8State *)ps;
++ us = (_UTF2State *)ps;
+
+ if (us->want != 0) {
+ errno = EINVAL;
+@@ -369,7 +352,7 @@
+ if (0 <= *s && *s < 0x80)
+ /* Fast path for plain ASCII characters. */
+ nb = 1;
+- else if ((nb = _UTF8_wcrtomb(buf, *s, ps)) ==
++ else if ((nb = _UTF2_wcrtomb(buf, *s, ps, loc)) ==
+ (size_t)-1)
+ /* Invalid character - wcrtomb() sets errno. */
+ return ((size_t)-1);
+@@ -386,9 +369,9 @@
+ /* Fast path for plain ASCII characters. */
+ nb = 1;
+ *dst = *s;
+- } else if (len > (size_t)MB_CUR_MAX) {
++ } else if (len > (size_t)UTF2_MB_CUR_MAX) {
+ /* Enough space to translate in-place. */
+- if ((nb = (int)_UTF8_wcrtomb(dst, *s, ps)) < 0) {
++ if ((nb = (int)_UTF2_wcrtomb(dst, *s, ps, loc)) < 0) {
+ *src = s;
+ return ((size_t)-1);
+ }
+@@ -396,7 +379,7 @@
+ /*
+ * May not be enough space; use temp. buffer.
+ */
+- if ((nb = (int)_UTF8_wcrtomb(buf, *s, ps)) < 0) {
++ if ((nb = (int)_UTF2_wcrtomb(buf, *s, ps, loc)) < 0) {
+ *src = s;
+ return ((size_t)-1);
+ }
.\" SUCH DAMAGE.
.\"
.\" @(#)utf2.4 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/locale/utf8.5,v 1.3 2002/11/29 17:35:09 ru Exp $
+.\" $FreeBSD: src/lib/libc/locale/utf8.5,v 1.6 2004/10/17 02:29:15 tjr Exp $
.\"
-.Dd October 30, 2002
+.Dd April 7, 2004
.Dt UTF8 5
.Os
.Sh NAME
used.
Longer ones are detected as an error as they pose a potential
security risk, and destroy the 1:1 character:octet sequence mapping.
-.Sh COMPATIBILITY
-The
-.Nm
-encoding supersedes the
-.Xr utf2 4
-encoding.
-The only differences between the two are that
-.Nm
-handles the full 31-bit character set of
-.Tn ISO
-10646
-whereas
-.Xr utf2 4
-is limited to a 16-bit character set,
-and that
-.Xr utf2 4
-accepts redundant,
-.No non- Ns Dq "shortest form"
-representations of characters.
.Sh SEE ALSO
-.Xr euc 4 ,
-.Xr utf2 4
+.Xr euc 5
.Rs
.%A "Rob Pike"
.%A "Ken Thompson"
The
.Nm
encoding is compatible with RFC 2279 and Unicode 3.2.
-.Sh BUGS
-Byte order marker (BOM) characters are neither added nor removed
-from UTF-8-encoded wide character
-.Xr stdio 3
-streams.
/*-
- * Copyright (c) 2002 Tim J. Robbins
+ * Copyright (c) 2002-2004 Tim J. Robbins
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/utf8.c,v 1.2 2003/02/18 13:39:51 nectar Exp $");
+#include <sys/param.h>
+__FBSDID("$FreeBSD: src/lib/libc/locale/utf8.c,v 1.11 2004/07/27 06:29:48 tjr Exp $");
-#include <rune.h>
-#include <stddef.h>
-#include <stdio.h>
+#include <errno.h>
+#include <limits.h>
+#include <runetype.h>
#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include "mblocal.h"
-rune_t _UTF8_sgetrune(const char *, size_t, char const **);
-int _UTF8_sputrune(rune_t, char *, size_t, char **);
+size_t _UTF8_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
+ mbstate_t * __restrict);
+int _UTF8_mbsinit(const mbstate_t *);
+size_t _UTF8_mbsnrtowcs(wchar_t * __restrict, const char ** __restrict,
+ size_t, size_t, mbstate_t * __restrict);
+size_t _UTF8_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
+size_t _UTF8_wcsnrtombs(char * __restrict, const wchar_t ** __restrict,
+ size_t, size_t, mbstate_t * __restrict);
+
+typedef struct {
+ wchar_t ch;
+ int want;
+ wchar_t lbound;
+} _UTF8State;
int
_UTF8_init(_RuneLocale *rl)
{
- rl->sgetrune = _UTF8_sgetrune;
- rl->sputrune = _UTF8_sputrune;
+ __mbrtowc = _UTF8_mbrtowc;
+ __wcrtomb = _UTF8_wcrtomb;
+ __mbsinit = _UTF8_mbsinit;
+ __mbsnrtowcs = _UTF8_mbsnrtowcs;
+ __wcsnrtombs = _UTF8_wcsnrtombs;
_CurrentRuneLocale = rl;
__mb_cur_max = 6;
return (0);
}
-rune_t
-_UTF8_sgetrune(const char *string, size_t n, const char **result)
+int
+_UTF8_mbsinit(const mbstate_t *ps)
+{
+
+ return (ps == NULL || ((const _UTF8State *)ps)->want == 0);
+}
+
+size_t
+_UTF8_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
+ mbstate_t * __restrict ps)
{
- int ch, len, mask;
- rune_t lbound, wch;
+ _UTF8State *us;
+ int ch, i, mask, want;
+ wchar_t lbound, wch;
+
+ us = (_UTF8State *)ps;
- if (n < 1) {
- if (result != NULL)
- *result = string;
- return (_INVALID_RUNE);
+ if (us->want < 0 || us->want > 6) {
+ errno = EINVAL;
+ return ((size_t)-1);
}
- /*
- * Determine the number of octets that make up this character from
- * the first octet, and a mask that extracts the interesting bits of
- * the first octet.
- *
- * We also specify a lower bound for the character code to detect
- * redundant, non-"shortest form" encodings. For example, the
- * sequence C0 80 is _not_ a legal representation of the null
- * character. This enforces a 1-to-1 mapping between character
- * codes and their multibyte representations.
- */
- ch = (unsigned char)*string;
- if ((ch & 0x80) == 0) {
- mask = 0x7f;
- len = 1;
- lbound = 0;
- } else if ((ch & 0xe0) == 0xc0) {
- mask = 0x1f;
- len = 2;
- lbound = 0x80;
- } else if ((ch & 0xf0) == 0xe0) {
- mask = 0x0f;
- len = 3;
- lbound = 0x800;
- } else if ((ch & 0xf8) == 0xf0) {
- mask = 0x07;
- len = 4;
- lbound = 0x10000;
- } else if ((ch & 0xfc) == 0xf8) {
- mask = 0x03;
- len = 5;
- lbound = 0x200000;
- } else if ((ch & 0xfc) == 0xfc) {
- mask = 0x01;
- len = 6;
- lbound = 0x4000000;
- } else {
- /*
- * Malformed input; input is not UTF-8.
- */
- if (result != NULL)
- *result = string + 1;
- return (_INVALID_RUNE);
+ if (s == NULL) {
+ s = "";
+ n = 1;
+ pwc = NULL;
}
- if (n < len) {
+ if (n == 0)
+ /* Incomplete multibyte sequence */
+ return ((size_t)-2);
+
+ if (us->want == 0 && ((ch = (unsigned char)*s) & ~0x7f) == 0) {
+ /* Fast path for plain ASCII characters. */
+ if (pwc != NULL)
+ *pwc = ch;
+ return (ch != '\0' ? 1 : 0);
+ }
+
+ if (us->want == 0) {
/*
- * Truncated or partial input.
+ * Determine the number of octets that make up this character
+ * from the first octet, and a mask that extracts the
+ * interesting bits of the first octet. We already know
+ * the character is at least two bytes long.
+ *
+ * We also specify a lower bound for the character code to
+ * detect redundant, non-"shortest form" encodings. For
+ * example, the sequence C0 80 is _not_ a legal representation
+ * of the null character. This enforces a 1-to-1 mapping
+ * between character codes and their multibyte representations.
*/
- if (result != NULL)
- *result = string;
- return (_INVALID_RUNE);
+ ch = (unsigned char)*s;
+ if ((ch & 0x80) == 0) {
+ mask = 0x7f;
+ want = 1;
+ lbound = 0;
+ } else if ((ch & 0xe0) == 0xc0) {
+ mask = 0x1f;
+ want = 2;
+ lbound = 0x80;
+ } else if ((ch & 0xf0) == 0xe0) {
+ mask = 0x0f;
+ want = 3;
+ lbound = 0x800;
+ } else if ((ch & 0xf8) == 0xf0) {
+ mask = 0x07;
+ want = 4;
+ lbound = 0x10000;
+ } else if ((ch & 0xfc) == 0xf8) {
+ mask = 0x03;
+ want = 5;
+ lbound = 0x200000;
+ } else if ((ch & 0xfc) == 0xfc) {
+ mask = 0x01;
+ want = 6;
+ lbound = 0x4000000;
+ } else {
+ /*
+ * Malformed input; input is not UTF-8.
+ */
+ errno = EILSEQ;
+ return ((size_t)-1);
+ }
+ } else {
+ want = us->want;
+ lbound = us->lbound;
}
/*
* Decode the octet sequence representing the character in chunks
* of 6 bits, most significant first.
*/
- wch = (unsigned char)*string++ & mask;
- while (--len != 0) {
- if ((*string & 0xc0) != 0x80) {
+ if (us->want == 0)
+ wch = (unsigned char)*s++ & mask;
+ else
+ wch = us->ch;
+ for (i = (us->want == 0) ? 1 : 0; i < MIN(want, n); i++) {
+ if ((*s & 0xc0) != 0x80) {
/*
* Malformed input; bad characters in the middle
* of a character.
*/
- wch = _INVALID_RUNE;
- if (result != NULL)
- *result = string + 1;
- return (_INVALID_RUNE);
+ errno = EILSEQ;
+ return ((size_t)-1);
}
wch <<= 6;
- wch |= *string++ & 0x3f;
+ wch |= *s++ & 0x3f;
}
- if (wch != _INVALID_RUNE && wch < lbound)
+ if (i < want) {
+ /* Incomplete multibyte sequence. */
+ us->want = want - i;
+ us->lbound = lbound;
+ us->ch = wch;
+ return ((size_t)-2);
+ }
+ if (wch < lbound) {
/*
* Malformed input; redundant encoding.
*/
- wch = _INVALID_RUNE;
- if (result != NULL)
- *result = string;
- return (wch);
+ errno = EILSEQ;
+ return ((size_t)-1);
+ }
+ if (pwc != NULL)
+ *pwc = wch;
+ us->want = 0;
+ return (wch == L'\0' ? 0 : want);
}
-int
-_UTF8_sputrune(rune_t c, char *string, size_t n, char **result)
+size_t
+_UTF8_mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src,
+ size_t nms, size_t len, mbstate_t * __restrict ps)
{
+ _UTF8State *us;
+ const char *s;
+ size_t nchr;
+ wchar_t wc;
+ size_t nb;
+
+ us = (_UTF8State *)ps;
+
+ s = *src;
+ nchr = 0;
+
+ if (dst == NULL) {
+ /*
+ * The fast path in the loop below is not safe if an ASCII
+ * character appears as anything but the first byte of a
+ * multibyte sequence. Check now to avoid doing it in the loop.
+ */
+ if (nms > 0 && us->want > 0 && (signed char)*s > 0) {
+ errno = EILSEQ;
+ return ((size_t)-1);
+ }
+ for (;;) {
+ if (nms > 0 && (signed char)*s > 0)
+ /*
+ * Fast path for plain ASCII characters
+ * excluding NUL.
+ */
+ nb = 1;
+ else if ((nb = _UTF8_mbrtowc(&wc, s, nms, ps)) ==
+ (size_t)-1)
+ /* Invalid sequence - mbrtowc() sets errno. */
+ return ((size_t)-1);
+ else if (nb == 0 || nb == (size_t)-2)
+ return (nchr);
+ s += nb;
+ nms -= nb;
+ nchr++;
+ }
+ /*NOTREACHED*/
+ }
+
+ /*
+ * The fast path in the loop below is not safe if an ASCII
+ * character appears as anything but the first byte of a
+ * multibyte sequence. Check now to avoid doing it in the loop.
+ */
+ if (nms > 0 && len > 0 && us->want > 0 && (signed char)*s > 0) {
+ errno = EILSEQ;
+ return ((size_t)-1);
+ }
+ while (len-- > 0) {
+ if (nms > 0 && (signed char)*s > 0) {
+ /*
+ * Fast path for plain ASCII characters
+ * excluding NUL.
+ */
+ *dst = (wchar_t)*s;
+ nb = 1;
+ } else if ((nb = _UTF8_mbrtowc(dst, s, nms, ps)) ==
+ (size_t)-1) {
+ *src = s;
+ return ((size_t)-1);
+ } else if (nb == (size_t)-2) {
+ *src = s + nms;
+ return (nchr);
+ } else if (nb == 0) {
+ *src = NULL;
+ return (nchr);
+ }
+ s += nb;
+ nms -= nb;
+ nchr++;
+ dst++;
+ }
+ *src = s;
+ return (nchr);
+}
+
+size_t
+_UTF8_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
+{
+ _UTF8State *us;
unsigned char lead;
int i, len;
+ us = (_UTF8State *)ps;
+
+ if (us->want != 0) {
+ errno = EINVAL;
+ return ((size_t)-1);
+ }
+
+ if (s == NULL)
+ /* Reset to initial shift state (no-op) */
+ return (1);
+
+ if ((wc & ~0x7f) == 0) {
+ /* Fast path for plain ASCII characters. */
+ *s = (char)wc;
+ return (1);
+ }
+
/*
* Determine the number of octets needed to represent this character.
* We always output the shortest sequence possible. Also specify the
* first few bits of the first octet, which contains the information
* about the sequence length.
*/
- if ((c & ~0x7f) == 0) {
+ if ((wc & ~0x7f) == 0) {
lead = 0;
len = 1;
- } else if ((c & ~0x7ff) == 0) {
+ } else if ((wc & ~0x7ff) == 0) {
lead = 0xc0;
len = 2;
- } else if ((c & ~0xffff) == 0) {
+ } else if ((wc & ~0xffff) == 0) {
lead = 0xe0;
len = 3;
- } else if ((c & ~0x1fffff) == 0) {
+ } else if ((wc & ~0x1fffff) == 0) {
lead = 0xf0;
len = 4;
- } else if ((c & ~0x3ffffff) == 0) {
+ } else if ((wc & ~0x3ffffff) == 0) {
lead = 0xf8;
len = 5;
- } else if ((c & ~0x7fffffff) == 0) {
+ } else if ((wc & ~0x7fffffff) == 0) {
lead = 0xfc;
len = 6;
} else {
- /*
- * Wide character code is out of range.
- */
- if (result != NULL)
- *result = NULL;
- return (0);
+ errno = EILSEQ;
+ return ((size_t)-1);
}
- if (n < len) {
- if (result != NULL)
- *result = NULL;
- } else {
- /*
- * Output the octets representing the character in chunks
- * of 6 bits, least significant last. The first octet is
- * a special case because it contains the sequence length
- * information.
- */
- for (i = len - 1; i > 0; i--) {
- string[i] = (c & 0x3f) | 0x80;
- c >>= 6;
- }
- *string = (c & 0xff) | lead;
- if (result != NULL)
- *result = string + len;
+ /*
+ * Output the octets representing the character in chunks
+ * of 6 bits, least significant last. The first octet is
+ * a special case because it contains the sequence length
+ * information.
+ */
+ for (i = len - 1; i > 0; i--) {
+ s[i] = (wc & 0x3f) | 0x80;
+ wc >>= 6;
}
+ *s = (wc & 0xff) | lead;
return (len);
}
+
+size_t
+_UTF8_wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src,
+ size_t nwc, size_t len, mbstate_t * __restrict ps)
+{
+ _UTF8State *us;
+ char buf[MB_LEN_MAX];
+ const wchar_t *s;
+ size_t nbytes;
+ size_t nb;
+
+ us = (_UTF8State *)ps;
+
+ if (us->want != 0) {
+ errno = EINVAL;
+ return ((size_t)-1);
+ }
+
+ s = *src;
+ nbytes = 0;
+
+ if (dst == NULL) {
+ while (nwc-- > 0) {
+ if (0 <= *s && *s < 0x80)
+ /* Fast path for plain ASCII characters. */
+ nb = 1;
+ else if ((nb = _UTF8_wcrtomb(buf, *s, ps)) ==
+ (size_t)-1)
+ /* Invalid character - wcrtomb() sets errno. */
+ return ((size_t)-1);
+ if (*s == L'\0')
+ return (nbytes + nb - 1);
+ s++;
+ nbytes += nb;
+ }
+ return (nbytes);
+ }
+
+ while (len > 0 && nwc-- > 0) {
+ if (0 <= *s && *s < 0x80) {
+ /* Fast path for plain ASCII characters. */
+ nb = 1;
+ *dst = *s;
+ } else if (len > (size_t)MB_CUR_MAX) {
+ /* Enough space to translate in-place. */
+ if ((nb = (int)_UTF8_wcrtomb(dst, *s, ps)) < 0) {
+ *src = s;
+ return ((size_t)-1);
+ }
+ } else {
+ /*
+ * May not be enough space; use temp. buffer.
+ */
+ if ((nb = (int)_UTF8_wcrtomb(buf, *s, ps)) < 0) {
+ *src = s;
+ return ((size_t)-1);
+ }
+ if (nb > (int)len)
+ /* MB sequence for character won't fit. */
+ break;
+ memcpy(dst, buf, nb);
+ }
+ if (*s == L'\0') {
+ *src = NULL;
+ return (nbytes + nb - 1);
+ }
+ s++;
+ dst += nb;
+ len -= nb;
+ nbytes += nb;
+ }
+ *src = s;
+ return (nbytes);
+}
---- utf8.c.orig Tue May 20 15:21:44 2003
-+++ utf8.c Wed Jun 18 12:07:28 2003
-@@ -53,11 +53,10 @@
- int ch, len, mask;
- rune_t lbound, wch;
+--- utf8.c.orig Thu Nov 25 11:38:20 2004
++++ utf8.c Fri Feb 18 15:40:44 2005
+@@ -27,6 +27,8 @@
+ #include <sys/param.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/utf8.c,v 1.11 2004/07/27 06:29:48 tjr Exp $");
-- if (n < 1) {
-- if (result != NULL)
-- *result = string;
-+ if (result != NULL)
-+ *result = string;
-+ if (n < 1)
- return (_INVALID_RUNE);
-- }
++#include "xlocale_private.h"
++
+ #include <errno.h>
+ #include <limits.h>
+ #include <runetype.h>
+@@ -35,14 +37,16 @@
+ #include <wchar.h>
+ #include "mblocal.h"
- /*
- * Determine the number of octets that make up this character from
-@@ -100,18 +99,15 @@
- * Malformed input; input is not UTF-8.
- */
- if (result != NULL)
-- *result = string + 1;
-+ (*result)++;
- return (_INVALID_RUNE);
- }
+-size_t _UTF8_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
+- mbstate_t * __restrict);
+-int _UTF8_mbsinit(const mbstate_t *);
+-size_t _UTF8_mbsnrtowcs(wchar_t * __restrict, const char ** __restrict,
+- size_t, size_t, mbstate_t * __restrict);
+-size_t _UTF8_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
+-size_t _UTF8_wcsnrtombs(char * __restrict, const wchar_t ** __restrict,
+- size_t, size_t, mbstate_t * __restrict);
++#define UTF8_MB_CUR_MAX 6
++
++static size_t _UTF8_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
++ mbstate_t * __restrict, locale_t);
++static int _UTF8_mbsinit(const mbstate_t *, locale_t);
++static size_t _UTF8_mbsnrtowcs(wchar_t * __restrict, const char ** __restrict,
++ size_t, size_t, mbstate_t * __restrict, locale_t);
++static size_t _UTF8_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict, locale_t);
++static size_t _UTF8_wcsnrtombs(char * __restrict, const wchar_t ** __restrict,
++ size_t, size_t, mbstate_t * __restrict, locale_t);
-- if (n < len) {
-+ if (n < len)
- /*
- * Truncated or partial input.
- */
-- if (result != NULL)
-- *result = string;
- return (_INVALID_RUNE);
-- }
+ typedef struct {
+ wchar_t ch;
+@@ -50,31 +54,30 @@
+ wchar_t lbound;
+ } _UTF8State;
- /*
- * Decode the octet sequence representing the character in chunks
-@@ -124,19 +120,21 @@
- * Malformed input; bad characters in the middle
- * of a character.
+-int
+-_UTF8_init(_RuneLocale *rl)
++__private_extern__ int
++_UTF8_init(struct __xlocale_st_runelocale *xrl)
+ {
+
+- __mbrtowc = _UTF8_mbrtowc;
+- __wcrtomb = _UTF8_wcrtomb;
+- __mbsinit = _UTF8_mbsinit;
+- __mbsnrtowcs = _UTF8_mbsnrtowcs;
+- __wcsnrtombs = _UTF8_wcsnrtombs;
+- _CurrentRuneLocale = rl;
+- __mb_cur_max = 6;
++ xrl->__mbrtowc = _UTF8_mbrtowc;
++ xrl->__wcrtomb = _UTF8_wcrtomb;
++ xrl->__mbsinit = _UTF8_mbsinit;
++ xrl->__mbsnrtowcs = _UTF8_mbsnrtowcs;
++ xrl->__wcsnrtombs = _UTF8_wcsnrtombs;
++ xrl->__mb_cur_max = UTF8_MB_CUR_MAX;
+
+ return (0);
+ }
+
+-int
+-_UTF8_mbsinit(const mbstate_t *ps)
++static int
++_UTF8_mbsinit(const mbstate_t *ps, locale_t loc)
+ {
+
+ return (ps == NULL || ((const _UTF8State *)ps)->want == 0);
+ }
+
+-size_t
++static size_t
+ _UTF8_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
+- mbstate_t * __restrict ps)
++ mbstate_t * __restrict ps, locale_t loc)
+ {
+ _UTF8State *us;
+ int ch, i, mask, want;
+@@ -194,9 +197,9 @@
+ return (wch == L'\0' ? 0 : want);
+ }
+
+-size_t
++static size_t
+ _UTF8_mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src,
+- size_t nms, size_t len, mbstate_t * __restrict ps)
++ size_t nms, size_t len, mbstate_t * __restrict ps, locale_t loc)
+ {
+ _UTF8State *us;
+ const char *s;
+@@ -226,7 +229,7 @@
+ * excluding NUL.
+ */
+ nb = 1;
+- else if ((nb = _UTF8_mbrtowc(&wc, s, nms, ps)) ==
++ else if ((nb = _UTF8_mbrtowc(&wc, s, nms, ps, loc)) ==
+ (size_t)-1)
+ /* Invalid sequence - mbrtowc() sets errno. */
+ return ((size_t)-1);
+@@ -256,7 +259,7 @@
+ */
+ *dst = (wchar_t)*s;
+ nb = 1;
+- } else if ((nb = _UTF8_mbrtowc(dst, s, nms, ps)) ==
++ } else if ((nb = _UTF8_mbrtowc(dst, s, nms, ps, loc)) ==
+ (size_t)-1) {
+ *src = s;
+ return ((size_t)-1);
+@@ -276,8 +279,8 @@
+ return (nchr);
+ }
+
+-size_t
+-_UTF8_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
++static size_t
++_UTF8_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps, locale_t loc)
+ {
+ _UTF8State *us;
+ unsigned char lead;
+@@ -344,9 +347,9 @@
+ return (len);
+ }
+
+-size_t
++static size_t
+ _UTF8_wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src,
+- size_t nwc, size_t len, mbstate_t * __restrict ps)
++ size_t nwc, size_t len, mbstate_t * __restrict ps, locale_t loc)
+ {
+ _UTF8State *us;
+ char buf[MB_LEN_MAX];
+@@ -369,7 +372,7 @@
+ if (0 <= *s && *s < 0x80)
+ /* Fast path for plain ASCII characters. */
+ nb = 1;
+- else if ((nb = _UTF8_wcrtomb(buf, *s, ps)) ==
++ else if ((nb = _UTF8_wcrtomb(buf, *s, ps, loc)) ==
+ (size_t)-1)
+ /* Invalid character - wcrtomb() sets errno. */
+ return ((size_t)-1);
+@@ -386,9 +389,9 @@
+ /* Fast path for plain ASCII characters. */
+ nb = 1;
+ *dst = *s;
+- } else if (len > (size_t)MB_CUR_MAX) {
++ } else if (len > (size_t)UTF8_MB_CUR_MAX) {
+ /* Enough space to translate in-place. */
+- if ((nb = (int)_UTF8_wcrtomb(dst, *s, ps)) < 0) {
++ if ((nb = (int)_UTF8_wcrtomb(dst, *s, ps, loc)) < 0) {
+ *src = s;
+ return ((size_t)-1);
+ }
+@@ -396,7 +399,7 @@
+ /*
+ * May not be enough space; use temp. buffer.
*/
-- wch = _INVALID_RUNE;
- if (result != NULL)
-- *result = string + 1;
-+ (*result)++;
- return (_INVALID_RUNE);
- }
- wch <<= 6;
- wch |= *string++ & 0x3f;
- }
-- if (wch != _INVALID_RUNE && wch < lbound)
-+ if (wch < lbound) {
- /*
- * Malformed input; redundant encoding.
- */
-- wch = _INVALID_RUNE;
-+ if (result != NULL)
-+ (*result)++;
-+ return (_INVALID_RUNE);
-+ }
- if (result != NULL)
- *result = string;
- return (wch);
+- if ((nb = (int)_UTF8_wcrtomb(buf, *s, ps)) < 0) {
++ if ((nb = (int)_UTF8_wcrtomb(buf, *s, ps, loc)) < 0) {
+ *src = s;
+ return ((size_t)-1);
+ }
-.\" Copyright (c) 2002 Tim J. Robbins
+.\" Copyright (c) 2002-2004 Tim J. Robbins
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/lib/libc/locale/wcrtomb.3,v 1.3 2002/11/29 17:35:09 ru Exp $
+.\" $FreeBSD: src/lib/libc/locale/wcrtomb.3,v 1.4 2004/04/08 09:59:02 tjr Exp $
.\"
-.Dd August 15, 2002
+.Dd April 8, 2004
.Dt WCRTOMB 3
.Os
.Sh NAME
.Fn wcrtomb
uses an internal, static
.Vt mbstate_t
-object.
+object, which is initialized to the initial conversion state
+at program startup.
.Sh RETURN VALUES
The
.Fn wcrtomb
.Fn wcrtomb
function will fail if:
.Bl -tag -width Er
-.\".It Bq Er EINVAL
-.\"Invalid argument.
.It Bq Er EILSEQ
An invalid wide character code was specified.
+.It Bq Er EINVAL
+The conversion state is invalid.
.El
.Sh SEE ALSO
.Xr mbrtowc 3 ,
+.Xr multibyte 3 ,
.Xr setlocale 3 ,
.Xr wctomb 3
.Sh STANDARDS
.Fn wcrtomb
function conforms to
.St -isoC-99 .
-.Sh BUGS
-The current implementation does not support shift states.
--- /dev/null
+--- wcrtomb.3.orig Fri Mar 11 19:44:47 2005
++++ wcrtomb.3 Fri Mar 11 19:49:35 2005
+@@ -28,7 +28,8 @@
+ .Dt WCRTOMB 3
+ .Os
+ .Sh NAME
+-.Nm wcrtomb
++.Nm wcrtomb ,
++.Nm wcrtomb_l
+ .Nd "convert a wide-character code to a character (restartable)"
+ .Sh LIBRARY
+ .Lb libc
+@@ -36,6 +37,9 @@
+ .In wchar.h
+ .Ft size_t
+ .Fn wcrtomb "char * restrict s" "wchar_t wc" "mbstate_t * restrict ps"
++.In xlocale.h
++.Ft size_t
++.Fn wcrtomb_l "char * restrict s" "wchar_t wc" "mbstate_t * restrict ps" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn wcrtomb
+@@ -72,6 +76,14 @@
+ .Vt mbstate_t
+ object, which is initialized to the initial conversion state
+ at program startup.
++.Pp
++While the
++.Fn wcrtomb
++function uses the current locale, the
++.Fn wcrtomb_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn wcrtomb
+@@ -97,7 +109,8 @@
+ .Xr mbrtowc 3 ,
+ .Xr multibyte 3 ,
+ .Xr setlocale 3 ,
+-.Xr wctomb 3
++.Xr wctomb 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn wcrtomb
/*-
- * Copyright (c) 2002 Tim J. Robbins.
+ * Copyright (c) 2002-2004 Tim J. Robbins.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/wcrtomb.c,v 1.4 2003/04/10 09:20:38 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/wcrtomb.c,v 1.8 2004/05/12 14:09:04 tjr Exp $");
-#include <errno.h>
-#include <limits.h>
-#include <rune.h>
-#include <stdlib.h>
#include <wchar.h>
+#include "mblocal.h"
size_t
-wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps __unused)
+wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
{
- char *e;
- char buf[MB_LEN_MAX];
+ static mbstate_t mbs;
- if (s == NULL) {
- s = buf;
- wc = L'\0';
- }
- sputrune(wc, s, MB_CUR_MAX, &e);
- if (e == NULL) {
- errno = EILSEQ;
- return ((size_t)-1);
- }
- return ((size_t)(e - s));
+ if (ps == NULL)
+ ps = &mbs;
+ return (__wcrtomb(s, wc, ps));
}
--- /dev/null
+--- wcrtomb.c.orig 2004-11-25 11:38:20.000000000 -0800
++++ wcrtomb.c 2005-02-18 18:30:14.000000000 -0800
+@@ -27,15 +27,23 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/wcrtomb.c,v 1.8 2004/05/12 14:09:04 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <wchar.h>
+ #include "mblocal.h"
+
+ size_t
+-wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
++wcrtomb_l(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps,
++ locale_t loc)
+ {
+- static mbstate_t mbs;
+-
++ NORMALIZE_LOCALE(loc);
+ if (ps == NULL)
+- ps = &mbs;
+- return (__wcrtomb(s, wc, ps));
++ ps = &loc->__mbs_wcrtomb;
++ return (loc->__lc_ctype->__wcrtomb(s, wc, ps, loc));
++}
++
++size_t
++wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
++{
++ return wcrtomb_l(s, wc, ps, __current_locale());
+ }
--- /dev/null
+--- wcsftime.3.orig Fri Mar 11 19:44:47 2005
++++ wcsftime.3 Fri Mar 11 19:49:00 2005
+@@ -28,7 +28,8 @@
+ .Dt WCSFTIME 3
+ .Os
+ .Sh NAME
+-.Nm wcsftime
++.Nm wcsftime ,
++.Nm wcsftime_l
+ .Nd "convert date and time to a wide-character string"
+ .Sh LIBRARY
+ .Lb libc
+@@ -39,6 +40,12 @@
+ .Fa "wchar_t * restrict wcs" "size_t maxsize"
+ .Fa "const wchar_t * restrict format" "const struct tm * restrict timeptr"
+ .Fc
++.In xlocale.h
++.Ft size_t
++.Fo wcsftime_l
++.Fa "wchar_t * restrict wcs" "size_t maxsize"
++.Fa "const wchar_t * restrict format" "const struct tm * restrict timeptr" "locale_t loc"
++.Fc
+ .Sh DESCRIPTION
+ The
+ .Fn wcsftime
+@@ -48,6 +55,14 @@
+ Refer to
+ .Xr strftime 3
+ for a detailed description.
++.Pp
++While the
++.Fn wcsftime
++function uses the current locale, the
++.Fn wcsftime_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh COMPATIBILITY
+ Some early implementations of
+ .Fn wcsftime
+@@ -58,7 +73,8 @@
+ instead of
+ .Vt "const wchar_t *" .
+ .Sh SEE ALSO
+-.Xr strftime 3
++.Xr strftime 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn wcsftime
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/wcsftime.c,v 1.2 2002/09/15 08:06:17 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/wcsftime.c,v 1.4 2004/04/07 09:47:56 tjr Exp $");
#include <errno.h>
#include <limits.h>
const wchar_t * __restrict format, const struct tm * __restrict timeptr)
{
static const mbstate_t initial;
- mbstate_t state;
+ mbstate_t mbs;
char *dst, *dstp, *sformat;
size_t n, sflen;
int sverrno;
* Convert the supplied format string to a multibyte representation
* for strftime(), which only handles single-byte characters.
*/
- state = initial;
- sflen = wcsrtombs(NULL, &format, 0, &state);
+ mbs = initial;
+ sflen = wcsrtombs(NULL, &format, 0, &mbs);
if (sflen == (size_t)-1)
goto error;
if ((sformat = malloc(sflen + 1)) == NULL)
goto error;
- state = initial;
- wcsrtombs(sformat, &format, sflen + 1, &state);
+ mbs = initial;
+ wcsrtombs(sformat, &format, sflen + 1, &mbs);
/*
* Allocate memory for longest multibyte sequence that will fit
goto error;
if (strftime(dst, maxsize, sformat, timeptr) == 0)
goto error;
- state = initial;
dstp = dst;
- n = mbsrtowcs(wcs, (const char **)&dstp, maxsize, &state);
+ mbs = initial;
+ n = mbsrtowcs(wcs, (const char **)&dstp, maxsize, &mbs);
if (n == (size_t)-2 || n == (size_t)-1 || dstp != NULL)
goto error;
--- /dev/null
+--- wcsftime.c.orig 2004-11-25 11:38:20.000000000 -0800
++++ wcsftime.c 2005-02-24 00:53:36.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/wcsftime.c,v 1.4 2004/04/07 09:47:56 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <errno.h>
+ #include <limits.h>
+ #include <stdlib.h>
+@@ -47,8 +49,9 @@
+ * format specifications in the format string.
+ */
+ size_t
+-wcsftime(wchar_t * __restrict wcs, size_t maxsize,
+- const wchar_t * __restrict format, const struct tm * __restrict timeptr)
++wcsftime_l(wchar_t * __restrict wcs, size_t maxsize,
++ const wchar_t * __restrict format, const struct tm * __restrict timeptr,
++ locale_t loc)
+ {
+ static const mbstate_t initial;
+ mbstate_t mbs;
+@@ -56,6 +59,7 @@
+ size_t n, sflen;
+ int sverrno;
+
++ NORMALIZE_LOCALE(loc);
+ sformat = dst = NULL;
+
+ /*
+@@ -63,13 +67,13 @@
+ * for strftime(), which only handles single-byte characters.
+ */
+ mbs = initial;
+- sflen = wcsrtombs(NULL, &format, 0, &mbs);
++ sflen = wcsrtombs_l(NULL, &format, 0, &mbs, loc);
+ if (sflen == (size_t)-1)
+ goto error;
+ if ((sformat = malloc(sflen + 1)) == NULL)
+ goto error;
+ mbs = initial;
+- wcsrtombs(sformat, &format, sflen + 1, &mbs);
++ wcsrtombs_l(sformat, &format, sflen + 1, &mbs, loc);
+
+ /*
+ * Allocate memory for longest multibyte sequence that will fit
+@@ -77,18 +81,18 @@
+ * Then, copy and convert the result back into wide characters in
+ * the caller's buffer.
+ */
+- if (SIZE_T_MAX / MB_CUR_MAX <= maxsize) {
++ if (SIZE_T_MAX / MB_CUR_MAX_L(loc) <= maxsize) {
+ /* maxsize is prepostorously large - avoid int. overflow. */
+ errno = EINVAL;
+ goto error;
+ }
+- if ((dst = malloc(maxsize * MB_CUR_MAX)) == NULL)
++ if ((dst = malloc(maxsize * MB_CUR_MAX_L(loc))) == NULL)
+ goto error;
+- if (strftime(dst, maxsize, sformat, timeptr) == 0)
++ if (strftime_l(dst, maxsize, sformat, timeptr, loc) == 0)
+ goto error;
+ dstp = dst;
+ mbs = initial;
+- n = mbsrtowcs(wcs, (const char **)&dstp, maxsize, &mbs);
++ n = mbsrtowcs_l(wcs, (const char **)&dstp, maxsize, &mbs, loc);
+ if (n == (size_t)-2 || n == (size_t)-1 || dstp != NULL)
+ goto error;
+
+@@ -103,3 +107,10 @@
+ errno = sverrno;
+ return (0);
+ }
++
++size_t
++wcsftime(wchar_t * __restrict wcs, size_t maxsize,
++ const wchar_t * __restrict format, const struct tm * __restrict timeptr)
++{
++ return wcsftime_l(wcs, maxsize, format, timeptr, __current_locale());
++}
--- /dev/null
+/*-
+ * Copyright (c) 2002-2004 Tim J. Robbins.
+ * 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/libc/locale/wcsnrtombs.c,v 1.2 2004/07/22 02:57:29 tjr Exp $");
+
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include "mblocal.h"
+
+size_t
+wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src, size_t nwc,
+ size_t len, mbstate_t * __restrict ps)
+{
+ static mbstate_t mbs;
+
+ if (ps == NULL)
+ ps = &mbs;
+ return (__wcsnrtombs(dst, src, nwc, len, ps));
+}
+
+size_t
+__wcsnrtombs_std(char * __restrict dst, const wchar_t ** __restrict src,
+ size_t nwc, size_t len, mbstate_t * __restrict ps)
+{
+ mbstate_t mbsbak;
+ char buf[MB_LEN_MAX];
+ const wchar_t *s;
+ size_t nbytes;
+ size_t nb;
+
+ s = *src;
+ nbytes = 0;
+
+ if (dst == NULL) {
+ while (nwc-- > 0) {
+ if ((nb = __wcrtomb(buf, *s, ps)) == (size_t)-1)
+ /* Invalid character - wcrtomb() sets errno. */
+ return ((size_t)-1);
+ else if (*s == L'\0')
+ return (nbytes + nb - 1);
+ s++;
+ nbytes += nb;
+ }
+ return (nbytes);
+ }
+
+ while (len > 0 && nwc-- > 0) {
+ if (len > (size_t)MB_CUR_MAX) {
+ /* Enough space to translate in-place. */
+ if ((nb = (int)__wcrtomb(dst, *s, ps)) < 0) {
+ *src = s;
+ return ((size_t)-1);
+ }
+ } else {
+ /*
+ * May not be enough space; use temp. buffer.
+ *
+ * We need to save a copy of the conversion state
+ * here so we can restore it if the multibyte
+ * character is too long for the buffer.
+ */
+ mbsbak = *ps;
+ if ((nb = (int)__wcrtomb(buf, *s, ps)) < 0) {
+ *src = s;
+ return ((size_t)-1);
+ }
+ if (nb > (int)len) {
+ /* MB sequence for character won't fit. */
+ *ps = mbsbak;
+ break;
+ }
+ memcpy(dst, buf, nb);
+ }
+ if (*s == L'\0') {
+ *src = NULL;
+ return (nbytes + nb - 1);
+ }
+ s++;
+ dst += nb;
+ len -= nb;
+ nbytes += nb;
+ }
+ *src = s;
+ return (nbytes);
+}
--- /dev/null
+--- wcsnrtombs.c.orig 2004-11-25 11:38:20.000000000 -0800
++++ wcsnrtombs.c 2005-02-18 18:38:25.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/wcsnrtombs.c,v 1.2 2004/07/22 02:57:29 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <limits.h>
+ #include <stdlib.h>
+ #include <string.h>
+@@ -34,32 +36,41 @@
+ #include "mblocal.h"
+
+ size_t
+-wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src, size_t nwc,
+- size_t len, mbstate_t * __restrict ps)
++wcsnrtombs_l(char * __restrict dst, const wchar_t ** __restrict src, size_t nwc,
++ size_t len, mbstate_t * __restrict ps, locale_t loc)
+ {
+- static mbstate_t mbs;
+-
++ NORMALIZE_LOCALE(loc);
+ if (ps == NULL)
+- ps = &mbs;
+- return (__wcsnrtombs(dst, src, nwc, len, ps));
++ ps = &loc->__mbs_wcsnrtombs;
++ return (loc->__lc_ctype->__wcsnrtombs(dst, src, nwc, len, ps, loc));
+ }
+
+ size_t
++wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src, size_t nwc,
++ size_t len, mbstate_t * __restrict ps)
++{
++ return wcsnrtombs_l(dst, src, nwc, len, ps, __current_locale());
++}
++
++__private_extern__ size_t
+ __wcsnrtombs_std(char * __restrict dst, const wchar_t ** __restrict src,
+- size_t nwc, size_t len, mbstate_t * __restrict ps)
++ size_t nwc, size_t len, mbstate_t * __restrict ps, locale_t loc)
+ {
+ mbstate_t mbsbak;
+ char buf[MB_LEN_MAX];
+ const wchar_t *s;
+ size_t nbytes;
+ size_t nb;
++ struct __xlocale_st_runelocale *runeLocale = loc->__lc_ctype;
++ size_t (*__wcrtomb)(char * __restrict, wchar_t, mbstate_t * __restrict, locale_t) = runeLocale->__wcrtomb;
++ int mb_cur_max = runeLocale->__mb_cur_max;
+
+ s = *src;
+ nbytes = 0;
+
+ if (dst == NULL) {
+ while (nwc-- > 0) {
+- if ((nb = __wcrtomb(buf, *s, ps)) == (size_t)-1)
++ if ((nb = __wcrtomb(buf, *s, ps, loc)) == (size_t)-1)
+ /* Invalid character - wcrtomb() sets errno. */
+ return ((size_t)-1);
+ else if (*s == L'\0')
+@@ -71,9 +82,9 @@
+ }
+
+ while (len > 0 && nwc-- > 0) {
+- if (len > (size_t)MB_CUR_MAX) {
++ if (len > (size_t)mb_cur_max) {
+ /* Enough space to translate in-place. */
+- if ((nb = (int)__wcrtomb(dst, *s, ps)) < 0) {
++ if ((nb = (int)__wcrtomb(dst, *s, ps, loc)) < 0) {
+ *src = s;
+ return ((size_t)-1);
+ }
+@@ -86,7 +97,7 @@
+ * character is too long for the buffer.
+ */
+ mbsbak = *ps;
+- if ((nb = (int)__wcrtomb(buf, *s, ps)) < 0) {
++ if ((nb = (int)__wcrtomb(buf, *s, ps, loc)) < 0) {
+ *src = s;
+ return ((size_t)-1);
+ }
-.\" Copyright (c) 2002 Tim J. Robbins
+.\" Copyright (c) 2002-2004 Tim J. Robbins
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/lib/libc/locale/wcsrtombs.3,v 1.3 2002/11/29 17:35:09 ru Exp $
+.\" $FreeBSD: src/lib/libc/locale/wcsrtombs.3,v 1.5 2004/07/21 10:54:57 tjr Exp $
.\"
-.Dd August 16, 2002
+.Dd July 21, 2004
.Dt WCSRTOMBS 3
.Os
.Sh NAME
-.Nm wcsrtombs
+.Nm wcsrtombs ,
+.Nm wcsnrtombs
.Nd "convert a wide-character string to a character string (restartable)"
.Sh LIBRARY
.Lb libc
.Fa "char * restrict dst" "const wchar_t ** restrict src"
.Fa "size_t len" "mbstate_t * restrict ps"
.Fc
+.Ft size_t
+.Fo wcsnrtombs
+.Fa "char * restrict dst" "const wchar_t ** restrict src" "size_t nwc"
+.Fa "size_t len" "mbstate_t * restrict ps"
+.Fc
.Sh DESCRIPTION
The
.Fn wcsrtombs
.Fn wcsrtombs
uses an internal, static
.Vt mbstate_t
-object.
+object, which is initialized to the initial conversion state
+at program startup.
+.Pp
+The
+.Fn wcsnrtombs
+function behaves identically to
+.Fn wcsrtombs ,
+except that conversion stops after reading at most
+.Fa nwc
+characters from the buffer pointed to by
+.Fa src .
.Sh RETURN VALUES
The
.Fn wcsrtombs
-function returns the number of bytes stored in
+and
+.Fn wcsnrtombs
+functions return the number of bytes stored in
the array pointed to by
.Fa dst
(not including any terminating null), if successful, otherwise it returns
.Sh ERRORS
The
.Fn wcsrtombs
-function will fail if:
+and
+.Fn wcsnrtombs
+functions will fail if:
.Bl -tag -width Er
.It Bq Er EILSEQ
An invalid wide character was encountered.
+.It Bq Er EINVAL
+The conversion state is invalid.
.El
.Sh SEE ALSO
.Xr mbsrtowcs 3 ,
.Fn wcsrtombs
function conforms to
.St -isoC-99 .
-.Sh BUGS
-The current implementation does not support shift states.
+.Pp
+The
+.Fn wcsnrtombs
+function is an extension to the standard.
--- /dev/null
+--- wcsrtombs.3.orig Fri Mar 11 18:15:27 2005
++++ wcsrtombs.3 Fri Mar 11 18:18:11 2005
+@@ -29,7 +29,9 @@
+ .Os
+ .Sh NAME
+ .Nm wcsrtombs ,
+-.Nm wcsnrtombs
++.Nm wcsnrtombs ,
++.Nm wcsrtombs_l ,
++.Nm wcsnrtombs_l
+ .Nd "convert a wide-character string to a character string (restartable)"
+ .Sh LIBRARY
+ .Lb libc
+@@ -45,6 +47,17 @@
+ .Fa "char * restrict dst" "const wchar_t ** restrict src" "size_t nwc"
+ .Fa "size_t len" "mbstate_t * restrict ps"
+ .Fc
++.In xlocale.h
++.Ft size_t
++.Fo wcsrtombs_l
++.Fa "char * restrict dst" "const wchar_t ** restrict src"
++.Fa "size_t len" "mbstate_t * restrict ps" "locale_t loc"
++.Fc
++.Ft size_t
++.Fo wcsnrtombs_l
++.Fa "char * restrict dst" "const wchar_t ** restrict src" "size_t nwc"
++.Fa "size_t len" "mbstate_t * restrict ps" "locale_t loc"
++.Fc
+ .Sh DESCRIPTION
+ The
+ .Fn wcsrtombs
+@@ -97,6 +110,18 @@
+ .Fa nwc
+ characters from the buffer pointed to by
+ .Fa src .
++.Pp
++While the
++.Fn wcsrtombs
++and
++.Fn wcsnrtombs
++functions use the current locale, the
++.Fn wcsrtombs_l
++and
++.Fn wcsnrtombs_l
++functions may be passed locales directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn wcsrtombs
+@@ -122,7 +147,8 @@
+ .Sh SEE ALSO
+ .Xr mbsrtowcs 3 ,
+ .Xr wcrtomb 3 ,
+-.Xr wcstombs 3
++.Xr wcstombs 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn wcsrtombs
/*-
- * Copyright (c) 2002 Tim J. Robbins.
+ * Copyright (c) 2002-2004 Tim J. Robbins.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/wcsrtombs.c,v 1.2 2002/09/06 11:23:45 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/wcsrtombs.c,v 1.6 2004/07/21 10:54:57 tjr Exp $");
-#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
+#include "mblocal.h"
size_t
wcsrtombs(char * __restrict dst, const wchar_t ** __restrict src, size_t len,
- mbstate_t * __restrict ps __unused)
+ mbstate_t * __restrict ps)
{
- char buf[MB_LEN_MAX];
- const wchar_t *s;
- size_t nbytes;
- int nb;
+ static mbstate_t mbs;
- s = *src;
- nbytes = 0;
-
- if (dst == NULL) {
- for (;;) {
- if ((nb = (int)wcrtomb(buf, *s, NULL)) < 0)
- /* Invalid character - wcrtomb() sets errno. */
- return ((size_t)-1);
- else if (*s == L'\0')
- return (nbytes + nb - 1);
- s++;
- nbytes += nb;
- }
- /*NOTREACHED*/
- }
-
- while (len > 0) {
- if (len > (size_t)MB_CUR_MAX) {
- /* Enough space to translate in-place. */
- if ((nb = (int)wcrtomb(dst, *s, NULL)) < 0) {
- *src = s;
- return ((size_t)-1);
- }
- } else {
- /* May not be enough space; use temp. buffer. */
- if ((nb = (int)wcrtomb(buf, *s, NULL)) < 0) {
- *src = s;
- return ((size_t)-1);
- }
- if (nb > (int)len)
- /* MB sequence for character won't fit. */
- break;
- memcpy(dst, buf, nb);
- }
- if (*s == L'\0') {
- *src = NULL;
- return (nbytes + nb - 1);
- }
- s++;
- dst += nb;
- len -= nb;
- nbytes += nb;
- }
- *src = s;
- return (nbytes);
+ if (ps == NULL)
+ ps = &mbs;
+ return (__wcsnrtombs(dst, src, SIZE_T_MAX, len, ps));
}
--- /dev/null
+--- wcsrtombs.c.orig 2004-11-25 11:38:20.000000000 -0800
++++ wcsrtombs.c 2005-02-18 18:36:45.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/wcsrtombs.c,v 1.6 2004/07/21 10:54:57 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <limits.h>
+ #include <stdlib.h>
+ #include <string.h>
+@@ -34,12 +36,18 @@
+ #include "mblocal.h"
+
+ size_t
++wcsrtombs_l(char * __restrict dst, const wchar_t ** __restrict src, size_t len,
++ mbstate_t * __restrict ps, locale_t loc)
++{
++ NORMALIZE_LOCALE(loc);
++ if (ps == NULL)
++ ps = &loc->__mbs_wcsrtombs;
++ return (loc->__lc_ctype->__wcsnrtombs(dst, src, SIZE_T_MAX, len, ps, loc));
++}
++
++size_t
+ wcsrtombs(char * __restrict dst, const wchar_t ** __restrict src, size_t len,
+ mbstate_t * __restrict ps)
+ {
+- static mbstate_t mbs;
+-
+- if (ps == NULL)
+- ps = &mbs;
+- return (__wcsnrtombs(dst, src, SIZE_T_MAX, len, ps));
++ return wcsrtombs_l(dst, src, len, ps, __current_locale());
+ }
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/lib/libc/locale/wcstod.3,v 1.3 2003/03/13 06:29:53 tjr Exp $
+.\" $FreeBSD: src/lib/libc/locale/wcstod.3,v 1.4 2003/05/22 13:02:27 ru Exp $
.\"
.Dd February 22, 2003
.Dt WCSTOD 3
.Nm wcstof ,
.Nm wcstod ,
.Nm wcstold
-.Nd "convert string to float, double or long double"
+.Nd convert string to
+.Vt float , double
+or
+.Vt "long double"
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In wchar.h
.Ft float
.Fn wcstof "const wchar_t * restrict nptr" "wchar_t ** restrict endptr"
-.Ft long double
+.Ft "long double"
.Fn wcstold "const wchar_t * restrict nptr" "wchar_t ** restrict endptr"
.Ft double
.Fn wcstod "const wchar_t * restrict nptr" "wchar_t ** restrict endptr"
.Fn strtod
and
.Fn strtold
-functios.
+functions.
Refer to
.Xr strtod 3
for details.
.Sh SEE ALSO
.Xr strtod 3 ,
-.Xr wcstol 3 ,
+.Xr wcstol 3
.Sh STANDARDS
The
.Fn wcstof ,
--- /dev/null
+--- wcstod.3.orig Fri Mar 11 19:16:16 2005
++++ wcstod.3 Fri Mar 11 19:16:55 2005
+@@ -60,9 +60,16 @@
+ Refer to
+ .Xr strtod 3
+ for details.
++.Pp
++Extended locale versions of these functions are documented in
++.Xr wcstod_l 3 .
++See
++.Xr xlocale 3
++for more information.
+ .Sh SEE ALSO
+ .Xr strtod 3 ,
+-.Xr wcstol 3
++.Xr wcstol 3 ,
++.Xr wcstod_l 3
+ .Sh STANDARDS
+ The
+ .Fn wcstof ,
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/wcstod.c,v 1.2 2003/02/22 00:06:05 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/wcstod.c,v 1.4 2004/04/07 09:47:56 tjr Exp $");
#include <stdlib.h>
#include <wchar.h>
wcstod(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
{
static const mbstate_t initial;
- mbstate_t state;
+ mbstate_t mbs;
double val;
- char *buf, *end, *p;
+ char *buf, *end;
const wchar_t *wcp;
- size_t clen, len;
+ size_t len;
while (iswspace(*nptr))
nptr++;
* duplicates a lot of strtod()'s functionality and slows down the
* most common cases.
*/
- state = initial;
wcp = nptr;
- if ((len = wcsrtombs(NULL, &wcp, 0, &state)) == (size_t)-1) {
+ mbs = initial;
+ if ((len = wcsrtombs(NULL, &wcp, 0, &mbs)) == (size_t)-1) {
if (endptr != NULL)
*endptr = (wchar_t *)nptr;
return (0.0);
}
if ((buf = malloc(len + 1)) == NULL)
return (0.0);
- state = initial;
- wcsrtombs(buf, &wcp, len + 1, &state);
+ mbs = initial;
+ wcsrtombs(buf, &wcp, len + 1, &mbs);
/* Let strtod() do most of the work for us. */
val = strtod(buf, &end);
* where it ended, count multibyte characters to find the
* corresponding position in the wide char string.
*/
- if (endptr != NULL) {
-#if 1 /* Fast, assume 1:1 WC:MBS mapping. */
+ if (endptr != NULL)
+ /* XXX Assume each wide char is one byte. */
*endptr = (wchar_t *)nptr + (end - buf);
- (void)clen;
- (void)p;
-#else /* Slow, conservative approach. */
- state = initial;
- *endptr = (wchar_t *)nptr;
- p = buf;
- while (p < end &&
- (clen = mbrlen(p, end - p, &state)) > 0) {
- p += clen;
- (*endptr)++;
- }
-#endif
- }
free(buf);
--- /dev/null
+--- wcstod.c.orig Thu Nov 25 11:38:20 2004
++++ wcstod.c Fri Feb 18 14:45:42 2005
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/wcstod.c,v 1.4 2004/04/07 09:47:56 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdlib.h>
+ #include <wchar.h>
+ #include <wctype.h>
+@@ -41,7 +43,8 @@
+ * for at least the digits, radix character and letters.
+ */
+ double
+-wcstod(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
++wcstod_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
++ locale_t loc)
+ {
+ static const mbstate_t initial;
+ mbstate_t mbs;
+@@ -50,7 +53,8 @@
+ const wchar_t *wcp;
+ size_t len;
+
+- while (iswspace(*nptr))
++ NORMALIZE_LOCALE(loc);
++ while (iswspace_l(*nptr, loc))
+ nptr++;
+
+ /*
+@@ -65,7 +69,7 @@
+ */
+ wcp = nptr;
+ mbs = initial;
+- if ((len = wcsrtombs(NULL, &wcp, 0, &mbs)) == (size_t)-1) {
++ if ((len = wcsrtombs_l(NULL, &wcp, 0, &mbs, loc)) == (size_t)-1) {
+ if (endptr != NULL)
+ *endptr = (wchar_t *)nptr;
+ return (0.0);
+@@ -73,10 +77,10 @@
+ if ((buf = malloc(len + 1)) == NULL)
+ return (0.0);
+ mbs = initial;
+- wcsrtombs(buf, &wcp, len + 1, &mbs);
++ wcsrtombs_l(buf, &wcp, len + 1, &mbs, loc);
+
+ /* Let strtod() do most of the work for us. */
+- val = strtod(buf, &end);
++ val = strtod_l(buf, &end, loc);
+
+ /*
+ * We only know where the number ended in the _multibyte_
+@@ -91,4 +95,10 @@
+ free(buf);
+
+ return (val);
++}
++
++double
++wcstod(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
++{
++ return wcstod_l(nptr, endptr, __current_locale());
+ }
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/wcstof.c,v 1.1 2003/03/13 06:29:53 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/wcstof.c,v 1.3 2004/04/07 09:47:56 tjr Exp $");
#include <stdlib.h>
#include <wchar.h>
wcstof(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
{
static const mbstate_t initial;
- mbstate_t state;
+ mbstate_t mbs;
float val;
- char *buf, *end, *p;
+ char *buf, *end;
const wchar_t *wcp;
- size_t clen, len;
+ size_t len;
while (iswspace(*nptr))
nptr++;
- state = initial;
wcp = nptr;
- if ((len = wcsrtombs(NULL, &wcp, 0, &state)) == (size_t)-1) {
+ mbs = initial;
+ if ((len = wcsrtombs(NULL, &wcp, 0, &mbs)) == (size_t)-1) {
if (endptr != NULL)
*endptr = (wchar_t *)nptr;
return (0.0);
}
if ((buf = malloc(len + 1)) == NULL)
return (0.0);
- state = initial;
- wcsrtombs(buf, &wcp, len + 1, &state);
+ mbs = initial;
+ wcsrtombs(buf, &wcp, len + 1, &mbs);
val = strtof(buf, &end);
- if (endptr != NULL) {
-#if 1 /* Fast, assume 1:1 WC:MBS mapping. */
+ if (endptr != NULL)
*endptr = (wchar_t *)nptr + (end - buf);
- (void)clen;
- (void)p;
-#else /* Slow, conservative approach. */
- state = initial;
- *endptr = (wchar_t *)nptr;
- p = buf;
- while (p < end &&
- (clen = mbrlen(p, end - p, &state)) > 0) {
- p += clen;
- (*endptr)++;
- }
-#endif
- }
free(buf);
--- /dev/null
+--- wcstof.c.orig Thu Nov 25 11:38:20 2004
++++ wcstof.c Fri Feb 18 14:48:11 2005
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/wcstof.c,v 1.3 2004/04/07 09:47:56 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdlib.h>
+ #include <wchar.h>
+ #include <wctype.h>
+@@ -35,7 +37,8 @@
+ * See wcstod() for comments as to the logic used.
+ */
+ float
+-wcstof(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
++wcstof_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
++ locale_t loc)
+ {
+ static const mbstate_t initial;
+ mbstate_t mbs;
+@@ -44,12 +47,13 @@
+ const wchar_t *wcp;
+ size_t len;
+
+- while (iswspace(*nptr))
++ NORMALIZE_LOCALE(loc);
++ while (iswspace_l(*nptr, loc))
+ nptr++;
+
+ wcp = nptr;
+ mbs = initial;
+- if ((len = wcsrtombs(NULL, &wcp, 0, &mbs)) == (size_t)-1) {
++ if ((len = wcsrtombs_l(NULL, &wcp, 0, &mbs, loc)) == (size_t)-1) {
+ if (endptr != NULL)
+ *endptr = (wchar_t *)nptr;
+ return (0.0);
+@@ -57,9 +61,9 @@
+ if ((buf = malloc(len + 1)) == NULL)
+ return (0.0);
+ mbs = initial;
+- wcsrtombs(buf, &wcp, len + 1, &mbs);
++ wcsrtombs_l(buf, &wcp, len + 1, &mbs, loc);
+
+- val = strtof(buf, &end);
++ val = strtof_l(buf, &end, loc);
+
+ if (endptr != NULL)
+ *endptr = (wchar_t *)nptr + (end - buf);
+@@ -67,4 +71,10 @@
+ free(buf);
+
+ return (val);
++}
++
++float
++wcstof(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
++{
++ return wcstof_l(nptr, endptr, __current_locale());
+ }
--- /dev/null
+--- wcstoimax.c.orig 2003-05-20 15:21:45.000000000 -0700
++++ wcstoimax.c 2005-02-23 16:06:32.000000000 -0800
+@@ -40,6 +40,8 @@
+ #endif
+ __FBSDID("$FreeBSD: src/lib/libc/locale/wcstoimax.c,v 1.2 2003/01/01 18:48:43 schweikh Exp $");
+
++#include "xlocale_private.h"
++
+ #include <errno.h>
+ #include <inttypes.h>
+ #include <stdlib.h>
+@@ -50,8 +52,8 @@
+ * Convert a wide character string to an intmax_t integer.
+ */
+ intmax_t
+-wcstoimax(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
+- int base)
++wcstoimax_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
++ int base, locale_t loc)
+ {
+ const wchar_t *s;
+ uintmax_t acc;
+@@ -59,13 +61,14 @@
+ uintmax_t cutoff;
+ int neg, any, cutlim;
+
++ NORMALIZE_LOCALE(loc);
+ /*
+ * See strtoimax for comments as to the logic used.
+ */
+ s = nptr;
+ do {
+ c = *s++;
+- } while (iswspace(c));
++ } while (iswspace_l(c, loc));
+ if (c == L'-') {
+ neg = 1;
+ c = *s++;
+@@ -92,8 +95,8 @@
+ cutoff /= base;
+ for ( ; ; c = *s++) {
+ #ifdef notyet
+- if (iswdigit(c))
+- c = digittoint(c);
++ if (iswdigit_l(c, loc))
++ c = digittoint_l(c, loc);
+ else
+ #endif
+ if (c >= L'0' && c <= L'9')
+@@ -126,3 +129,10 @@
+ *endptr = (wchar_t *)(any ? s - 1 : nptr);
+ return (acc);
+ }
++
++intmax_t
++wcstoimax(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
++ int base)
++{
++ return wcstoimax_l(nptr, endptr, base, __current_locale());
++}
--- /dev/null
+--- wcstol.3.orig Fri Mar 11 19:16:13 2005
++++ wcstol.3 Fri Mar 11 19:17:53 2005
+@@ -78,9 +78,16 @@
+ Refer to their manual pages (for example
+ .Xr strtol 3 )
+ for details.
++.Pp
++Extended locale versions of these functions are documented in
++.Xr wcstol_l 3 .
++See
++.Xr xlocale 3
++for more information.
+ .Sh SEE ALSO
+ .Xr strtol 3 ,
+-.Xr strtoul 3
++.Xr strtoul 3 ,
++.Xr wcstol_l 3
+ .Sh STANDARDS
+ The
+ .Fn wcstol ,
--- /dev/null
+--- wcstol.c.orig Tue May 20 15:21:45 2003
++++ wcstol.c Fri Feb 18 14:50:27 2005
+@@ -34,6 +34,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/wcstol.c,v 1.1 2002/09/08 13:27:26 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <ctype.h>
+ #include <errno.h>
+ #include <limits.h>
+@@ -44,7 +46,8 @@
+ * Convert a string to a long integer.
+ */
+ long
+-wcstol(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, int base)
++wcstol_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
++ int base, locale_t loc)
+ {
+ const wchar_t *s;
+ unsigned long acc;
+@@ -52,13 +55,14 @@
+ unsigned long cutoff;
+ int neg, any, cutlim;
+
++ NORMALIZE_LOCALE(loc);
+ /*
+ * See strtol for comments as to the logic used.
+ */
+ s = nptr;
+ do {
+ c = *s++;
+- } while (iswspace(c));
++ } while (iswspace_l(c, loc));
+ if (c == '-') {
+ neg = 1;
+ c = *s++;
+@@ -85,8 +89,8 @@
+ cutoff /= base;
+ for ( ; ; c = *s++) {
+ #ifdef notyet
+- if (iswdigit(c))
+- c = digittoint(c);
++ if (iswdigit_l(c, loc))
++ c = digittoint_l(c, loc);
+ else
+ #endif
+ if (c >= L'0' && c <= L'9')
+@@ -118,4 +122,10 @@
+ if (endptr != NULL)
+ *endptr = (wchar_t *)(any ? s - 1 : nptr);
+ return (acc);
++}
++
++long
++wcstol(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, int base)
++{
++ return wcstol_l(nptr, endptr, base, __current_locale());
+ }
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/wcstold.c,v 1.1 2003/03/13 06:29:53 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/wcstold.c,v 1.4 2004/04/07 09:47:56 tjr Exp $");
#include <stdlib.h>
#include <wchar.h>
wcstold(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
{
static const mbstate_t initial;
- mbstate_t state;
+ mbstate_t mbs;
long double val;
- char *buf, *end, *p;
+ char *buf, *end;
const wchar_t *wcp;
- size_t clen, len;
+ size_t len;
while (iswspace(*nptr))
nptr++;
- state = initial;
wcp = nptr;
- if ((len = wcsrtombs(NULL, &wcp, 0, &state)) == (size_t)-1) {
+ mbs = initial;
+ if ((len = wcsrtombs(NULL, &wcp, 0, &mbs)) == (size_t)-1) {
if (endptr != NULL)
*endptr = (wchar_t *)nptr;
return (0.0);
}
if ((buf = malloc(len + 1)) == NULL)
return (0.0);
- state = initial;
- wcsrtombs(buf, &wcp, len + 1, &state);
+ mbs = initial;
+ wcsrtombs(buf, &wcp, len + 1, &mbs);
val = strtold(buf, &end);
- if (endptr != NULL) {
-#if 1 /* Fast, assume 1:1 WC:MBS mapping. */
+ if (endptr != NULL)
*endptr = (wchar_t *)nptr + (end - buf);
- (void)clen;
- (void)p;
-#else /* Slow, conservative approach. */
- state = initial;
- *endptr = (wchar_t *)nptr;
- p = buf;
- while (p < end &&
- (clen = mbrlen(p, end - p, &state)) > 0) {
- p += clen;
- (*endptr)++;
- }
-#endif
- }
free(buf);
--- /dev/null
+--- wcstold.c.orig Thu Nov 25 11:38:20 2004
++++ wcstold.c Fri Feb 18 14:52:24 2005
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/wcstold.c,v 1.4 2004/04/07 09:47:56 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdlib.h>
+ #include <wchar.h>
+ #include <wctype.h>
+@@ -35,7 +37,8 @@
+ * See wcstod() for comments as to the logic used.
+ */
+ long double
+-wcstold(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
++wcstold_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
++ locale_t loc)
+ {
+ static const mbstate_t initial;
+ mbstate_t mbs;
+@@ -44,12 +47,13 @@
+ const wchar_t *wcp;
+ size_t len;
+
+- while (iswspace(*nptr))
++ NORMALIZE_LOCALE(loc);
++ while (iswspace_l(*nptr, loc))
+ nptr++;
+
+ wcp = nptr;
+ mbs = initial;
+- if ((len = wcsrtombs(NULL, &wcp, 0, &mbs)) == (size_t)-1) {
++ if ((len = wcsrtombs_l(NULL, &wcp, 0, &mbs, loc)) == (size_t)-1) {
+ if (endptr != NULL)
+ *endptr = (wchar_t *)nptr;
+ return (0.0);
+@@ -57,9 +61,9 @@
+ if ((buf = malloc(len + 1)) == NULL)
+ return (0.0);
+ mbs = initial;
+- wcsrtombs(buf, &wcp, len + 1, &mbs);
++ wcsrtombs_l(buf, &wcp, len + 1, &mbs, loc);
+
+- val = strtold(buf, &end);
++ val = strtold_l(buf, &end, loc);
+
+ if (endptr != NULL)
+ *endptr = (wchar_t *)nptr + (end - buf);
+@@ -67,4 +71,10 @@
+ free(buf);
+
+ return (val);
++}
++
++long double
++wcstold(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
++{
++ return wcstold_l(nptr, endptr, __current_locale());
+ }
--- /dev/null
+--- wcstoll.c.orig Tue May 20 15:21:45 2003
++++ wcstoll.c Fri Feb 18 14:54:25 2005
+@@ -40,6 +40,8 @@
+ #endif
+ __FBSDID("$FreeBSD: src/lib/libc/locale/wcstoll.c,v 1.1 2002/09/22 08:06:45 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <errno.h>
+ #include <limits.h>
+ #include <stdlib.h>
+@@ -50,7 +52,8 @@
+ * Convert a wide character string to a long long integer.
+ */
+ long long
+-wcstoll(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, int base)
++wcstoll_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
++ int base, locale_t loc)
+ {
+ const wchar_t *s;
+ unsigned long long acc;
+@@ -58,13 +61,14 @@
+ unsigned long long cutoff;
+ int neg, any, cutlim;
+
++ NORMALIZE_LOCALE(loc);
+ /*
+ * See strtoll for comments as to the logic used.
+ */
+ s = nptr;
+ do {
+ c = *s++;
+- } while (iswspace(c));
++ } while (iswspace_l(c, loc));
+ if (c == L'-') {
+ neg = 1;
+ c = *s++;
+@@ -91,8 +95,8 @@
+ cutoff /= base;
+ for ( ; ; c = *s++) {
+ #ifdef notyet
+- if (iswdigit(c))
+- c = digittoint(c);
++ if (iswdigit_l(c, loc))
++ c = digittoint_l(c, loc);
+ else
+ #endif
+ if (c >= L'0' && c <= L'9')
+@@ -124,4 +128,10 @@
+ if (endptr != NULL)
+ *endptr = (wchar_t *)(any ? s - 1 : nptr);
+ return (acc);
++}
++
++long long
++wcstoll(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, int base)
++{
++ return wcstoll_l(nptr, endptr, base, __current_locale());
+ }
--- /dev/null
+.\" Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved.
+.\" Copyright (c) 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Donn Seeley of BSDI.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" From @(#)multibyte.3 8.1 (Berkeley) 6/4/93
+.\" From FreeBSD: src/lib/libc/locale/multibyte.3,v 1.22 2003/11/08 03:23:11 tjr Exp
+.\" $FreeBSD: src/lib/libc/locale/wcstombs.3,v 1.4 2004/07/05 06:36:36 ru Exp $
+.\"
+.Dd April 8, 2004
+.Dt WCSTOMBS 3
+.Os
+.Sh NAME
+.Nm wcstombs
+.Nd convert a wide-character string to a character string
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdlib.h
+.Ft size_t
+.Fo wcstombs
+.Fa "char * restrict mbstring" "const wchar_t * restrict wcstring"
+.Fa "size_t nbytes"
+.Fc
+.Sh DESCRIPTION
+The
+.Fn wcstombs
+function converts a wide character string
+.Fa wcstring
+into a multibyte character string,
+.Fa mbstring ,
+beginning in the initial conversion state.
+Up to
+.Fa nbytes
+bytes are stored in
+.Fa mbstring .
+Partial multibyte characters at the end of the string are not stored.
+The multibyte character string is null terminated if there is room.
+.Sh RETURN VALUES
+The
+.Fn wcstombs
+function returns the number of bytes converted
+(not including any terminating null), if successful, otherwise it returns
+.Po Vt size_t Pc Ns \-1 .
+.Sh ERRORS
+The
+.Fn wcstombs
+function will fail if:
+.Bl -tag -width Er
+.It Bq Er EILSEQ
+An invalid wide character was encountered.
+.It Bq Er EINVAL
+The conversion state is invalid.
+.El
+.Sh SEE ALSO
+.Xr mbstowcs 3 ,
+.Xr multibyte 3 ,
+.Xr wcsrtombs 3 ,
+.Xr wctomb 3
+.Sh STANDARDS
+The
+.Fn wcstombs
+function conforms to
+.St -isoC-99 .
--- /dev/null
+--- wcstombs.3.orig Fri Mar 11 19:44:47 2005
++++ wcstombs.3 Fri Mar 11 19:48:16 2005
+@@ -41,7 +41,8 @@
+ .Dt WCSTOMBS 3
+ .Os
+ .Sh NAME
+-.Nm wcstombs
++.Nm wcstombs ,
++.Nm wcstombs_l
+ .Nd convert a wide-character string to a character string
+ .Sh LIBRARY
+ .Lb libc
+@@ -52,6 +53,12 @@
+ .Fa "char * restrict mbstring" "const wchar_t * restrict wcstring"
+ .Fa "size_t nbytes"
+ .Fc
++.In xlocale.h
++.Ft size_t
++.Fo wcstombs_l
++.Fa "char * restrict mbstring" "const wchar_t * restrict wcstring"
++.Fa "size_t nbytes" "locale_t loc"
++.Fc
+ .Sh DESCRIPTION
+ The
+ .Fn wcstombs
+@@ -66,6 +73,14 @@
+ .Fa mbstring .
+ Partial multibyte characters at the end of the string are not stored.
+ The multibyte character string is null terminated if there is room.
++.Pp
++While the
++.Fn wcstombs
++function uses the current locale, the
++.Fn wcstombs_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn wcstombs
+@@ -86,7 +101,8 @@
+ .Xr mbstowcs 3 ,
+ .Xr multibyte 3 ,
+ .Xr wcsrtombs 3 ,
+-.Xr wctomb 3
++.Xr wctomb 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn wcstombs
/*-
- * Copyright (c) 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Paul Borman at Krystal Technologies.
+ * Copyright (c) 2002-2004 Tim J. Robbins.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * 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 REGENTS OR CONTRIBUTORS BE LIABLE
+ * 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)
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/wcstombs.c,v 1.5 2002/10/27 10:41:21 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/wcstombs.c,v 1.10 2004/07/21 10:54:57 tjr Exp $");
-#include <errno.h>
-#include <stdlib.h>
#include <limits.h>
-#include <stddef.h>
-#include <rune.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include "mblocal.h"
size_t
wcstombs(char * __restrict s, const wchar_t * __restrict pwcs, size_t n)
{
- char buf[MB_LEN_MAX];
- char *e;
- int cnt, nb;
-
- if (pwcs == NULL || n > INT_MAX) {
- errno = EINVAL;
- return (-1);
- }
-
- cnt = 0;
-
- if (s == NULL) {
- /* Convert and count only, do not store. */
- while (*pwcs != L'\0') {
- if (sputrune(*pwcs++, buf, MB_LEN_MAX, &e) == 0) {
- errno = EILSEQ;
- return (-1);
- }
- cnt += e - buf;
- }
- return (cnt);
- }
-
- /* Convert, store and count characters. */
- nb = n;
- while (nb > 0) {
- if (*pwcs == L'\0') {
- *s = '\0';
- break;
- }
- if (sputrune(*pwcs++, s, nb, &e) == 0) {
- errno = EILSEQ;
- return (-1);
- }
- if (e == NULL) /* too long */
- return (cnt);
- cnt += e - s;
- nb -= e - s;
- s = e;
- }
+ static const mbstate_t initial;
+ mbstate_t mbs;
- return (cnt);
+ mbs = initial;
+ return (__wcsnrtombs(s, &pwcs, SIZE_T_MAX, n, &mbs));
}
--- /dev/null
+--- wcstombs.c.orig Thu Nov 25 11:38:20 2004
++++ wcstombs.c Fri Feb 18 17:17:37 2005
+@@ -27,17 +27,27 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/wcstombs.c,v 1.10 2004/07/21 10:54:57 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <limits.h>
+ #include <stdlib.h>
+ #include <wchar.h>
+ #include "mblocal.h"
+
+ size_t
+-wcstombs(char * __restrict s, const wchar_t * __restrict pwcs, size_t n)
++wcstombs_l(char * __restrict s, const wchar_t * __restrict pwcs, size_t n,
++ locale_t loc)
+ {
+ static const mbstate_t initial;
+ mbstate_t mbs;
+
++ NORMALIZE_LOCALE(loc);
+ mbs = initial;
+- return (__wcsnrtombs(s, &pwcs, SIZE_T_MAX, n, &mbs));
++ return (loc->__lc_ctype->__wcsnrtombs(s, &pwcs, SIZE_T_MAX, n, &mbs, loc));
++}
++
++size_t
++wcstombs(char * __restrict s, const wchar_t * __restrict pwcs, size_t n)
++{
++ return wcstombs_l(s, pwcs, n, __current_locale());
+ }
--- /dev/null
+--- wcstoul.c.orig Tue May 20 15:21:45 2003
++++ wcstoul.c Fri Feb 18 14:56:18 2005
+@@ -34,6 +34,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/wcstoul.c,v 1.1 2002/09/08 13:27:26 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <ctype.h>
+ #include <errno.h>
+ #include <limits.h>
+@@ -44,7 +46,8 @@
+ * Convert a wide character string to an unsigned long integer.
+ */
+ unsigned long
+-wcstoul(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, int base)
++wcstoul_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
++ int base, locale_t loc)
+ {
+ const wchar_t *s;
+ unsigned long acc;
+@@ -52,13 +55,14 @@
+ unsigned long cutoff;
+ int neg, any, cutlim;
+
++ NORMALIZE_LOCALE(loc);
+ /*
+ * See strtol for comments as to the logic used.
+ */
+ s = nptr;
+ do {
+ c = *s++;
+- } while (iswspace(c));
++ } while (iswspace_l(c, loc));
+ if (c == L'-') {
+ neg = 1;
+ c = *s++;
+@@ -83,8 +87,8 @@
+ cutlim = ULONG_MAX % base;
+ for ( ; ; c = *s++) {
+ #ifdef notyet
+- if (iswdigit(c))
+- c = digittoint(c);
++ if (iswdigit_l(c, loc))
++ c = digittoint_l(c, loc);
+ else
+ #endif
+ if (c >= L'0' && c <= L'9')
+@@ -116,4 +120,10 @@
+ if (endptr != NULL)
+ *endptr = (wchar_t *)(any ? s - 1 : nptr);
+ return (acc);
++}
++
++unsigned long
++wcstoul(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, int base)
++{
++ return wcstoul_l(nptr, endptr, base, __current_locale());
+ }
--- /dev/null
+--- wcstoull.c.orig Tue May 20 15:21:45 2003
++++ wcstoull.c Fri Feb 18 14:58:24 2005
+@@ -40,6 +40,8 @@
+ #endif
+ __FBSDID("$FreeBSD: src/lib/libc/locale/wcstoull.c,v 1.1 2002/09/22 08:06:45 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <errno.h>
+ #include <limits.h>
+ #include <stdlib.h>
+@@ -50,8 +52,8 @@
+ * Convert a wide character string to an unsigned long long integer.
+ */
+ unsigned long long
+-wcstoull(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
+- int base)
++wcstoull_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
++ int base, locale_t loc)
+ {
+ const wchar_t *s;
+ unsigned long long acc;
+@@ -59,13 +61,14 @@
+ unsigned long long cutoff;
+ int neg, any, cutlim;
+
++ NORMALIZE_LOCALE(loc);
+ /*
+ * See strtoull for comments as to the logic used.
+ */
+ s = nptr;
+ do {
+ c = *s++;
+- } while (iswspace(c));
++ } while (iswspace_l(c, loc));
+ if (c == L'-') {
+ neg = 1;
+ c = *s++;
+@@ -90,8 +93,8 @@
+ cutlim = ULLONG_MAX % base;
+ for ( ; ; c = *s++) {
+ #ifdef notyet
+- if (iswdigit(c))
+- c = digittoint(c);
++ if (iswdigit_l(c, loc))
++ c = digittoint_l(c, loc);
+ else
+ #endif
+ if (c >= L'0' && c <= L'9')
+@@ -123,4 +126,11 @@
+ if (endptr != NULL)
+ *endptr = (wchar_t *)(any ? s - 1 : nptr);
+ return (acc);
++}
++
++unsigned long long
++wcstoull(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
++ int base)
++{
++ return wcstoull_l(nptr, endptr, base, __current_locale());
+ }
--- /dev/null
+--- wcstoumax.c.orig 2003-05-20 15:21:45.000000000 -0700
++++ wcstoumax.c 2005-02-23 16:08:34.000000000 -0800
+@@ -40,6 +40,8 @@
+ #endif
+ __FBSDID("$FreeBSD: src/lib/libc/locale/wcstoumax.c,v 1.1 2002/09/22 08:06:45 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <errno.h>
+ #include <inttypes.h>
+ #include <stdlib.h>
+@@ -50,8 +52,8 @@
+ * Convert a wide character string to a uintmax_t integer.
+ */
+ uintmax_t
+-wcstoumax(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
+- int base)
++wcstoumax_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
++ int base, locale_t loc)
+ {
+ const wchar_t *s;
+ uintmax_t acc;
+@@ -59,13 +61,14 @@
+ uintmax_t cutoff;
+ int neg, any, cutlim;
+
++ NORMALIZE_LOCALE(loc);
+ /*
+ * See strtoimax for comments as to the logic used.
+ */
+ s = nptr;
+ do {
+ c = *s++;
+- } while (iswspace(c));
++ } while (iswspace_l(c, loc));
+ if (c == L'-') {
+ neg = 1;
+ c = *s++;
+@@ -90,8 +93,8 @@
+ cutlim = UINTMAX_MAX % base;
+ for ( ; ; c = *s++) {
+ #ifdef notyet
+- if (iswdigit(c))
+- c = digittoint(c);
++ if (iswdigit_l(c, loc))
++ c = digittoint_l(c, loc);
+ else
+ #endif
+ if (c >= L'0' && c <= L'9')
+@@ -124,3 +127,10 @@
+ *endptr = (wchar_t *)(any ? s - 1 : nptr);
+ return (acc);
+ }
++
++uintmax_t
++wcstoumax(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
++ int base)
++{
++ return wcstoumax_l(nptr, endptr, base, __current_locale());
++}
/*-
- * Copyright (c) 2002 Tim J. Robbins.
+ * Copyright (c) 2002-2004 Tim J. Robbins.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/wctob.c,v 1.1 2002/08/03 13:49:55 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/wctob.c,v 1.4 2004/05/12 14:26:54 tjr Exp $");
-#include <rune.h>
+#include <limits.h>
+#include <stdio.h>
#include <wchar.h>
+#include "mblocal.h"
int
wctob(wint_t c)
{
- char cc;
+ static const mbstate_t initial;
+ mbstate_t mbs = initial;
+ char buf[MB_LEN_MAX];
- if (c == WEOF || sputrune(c, &cc, 1, NULL) != 1)
+ if (c == WEOF || __wcrtomb(buf, c, &mbs) != 1)
return (EOF);
- return ((unsigned char)cc);
+ return ((unsigned char)*buf);
}
--- /dev/null
+--- wctob.c.orig 2004-11-25 11:38:20.000000000 -0800
++++ wctob.c 2005-02-18 18:16:08.000000000 -0800
+@@ -27,19 +27,28 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/wctob.c,v 1.4 2004/05/12 14:26:54 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <limits.h>
+ #include <stdio.h>
+ #include <wchar.h>
+ #include "mblocal.h"
+
+ int
+-wctob(wint_t c)
++wctob_l(wint_t c, locale_t loc)
+ {
+ static const mbstate_t initial;
+ mbstate_t mbs = initial;
+ char buf[MB_LEN_MAX];
+
+- if (c == WEOF || __wcrtomb(buf, c, &mbs) != 1)
++ NORMALIZE_LOCALE(loc);
++ if (c == WEOF || loc->__lc_ctype->__wcrtomb(buf, c, &mbs, loc) != 1)
+ return (EOF);
+ return ((unsigned char)*buf);
+ }
++
++int
++wctob(wint_t c)
++{
++ return wctob_l(c, __current_locale());
++}
--- /dev/null
+.\" Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved.
+.\" Copyright (c) 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Donn Seeley of BSDI.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" From @(#)multibyte.3 8.1 (Berkeley) 6/4/93
+.\" From FreeBSD: src/lib/libc/locale/multibyte.3,v 1.22 2003/11/08 03:23:11 tjr Exp
+.\" $FreeBSD: src/lib/libc/locale/wctomb.3,v 1.3 2004/07/05 06:36:36 ru Exp $
+.\"
+.Dd April 8, 2004
+.Dt WCTOMB 3
+.Os
+.Sh NAME
+.Nm wctomb
+.Nd convert a wide-character code to a character
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdlib.h
+.Ft int
+.Fn wctomb "char *mbchar" "wchar_t wchar"
+.Sh DESCRIPTION
+The
+.Fn wctomb
+function converts a wide character
+.Fa wchar
+into a multibyte character and stores
+the result in
+.Fa mbchar .
+The object pointed to by
+.Fa mbchar
+must be large enough to accommodate the multibyte character, which
+may be up to
+.Dv MB_LEN_MAX
+bytes.
+.Pp
+A call with a null
+.Fa mbchar
+pointer returns nonzero if the current locale requires shift states,
+zero otherwise;
+if shift states are required, the shift state is reset to the initial state.
+.Sh RETURN VALUES
+If
+.Fa mbchar
+is
+.Dv NULL ,
+the
+.Fn wctomb
+function returns nonzero if shift states are supported,
+zero otherwise.
+If
+.Fa mbchar
+is valid,
+.Fn wctomb
+returns
+the number of bytes processed in
+.Fa mbchar ,
+or \-1 if no multibyte character
+could be recognized or converted.
+In this case,
+.Fn wctomb Ns 's
+internal conversion state is undefined.
+.Sh ERRORS
+The
+.Fn wctomb
+function will fail if:
+.Bl -tag -width Er
+.It Bq Er EILSEQ
+An invalid multibyte sequence was detected.
+.It Bq Er EINVAL
+The internal conversion state is invalid.
+.El
+.Sh SEE ALSO
+.Xr mbtowc 3 ,
+.Xr wcrtomb 3 ,
+.Xr wcstombs 3 ,
+.Xr wctob 3
+.Sh STANDARDS
+The
+.Fn wctomb
+function conforms to
+.St -isoC-99 .
--- /dev/null
+--- wctomb.3.orig Fri Mar 11 19:44:47 2005
++++ wctomb.3 Fri Mar 11 19:47:38 2005
+@@ -41,7 +41,8 @@
+ .Dt WCTOMB 3
+ .Os
+ .Sh NAME
+-.Nm wctomb
++.Nm wctomb ,
++.Nm wctomb_l
+ .Nd convert a wide-character code to a character
+ .Sh LIBRARY
+ .Lb libc
+@@ -49,6 +50,9 @@
+ .In stdlib.h
+ .Ft int
+ .Fn wctomb "char *mbchar" "wchar_t wchar"
++.In xlocale.h
++.Ft int
++.Fn wctomb_l "char *mbchar" "wchar_t wchar" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn wctomb
+@@ -69,6 +73,14 @@
+ pointer returns nonzero if the current locale requires shift states,
+ zero otherwise;
+ if shift states are required, the shift state is reset to the initial state.
++.Pp
++While the
++.Fn wctomb
++function uses the current locale, the
++.Fn wctomb_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ If
+ .Fa mbchar
+@@ -104,7 +116,8 @@
+ .Xr mbtowc 3 ,
+ .Xr wcrtomb 3 ,
+ .Xr wcstombs 3 ,
+-.Xr wctob 3
++.Xr wctob 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn wctomb
/*-
- * Copyright (c) 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Paul Borman at Krystal Technologies.
+ * Copyright (c) 2002-2004 Tim J. Robbins.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * 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 REGENTS OR CONTRIBUTORS BE LIABLE
+ * 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)
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/wctomb.c,v 1.3 2002/10/27 10:41:21 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/wctomb.c,v 1.8 2004/07/29 06:18:40 tjr Exp $");
-#include <errno.h>
#include <stdlib.h>
-#include <limits.h>
-#include <stddef.h>
-#include <rune.h>
+#include <wchar.h>
+#include "mblocal.h"
int
wctomb(char *s, wchar_t wchar)
{
- char *e;
+ static const mbstate_t initial;
+ static mbstate_t mbs;
+ size_t rval;
- if (s == NULL)
+ if (s == NULL) {
/* No support for state dependent encodings. */
- return (0);
-
- if (wchar == L'\0') {
- *s = '\0';
- return (1);
+ mbs = initial;
+ return (0);
}
-
- sputrune(wchar, s, MB_CUR_MAX, &e);
- if (e == NULL) {
- errno = EILSEQ;
+ if ((rval = __wcrtomb(s, wchar, &mbs)) == (size_t)-1)
return (-1);
- }
- return (e - s);
+ return ((int)rval);
}
--- /dev/null
+--- wctomb.c.orig 2004-11-25 11:38:20.000000000 -0800
++++ wctomb.c 2005-02-18 18:40:43.000000000 -0800
+@@ -27,23 +27,31 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/wctomb.c,v 1.8 2004/07/29 06:18:40 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdlib.h>
+ #include <wchar.h>
+ #include "mblocal.h"
+
+ int
+-wctomb(char *s, wchar_t wchar)
++wctomb_l(char *s, wchar_t wchar, locale_t loc)
+ {
+ static const mbstate_t initial;
+- static mbstate_t mbs;
+ size_t rval;
+
++ NORMALIZE_LOCALE(loc);
+ if (s == NULL) {
+ /* No support for state dependent encodings. */
+- mbs = initial;
++ loc->__mbs_wctomb = initial;
+ return (0);
+ }
+- if ((rval = __wcrtomb(s, wchar, &mbs)) == (size_t)-1)
++ if ((rval = loc->__lc_ctype->__wcrtomb(s, wchar, &loc->__mbs_wctomb, loc)) == (size_t)-1)
+ return (-1);
+ return ((int)rval);
+ }
++
++int
++wctomb(char *s, wchar_t wchar)
++{
++ return wctomb_l(s, wchar, __current_locale());
++}
--- /dev/null
+--- wctrans.3.orig Fri Mar 11 18:13:15 2005
++++ wctrans.3 Fri Mar 11 18:14:31 2005
+@@ -28,7 +28,8 @@
+ .Dt WCTRANS 3
+ .Os
+ .Sh NAME
+-.Nm towctrans , wctrans
++.Nm towctrans , wctrans ,
++.Nm towctrans_l , wctrans_l
+ .Nd "wide character mapping functions"
+ .Sh LIBRARY
+ .Lb libc
+@@ -38,6 +39,11 @@
+ .Fn towctrans "wint_t wc" "wctrans_t desc"
+ .Ft wctrans_t
+ .Fn wctrans "const char *charclass"
++.In xlocale.h
++.Ft wint_t
++.Fn towctrans_l "wint_t wc" "wctrans_t desc" "locale_t loc"
++.Ft wctrans_t
++.Fn wctrans_l "const char *charclass" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn wctrans
+@@ -58,6 +64,18 @@
+ .Fa wc
+ according to the mapping described by
+ .Fa desc .
++.Pp
++While the
++.Fn towctrans
++and
++.Fn wctrans
++functions use the current locale, the
++.Fn towctrans_l
++and
++.Fn wctrans_l
++functions may be passed locales directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn towctrans
+@@ -105,7 +123,8 @@
+ .Sh SEE ALSO
+ .Xr tolower 3 ,
+ .Xr toupper 3 ,
+-.Xr wctype 3
++.Xr wctype 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn towctrans
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/wctrans.c,v 1.2 2002/11/09 05:19:08 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/wctrans.c,v 1.3 2003/11/01 08:20:58 tjr Exp $");
-#include <ctype.h>
#include <errno.h>
#include <string.h>
#include <wctype.h>
_WCT_TOUPPER = 2
};
-/*
- * TODO: Supply a macro version of this.
- */
wint_t
towctrans(wint_t wc, wctrans_t desc)
{
--- /dev/null
+--- wctrans.c.orig 2004-11-25 11:38:20.000000000 -0800
++++ wctrans.c 2005-02-19 14:30:32.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/wctrans.c,v 1.3 2003/11/01 08:20:58 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <errno.h>
+ #include <string.h>
+ #include <wctype.h>
+@@ -38,15 +40,16 @@
+ };
+
+ wint_t
+-towctrans(wint_t wc, wctrans_t desc)
++towctrans_l(wint_t wc, wctrans_t desc, locale_t loc)
+ {
+
++ NORMALIZE_LOCALE(loc);
+ switch (desc) {
+ case _WCT_TOLOWER:
+- wc = towlower(wc);
++ wc = towlower_l(wc, loc);
+ break;
+ case _WCT_TOUPPER:
+- wc = towupper(wc);
++ wc = towupper_l(wc, loc);
+ break;
+ case _WCT_ERROR:
+ default:
+@@ -57,6 +60,12 @@
+ return (wc);
+ }
+
++wint_t
++towctrans(wint_t wc, wctrans_t desc)
++{
++ return towctrans_l(wc, desc, __current_locale());
++}
++
+ wctrans_t
+ wctrans(const char *charclass)
+ {
+@@ -78,3 +87,14 @@
+ errno = EINVAL;
+ return (ccls[i].trans);
+ }
++
++/*
++ * The extended locale version just calls the regular version. If there
++ * is ever support for arbitrary per-locale translations, this need to
++ * be modified.
++ */
++wctrans_t
++wctrans_l(const char *charclass, locale_t loc)
++{
++ return wctrans(charclass);
++}
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/lib/libc/locale/wctype.3,v 1.4 2002/11/29 17:35:09 ru Exp $
+.\" $FreeBSD: src/lib/libc/locale/wctype.3,v 1.5 2004/03/27 08:59:21 tjr Exp $
.\"
-.Dd October 3, 2002
+.Dd March 27, 2004
.Dt WCTYPE 3
.Os
.Sh NAME
.Fn iswctype .
.Pp
The following character class names are recognised:
-.Bl -column -offset indent ".Li alnum" ".Li cntrl" ".Li phonogram" ".Li print" ".Li special"
-.It Li "alnum cntrl ideogram print special"
-.It Li "alpha digit lower punct upper"
-.It Li "blank graph phonogram space xdigit"
+.Bl -column -offset indent ".Li alnum" ".Li cntrl" ".Li ideogram" ".Li print" ".Li space"
+.It Li "alnum cntrl ideogram print space xdigit"
+.It Li "alpha digit lower punct special"
+.It Li "blank graph phonogram rune upper"
.El
.Pp
The
The
.Dq Li ideogram ,
.Dq Li phonogram
+.Dq Li special ,
and
-.Dq Li special
+.Dq Li rune
character classes are extensions.
.Sh HISTORY
The
--- /dev/null
+--- wctype.3.orig Fri Mar 11 18:15:32 2005
++++ wctype.3 Fri Mar 11 18:19:55 2005
+@@ -28,7 +28,8 @@
+ .Dt WCTYPE 3
+ .Os
+ .Sh NAME
+-.Nm iswctype , wctype
++.Nm iswctype , wctype ,
++.Nm iswctype_l , wctype_l
+ .Nd "wide character class functions"
+ .Sh LIBRARY
+ .Lb libc
+@@ -38,6 +39,11 @@
+ .Fn iswctype "wint_t wc" "wctype_t charclass"
+ .Ft wctype_t
+ .Fn wctype "const char *property"
++.In xlocale.h
++.Ft int
++.Fn iswctype_l "wint_t wc" "wctype_t charclass" "locale_t loc"
++.Ft wctype_t
++.Fn wctype_l "const char *property" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn wctype
+@@ -60,6 +66,18 @@
+ .Fa wc
+ is in the character class
+ .Fa charclass .
++.Pp
++While the
++.Fn iswctype
++and
++.Fn wctype
++functions use the current locale, the
++.Fn iswctype_l
++and
++.Fn wctype_l
++functions may be passed locales directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn iswctype
+@@ -94,7 +112,8 @@
+ }
+ .Ed
+ .Sh SEE ALSO
+-.Xr ctype 3
++.Xr ctype 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn iswctype
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/wctype.c,v 1.2 2002/08/04 12:43:53 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/wctype.c,v 1.3 2004/03/27 08:59:21 tjr Exp $");
#include <ctype.h>
#include <string.h>
{ "ideogram", _CTYPE_I }, /* BSD extension */
{ "special", _CTYPE_T }, /* BSD extension */
{ "phonogram", _CTYPE_Q }, /* BSD extension */
+ { "rune", 0xFFFFFF00L }, /* BSD extension */
{ NULL, 0UL }, /* Default */
};
int i;
--- /dev/null
+--- wctype.c.orig 2004-11-25 11:38:21.000000000 -0800
++++ wctype.c 2005-02-27 02:15:11.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/wctype.c,v 1.3 2004/03/27 08:59:21 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <ctype.h>
+ #include <string.h>
+ #include <wctype.h>
+@@ -36,34 +38,57 @@
+ iswctype(wint_t wc, wctype_t charclass)
+ {
+
+- return (__istype(wc, charclass));
++ return (__istype_l(wc, charclass, __current_locale()));
++}
++
++#undef iswctype_l
++int
++iswctype_l(wint_t wc, wctype_t charclass, locale_t loc)
++{
++ NORMALIZE_LOCALE(loc);
++ return (__istype_l(wc, charclass, loc));
+ }
+
++static struct {
++ const char *name;
++ wctype_t mask;
++} props[] = {
++ { "alnum", _CTYPE_A|_CTYPE_D },
++ { "alpha", _CTYPE_A },
++ { "blank", _CTYPE_B },
++ { "cntrl", _CTYPE_C },
++ { "digit", _CTYPE_D },
++ { "graph", _CTYPE_G },
++ { "lower", _CTYPE_L },
++ { "print", _CTYPE_R },
++ { "punct", _CTYPE_P },
++ { "space", _CTYPE_S },
++ { "upper", _CTYPE_U },
++ { "xdigit", _CTYPE_X },
++ { "ideogram", _CTYPE_I }, /* BSD extension */
++ { "special", _CTYPE_T }, /* BSD extension */
++ { "phonogram", _CTYPE_Q }, /* BSD extension */
++ { "rune", 0xFFFFFF00L }, /* BSD extension */
++ { NULL, 0UL }, /* Default */
++};
++
++/* these don't currently depend on the locale, but they could */
++
+ wctype_t
+ wctype(const char *property)
+ {
+- struct {
+- const char *name;
+- wctype_t mask;
+- } props[] = {
+- { "alnum", _CTYPE_A|_CTYPE_D },
+- { "alpha", _CTYPE_A },
+- { "blank", _CTYPE_B },
+- { "cntrl", _CTYPE_C },
+- { "digit", _CTYPE_D },
+- { "graph", _CTYPE_G },
+- { "lower", _CTYPE_L },
+- { "print", _CTYPE_R },
+- { "punct", _CTYPE_P },
+- { "space", _CTYPE_S },
+- { "upper", _CTYPE_U },
+- { "xdigit", _CTYPE_X },
+- { "ideogram", _CTYPE_I }, /* BSD extension */
+- { "special", _CTYPE_T }, /* BSD extension */
+- { "phonogram", _CTYPE_Q }, /* BSD extension */
+- { "rune", 0xFFFFFF00L }, /* BSD extension */
+- { NULL, 0UL }, /* Default */
+- };
++ int i;
++
++ i = 0;
++ while (props[i].name != NULL && strcmp(props[i].name, property) != 0)
++ i++;
++
++ return (props[i].mask);
++}
++
++wctype_t
++wctype_l(const char *property, locale_t loc)
++{
+ int i;
+
+ i = 0;
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/lib/libc/locale/wcwidth.3,v 1.3 2002/11/29 17:35:09 ru Exp $
+.\" $FreeBSD: src/lib/libc/locale/wcwidth.3,v 1.6 2004/08/17 04:56:03 trhodes Exp $
.\"
-.Dd October 3, 2002
+.Dd August 17, 2004
.Dt WCWIDTH 3
.Os
.Sh NAME
column = 0;
while ((ch = getwchar()) != WEOF) {
- if ((w = wcwidth(ch)) > 0)
- column += w;
- if (column >= 20) {
+ w = wcwidth(ch);
+ if (w > 0 && column + w >= 20) {
putwchar(L'\en');
column = 0;
}
putwchar(ch);
if (ch == L'\en')
column = 0;
+ else if (w > 0)
+ column += w;
}
.Ed
.Sh SEE ALSO
--- /dev/null
+--- wcwidth.3.orig Fri Mar 11 19:44:47 2005
++++ wcwidth.3 Fri Mar 11 19:46:47 2005
+@@ -28,7 +28,8 @@
+ .Dt WCWIDTH 3
+ .Os
+ .Sh NAME
+-.Nm wcwidth
++.Nm wcwidth ,
++.Nm wcwidth_l
+ .Nd "number of column positions of a wide-character code"
+ .Sh LIBRARY
+ .Lb libc
+@@ -36,12 +37,23 @@
+ .In wchar.h
+ .Ft int
+ .Fn wcwidth "wchar_t wc"
++.In xlocale.h
++.Ft int
++.Fn wcwidth_l "wchar_t wc" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn wcwidth
+ function determines the number of column positions required to
+ display the wide character
+ .Fa wc .
++.Pp
++While the
++.Fn wcwidth
++function uses the current locale, the
++.Fn wcwidth_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn wcwidth
+@@ -79,7 +91,8 @@
+ .Ed
+ .Sh SEE ALSO
+ .Xr iswprint 3 ,
+-.Xr wcswidth 3
++.Xr wcswidth 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn wcwidth
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/wcwidth.c,v 1.5 2002/08/19 20:32:27 ache Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/wcwidth.c,v 1.7 2004/08/12 12:19:11 tjr Exp $");
#include <wchar.h>
-#include <wctype.h>
-#define _CTYPE_SWM 0xe0000000L /* Mask to get screen width data */
-#define _CTYPE_SWS 30 /* Bits to shift to get width */
+#undef wcwidth
int
wcwidth(wchar_t wc)
{
- int width;
- if (wc == L'\0')
- return (0);
-
- width = __maskrune(wc, _CTYPE_SWM);
-
- /* 0 is autowidth (default) */
- return (width ? (int)((unsigned)width >> _CTYPE_SWS)
- : (iswprint(wc) ? 1 : -1));
+ return (__wcwidth(wc));
}
-
--- /dev/null
+--- wcwidth.c.orig 2004-11-25 11:38:21.000000000 -0800
++++ wcwidth.c 2005-02-24 00:37:25.000000000 -0800
+@@ -42,6 +42,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/locale/wcwidth.c,v 1.7 2004/08/12 12:19:11 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <wchar.h>
+
+ #undef wcwidth
+@@ -50,5 +52,13 @@
+ wcwidth(wchar_t wc)
+ {
+
+- return (__wcwidth(wc));
++ return (__wcwidth_l(wc, __current_locale()));
++}
++
++int
++wcwidth_l(wchar_t wc, locale_t loc)
++{
++
++ NORMALIZE_LOCALE(loc);
++ return (__wcwidth_l(wc, loc));
+ }
# locale sources
.PATH: ${.CURDIR}/${MACHINE_ARCH}/locale ${.CURDIR}/locale
+# depreciated interfaces
+MISRCS += frune.c mbrune.c runedepreciated.c setinvalidrune.c
+
+# extended locale
+MISRCS += isctype_l.c iswctype_l.c xlocale.c
+
.include "Makefile.fbsd_begin"
-FBSDMISRCS= big5.c btowc.c collate.c collcmp.c euc.c fix_grouping.c frune.c \
- isctype.c iswctype.c \
- ldpart.c lmessages.c lmonetary.c lnumeric.c localeconv.c mblen.c \
- mbrlen.c \
- mbrtowc.c mbrune.c mbsinit.c mbsrtowcs.c mbtowc.c mbstowcs.c \
- mskanji.c nl_langinfo.c nomacros.c none.c rune.c \
- runetype.c setinvalidrune.c setlocale.c setrunelocale.c table.c \
- tolower.c toupper.c utf2.c utf8.c wcrtomb.c wcsrtombs.c wcsftime.c \
- wcstof.c wcstod.c \
- wcstoimax.c wcstol.c wcstold.c wcstoll.c \
- wcstombs.c \
- wcstoul.c wcstoull.c wcstoumax.c wctob.c wctomb.c wctrans.c wctype.c \
- wcwidth.c
-FBSDHDRS= collate.h ldpart.h lmessages.h lmonetary.h lnumeric.h setlocale.h
+FBSDMISRCS= big5.c btowc.c collate.c collcmp.c euc.c fix_grouping.c \
+ gb18030.c gb2312.c gbk.c isctype.c iswctype.c \
+ ldpart.c lmessages.c lmonetary.c lnumeric.c localeconv.c \
+ mblen.c mbrlen.c mbrtowc.c mbsinit.c mbsnrtowcs.c mbsrtowcs.c \
+ mbstowcs.c mbtowc.c mskanji.c \
+ nextwctype.c nl_langinfo.c nomacros.c none.c \
+ rune.c runetype.c setlocale.c setrunelocale.c \
+ table.c tolower.c toupper.c utf8.c \
+ wcrtomb.c wcsftime.c wcsnrtombs.c wcsrtombs.c wcstod.c \
+ wcstof.c wcstoimax.c wcstol.c wcstold.c wcstoll.c wcstombs.c \
+ wcstoul.c wcstoull.c wcstoumax.c wctob.c wctomb.c wctrans.c \
+ wctype.c wcwidth.c
+FBSDHDRS= collate.h ldpart.h lmessages.h lmonetary.h lnumeric.h \
+ mblocal.h setlocale.h
.include "Makefile.fbsd_end"
+# special case: utf2-fbsd.c is derived from utf8.c with utf2.c.patch
+AUTOPATCHSRCS+= ${SYMROOT}/utf2-fbsd.c
+MISRCS+= utf2.c
+${SYMROOT}/utf2-fbsd.c: FreeBSD/utf8.c
+ cp ${.ALLSRC} ${.TARGET}
+ patch ${.TARGET} ${.ALLSRC:S/utf8/utf2/}.patch;
+
+# also build a 64-bit long double version (ppc only)
+LDBLSRCS += wcstold.c
+
# Begin hack for 3333969
MISRCS += lconv.c
# End hack for 3333969
+# for ppc64, we need to create rune32.h
+.if (${MACHINE_ARCH} == ppc64)
+# the following is good enough for ppc, ppc64 and i386
+ARCH32 != arch | sed 's/64//'
+rune.So rune.do rune.po rune.o: ${SYMROOT}/rune32.h
+${SYMROOT}/rune32.h: ${SYMROOT}/rune-fbsd.c
+ ${CC} -arch ${ARCH32} -DRUNEOFF32 -o ${SYMROOT}/rune32 ${.ALLSRC}
+ ${SYMROOT}/rune32 > ${.TARGET}
+.endif
+
.if ${LIB} == "c"
+MAN3+= ctype_l.3 isalnum_l.3 iswalnum_l.3 wcstod_l.3 wcstol_l.3
+MAN3+= duplocale.3 freelocale.3 newlocale.3 \
+ querylocale.3 uselocale.3 xlocale.3
+# depreciated man pages
+MAN3+= mbrune.3 rune.3
+MAN5+= utf2.5
+
.include "Makefile.fbsd_begin"
-FBSDMAN3= btowc.3 ctype.3 digittoint.3 isalnum.3 isalpha.3 isascii.3 isblank.3 \
- iscntrl.3 isdigit.3 isgraph.3 islower.3 isprint.3 ispunct.3 isspace.3 \
- isupper.3 iswalnum.3 isxdigit.3 mbrlen.3 mbrtowc.3 mbrune.3 mbsinit.3 \
- mbsrtowcs.3 multibyte.3 nl_langinfo.3 rune.3 setlocale.3 toascii.3 \
- tolower.3 toupper.3 towlower.3 towupper.3 wcsftime.3 wcrtomb.3 \
- wcsrtombs.3 wcstod.3 wcstol.3 wctrans.3 wctype.3 wcwidth.3
-FBSDMAN4= euc.4 utf2.4
-FBSDMAN5= utf8.5
+FBSDMAN3= btowc.3 ctype.3 digittoint.3 \
+ isalnum.3 isalpha.3 isascii.3 isblank.3 iscntrl.3 isdigit.3 \
+ isgraph.3 isideogram.3 islower.3 isphonogram.3 isprint.3 \
+ ispunct.3 isrune.3 isspace.3 isspecial.3 isupper.3 \
+ iswalnum.3 isxdigit.3 \
+ localeconv.3 \
+ mblen.3 mbrlen.3 mbrtowc.3 mbsinit.3 mbsrtowcs.3 mbstowcs.3 \
+ mbtowc.3 multibyte.3 \
+ nextwctype.3 nl_langinfo.3 \
+ setlocale.3 toascii.3 tolower.3 toupper.3 towlower.3 towupper.3 \
+ wcrtomb.3 wcsftime.3 wcsrtombs.3 wcstod.3 wcstol.3 wcstombs.3 \
+ wctomb.3 wctrans.3 wctype.3 wcwidth.3
+FBSDMAN5= big5.5 euc.5 gb18030.5 gb2312.5 gbk.5 mskanji.5 utf8.5
.include "Makefile.fbsd_end"
MLINKS+=btowc.3 wctob.3
-MLINKS+=ctype.3 isideogram.3 ctype.3 isphonogram.3 ctype.3 isspecial.3 \
- ctype.3 isrune.3
+MLINKS+=btowc.3 btowc_l.3 btowc.3 wctob_l.3
+MLINKS+=digittoint.3 digittoint_l.3
MLINKS+=isdigit.3 isnumber.3
+MLINKS+=isalnum_l.3 isalpha_l.3 isalnum_l.3 isblank_l.3 \
+ isalnum_l.3 iscntrl_l.3 isalnum_l.3 isdigit_l.3 isalnum_l.3 isgraph_l.3 \
+ isalnum_l.3 ishexnumber_l.3 \
+ isalnum_l.3 isideogram_l.3 isalnum_l.3 islower_l.3 isalnum_l.3 isnumber_l.3 \
+ isalnum_l.3 isphonogram_l.3 isalnum_l.3 isprint_l.3 isalnum_l.3 ispunct_l.3 \
+ isalnum_l.3 isrune_l.3 isalnum_l.3 isspace_l.3 isalnum_l.3 isspecial_l.3 \
+ isalnum_l.3 isupper_l.3 isalnum_l.3 isxdigit_l.3
MLINKS+=iswalnum.3 iswalpha.3 iswalnum.3 iswascii.3 iswalnum.3 iswblank.3 \
iswalnum.3 iswcntrl.3 iswalnum.3 iswdigit.3 iswalnum.3 iswgraph.3 \
- iswalnum.3 iswhexnumber.3 iswalnum.3 iswhexnumber.3 \
+ iswalnum.3 iswhexnumber.3 \
iswalnum.3 iswideogram.3 iswalnum.3 iswlower.3 iswalnum.3 iswnumber.3 \
iswalnum.3 iswphonogram.3 iswalnum.3 iswprint.3 iswalnum.3 iswpunct.3 \
iswalnum.3 iswrune.3 iswalnum.3 iswspace.3 iswalnum.3 iswspecial.3 \
iswalnum.3 iswupper.3 iswalnum.3 iswxdigit.3
+MLINKS+=iswalnum_l.3 iswalpha_l.3 iswalnum_l.3 iswblank_l.3 \
+ iswalnum_l.3 iswcntrl_l.3 iswalnum_l.3 iswdigit_l.3 iswalnum_l.3 iswgraph_l.3 \
+ iswalnum_l.3 iswhexnumber_l.3 \
+ iswalnum_l.3 iswideogram_l.3 iswalnum_l.3 iswlower_l.3 iswalnum_l.3 iswnumber_l.3 \
+ iswalnum_l.3 iswphonogram_l.3 iswalnum_l.3 iswprint_l.3 iswalnum_l.3 iswpunct_l.3 \
+ iswalnum_l.3 iswrune_l.3 iswalnum_l.3 iswspace_l.3 iswalnum_l.3 iswspecial_l.3 \
+ iswalnum_l.3 iswupper_l.3 iswalnum_l.3 iswxdigit_l.3
MLINKS+=isxdigit.3 ishexnumber.3
+MLINKS+=localeconv.3 localeconv_l.3
+MLINKS+=mblen.3 mblen_l.3
+MLINKS+=mbrlen.3 mbrlen_l.3
+MLINKS+=mbrtowc.3 mbrtowc_l.3
MLINKS+=mbrune.3 mbmb.3 mbrune.3 mbrrune.3
-MLINKS+=multibyte.3 mblen.3 multibyte.3 mbstowcs.3 multibyte.3 mbtowc.3 \
- multibyte.3 wcstombs.3 multibyte.3 wctomb.3
+MLINKS+=mbsinit.3 mbsinit_l.3
+MLINKS+=mbsrtowcs.3 mbsnrtowcs.3
+MLINKS+=mbsrtowcs.3 mbsrtowcs_l.3 mbsrtowcs.3 mbsnrtowcs_l.3
+MLINKS+=mbstowcs.3 mbstowcs_l.3
+MLINKS+=mbtowc.3 mbtowc_l.3
+MLINKS+=nextwctype.3 nextwctype_l.3
+MLINKS+=nl_langinfo.3 nl_langinfo_l.3
MLINKS+=rune.3 fgetrune.3 rune.3 fputrune.3 rune.3 fungetrune.3 \
rune.3 setinvalidrune.3 rune.3 setrunelocale.3 rune.3 sgetrune.3 \
rune.3 sputrune.3
-MLINKS+=setlocale.3 localeconv.3
+MLINKS+=tolower.3 tolower_l.3
+MLINKS+=toupper.3 toupper_l.3
+MLINKS+=towlower.3 towlower_l.3
+MLINKS+=towupper.3 towupper_l.3
+MLINKS+=wcrtomb.3 wcrtomb_l.3
+MLINKS+=wcsftime.3 wcsftime_l.3
+MLINKS+=wcsrtombs.3 wcsnrtombs.3
+MLINKS+=wcsrtombs.3 wcsrtombs_l.3 wcsrtombs.3 wcsnrtombs_l.3
MLINKS+=wcstod.3 wcstof.3 wcstod.3 wcstold.3
+MLINKS+=wcstod_l.3 wcstof_l.3 wcstod_l.3 wcstold_l.3
MLINKS+=wcstol.3 wcstoul.3 wcstol.3 wcstoll.3 wcstol.3 wcstoull.3 \
wcstol.3 wcstoimax.3 wcstol.3 wcstoumax.3
+MLINKS+=wcstol_l.3 wcstoul_l.3 wcstol_l.3 wcstoll_l.3 wcstol_l.3 wcstoull_l.3 \
+ wcstol_l.3 wcstoimax_l.3 wcstol_l.3 wcstoumax_l.3
+MLINKS+=wcstombs.3 wcstombs_l.3
+MLINKS+=wctomb.3 wctomb_l.3
MLINKS+=wctrans.3 towctrans.3
+MLINKS+=wctrans.3 wctrans_l.3 wctrans.3 towctrans_l.3
MLINKS+=wctype.3 iswctype.3
+MLINKS+=wctype.3 wctype_l.3 wctype.3 iswctype_l.3
+MLINKS+=wcwidth.3 wcwidth_l.3
.endif
--- /dev/null
+.\" Copyright (c) 1991, 1993
+.\" The Regents of the University of California. 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" @(#)ctype.3 8.1 (Berkeley) 6/4/93
+.\" $FreeBSD: src/lib/libc/locale/ctype.3,v 1.15 2004/06/30 20:09:08 ru Exp $
+.\"
+.Dd March 11, 2005
+.Dt CTYPE_L 3
+.Os
+.Sh NAME
+.Nm digittoint_l ,
+.Nm isalnum_l ,
+.Nm isalpha_l ,
+.Nm isascii_l ,
+.Nm isblank_l ,
+.Nm iscntrl_l ,
+.Nm isdigit_l ,
+.Nm isgraph_l ,
+.Nm ishexnumber_l ,
+.Nm isideogram_l ,
+.Nm islower_l ,
+.Nm isnumber_l ,
+.Nm isphonogram_l ,
+.Nm isprint_l ,
+.Nm ispunct_l ,
+.Nm isrune_l ,
+.Nm isspace_l ,
+.Nm isspecial_l ,
+.Nm isupper_l ,
+.Nm isxdigit_l ,
+.Nm toascii_l ,
+.Nm tolower_l ,
+.Nm toupper_l
+.Nd character classification macros
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In ctype.h
+.In xlocale.h
+.Ft int
+.Fn digittoint_l "int c" "locale_t loc"
+.Ft int
+.Fn isalnum_l "int c" "locale_t loc"
+.Ft int
+.Fn isalpha_l "int c" "locale_t loc"
+.Ft int
+.Fn isascii_l "int c" "locale_t loc"
+.Ft int
+.Fn iscntrl_l "int c" "locale_t loc"
+.Ft int
+.Fn isdigit_l "int c" "locale_t loc"
+.Ft int
+.Fn isgraph_l "int c" "locale_t loc"
+.Ft int
+.Fn ishexnumber_l "int c" "locale_t loc"
+.Ft int
+.Fn isideogram_l "int c" "locale_t loc"
+.Ft int
+.Fn islower_l "int c" "locale_t loc"
+.Ft int
+.Fn isnumber_l "int c" "locale_t loc"
+.Ft int
+.Fn isphonogram_l "int c" "locale_t loc"
+.Ft int
+.Fn isspecial_l "int c" "locale_t loc"
+.Ft int
+.Fn isprint_l "int c" "locale_t loc"
+.Ft int
+.Fn ispunct_l "int c" "locale_t loc"
+.Ft int
+.Fn isrune_l "int c" "locale_t loc"
+.Ft int
+.Fn isspace_l "int c" "locale_t loc"
+.Ft int
+.Fn isupper_l "int c" "locale_t loc"
+.Ft int
+.Fn isxdigit_l "int c" "locale_t loc"
+.Ft int
+.Fn toascii_l "int c" "locale_t loc"
+.Ft int
+.Fn tolower_l "int c" "locale_t loc"
+.Ft int
+.Fn toupper_l "int c" "locale_t loc"
+.Sh DESCRIPTION
+These
+functions are extended locale versions of the corresponding functions in
+.Xr ctype 3 .
+Also, see
+.Xr xlocale 3 for more information about extended locales.
+.Sh SEE ALSO
+.Xr ctype 3 ,
+.Xr xlocale 3
--- /dev/null
+.Dd March 11, 2005
+.Dt DUPLOCALE 3
+.Os
+.Sh NAME
+.Nm duplocale
+.Nd Duplicate existing locale
+.Sh SYNOPSIS
+.In xlocale.h
+.Ft locale_t
+.Fn duplocale "locale_t loc"
+.Sh DESCRIPTION
+Duplicates an existing
+.Vt locale_t .
+Sub-structures are shared between the two
+.Vt locale_t
+structures.
+Passing
+.Dv NULL
+will duplicate the current locale.
+Passing
+.Dv LC_GLOBAL_LOCALE
+will duplicate the global locale.
+.Sh RETURN VALUES
+Returns a duplicated
+.Vt locale_t ,
+or
+.Dv NULL
+on error.
+Duplicated locales should be freed with
+.Xr freelocale 3 .
+.Sh SEE ALSO
+.Xr xlocale 3 ,
+.Xr freelocale 3 ,
+.Xr newlocale 3 ,
+.Xr querylocale 3 ,
+.Xr uselocale 3
--- /dev/null
+.Dd March 11, 2005
+.Dt FREELOCALE 3
+.Os
+.Sh NAME
+.Nm freelocale
+.Nd Frees an allocated locale
+.Sh SYNOPSIS
+.In xlocale.h
+.Ft int
+.Fn freelocale "locale_t loc"
+.Sh DESCRIPTION
+Frees the storage associated with
+.Va loc .
+Sub-structures have their reference counts reduced,
+and are freed if the reference count becomes zero.
+.Sh RETURN VALUES
+Returns zero on success, -1 on error. An error will occur if
+.Va loc
+is not a
+.Vt locale_t ,
+or is
+.Dv NULL
+or
+.Dv LC_GLOBAL_LOCALE .
+.Sh SEE ALSO
+.Xr xlocale 3 ,
+.Xr duplocale 3 ,
+.Xr newlocale 3 ,
+.Xr querylocale 3 ,
+.Xr uselocale 3
--- /dev/null
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Paul Borman at Krystal Technologies.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)frune.c 8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/libc/locale/frune.c,v 1.3 2002/09/18 06:19:12 tjr Exp $");
+
+#include "xlocale_private.h"
+
+#include <limits.h>
+#include <rune.h>
+#include <stddef.h>
+#include <stdio.h>
+#include "runedepreciated.h"
+
+long
+fgetrune(fp)
+ FILE *fp;
+{
+ rune_t r;
+ int c, len;
+ char buf[MB_LEN_MAX];
+ char const *result;
+ __darwin_rune_t invalid_rune = __current_locale()->__lc_ctype->_CurrentRuneLocale.__invalid_rune;
+ static int warn_depreciated = 1;
+
+ if (warn_depreciated) {
+ warn_depreciated = 0;
+ fprintf(stderr, __rune_depreciated_msg, "fgetrune");
+ }
+
+ len = 0;
+ do {
+ if ((c = getc(fp)) == EOF) {
+ if (len)
+ break;
+ return (EOF);
+ }
+ buf[len++] = c;
+
+ if ((r = __sgetrune(buf, len, &result)) != invalid_rune)
+ return (r);
+ } while (result == buf && len < MB_LEN_MAX);
+
+ while (--len > 0)
+ ungetc(buf[len], fp);
+ return (invalid_rune);
+}
+
+int
+fungetrune(r, fp)
+ rune_t r;
+ FILE* fp;
+{
+ int len;
+ char buf[MB_LEN_MAX];
+ static int warn_depreciated = 1;
+
+ if (warn_depreciated) {
+ warn_depreciated = 0;
+ fprintf(stderr, __rune_depreciated_msg, "fungetrune");
+ }
+
+ len = __sputrune(r, buf, MB_LEN_MAX, 0);
+ while (len-- > 0)
+ if (ungetc(buf[len], fp) == EOF)
+ return (EOF);
+ return (0);
+}
+
+int
+fputrune(r, fp)
+ rune_t r;
+ FILE *fp;
+{
+ int i, len;
+ char buf[MB_LEN_MAX];
+ static int warn_depreciated = 1;
+
+ if (warn_depreciated) {
+ warn_depreciated = 0;
+ fprintf(stderr, __rune_depreciated_msg, "fputrune");
+ }
+
+ len = __sputrune(r, buf, MB_LEN_MAX, 0);
+
+ for (i = 0; i < len; ++i)
+ if (putc(buf[i], fp) == EOF)
+ return (EOF);
+
+ return (0);
+}
--- /dev/null
+.\" $NetBSD: iswalnum.3,v 1.5 2002/07/10 14:46:10 yamt Exp $
+.\"
+.\" Copyright (c) 1991 The Regents of the University of California.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" the American National Standards Committee X3, on Information
+.\" Processing Systems.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" @(#)isalnum.3 5.2 (Berkeley) 6/29/91
+.\" $FreeBSD: src/lib/libc/locale/iswalnum.3,v 1.5 2002/11/29 17:35:09 ru Exp $
+.\"
+.Dd March 11, 2005
+.Dt ISALNUM_L 3
+.Os
+.Sh NAME
+.Nm isalnum_l ,
+.Nm isalpha_l ,
+.Nm isblank_l ,
+.Nm iscntrl_l ,
+.Nm isdigit_l ,
+.Nm isgraph_l ,
+.Nm ishexnumber_l ,
+.Nm isideogram_l ,
+.Nm islower_l ,
+.Nm isnumber_l ,
+.Nm isphonogram_l ,
+.Nm isprint_l ,
+.Nm ispunct_l ,
+.Nm isrune_l ,
+.Nm isspace_l ,
+.Nm isspecial_l ,
+.Nm isupper_l ,
+.Nm isxdigit_l
+.Nd character classification utilities
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In wctype.h
+.In xlocale.h
+.Ft int
+.Fn isalnum_l "int c" "locale_t loc"
+.Ft int
+.Fn isalpha_l "int c" "locale_t loc"
+.Ft int
+.Fn isblank_l "int c" "locale_t loc"
+.Ft int
+.Fn iscntrl_l "int c" "locale_t loc"
+.Ft int
+.Fn isdigit_l "int c" "locale_t loc"
+.Ft int
+.Fn isgraph_l "int c" "locale_t loc"
+.Ft int
+.Fn ishexnumber_l "int c" "locale_t loc"
+.Ft int
+.Fn isideogram_l "int c" "locale_t loc"
+.Ft int
+.Fn islower_l "int c" "locale_t loc"
+.Ft int
+.Fn isnumber_l "int c" "locale_t loc"
+.Ft int
+.Fn isphonogram_l "int c" "locale_t loc"
+.Ft int
+.Fn isprint_l "int c" "locale_t loc"
+.Ft int
+.Fn ispunct_l "int c" "locale_t loc"
+.Ft int
+.Fn isrune_l "int c" "locale_t loc"
+.Ft int
+.Fn isspace_l "int c" "locale_t loc"
+.Ft int
+.Fn isspecial_l "int c" "locale_t loc"
+.Ft int
+.Fn isupper_l "int c" "locale_t loc"
+.Ft int
+.Fn isxdigit_l "int c" "locale_t loc"
+.Sh DESCRIPTION
+These
+functions are extended locale versions of the corresponding functions,
+with the _l removed.
+Also, see
+.Xr xlocale 3 for more information about extended locales.
+.Sh SEE ALSO
+.Xr isalnum 3 ,
+.Xr isalpha 3 ,
+.Xr isblank 3 ,
+.Xr iscntrl 3 ,
+.Xr isdigit 3 ,
+.Xr isgraph 3 ,
+.Xr ishexnumber 3 ,
+.Xr isideogram 3 ,
+.Xr islower 3 ,
+.Xr isnumber 3 ,
+.Xr isphonogram 3 ,
+.Xr isprint 3 ,
+.Xr ispunct 3 ,
+.Xr isrune 3 ,
+.Xr isspace 3 ,
+.Xr isspecial 3 ,
+.Xr isupper 3 ,
+.Xr isxdigit 3 ,
+.Xr xlocale 3
--- /dev/null
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Paul Borman at Krystal Technologies.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)isctype.c 8.3 (Berkeley) 2/24/94";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/libc/locale/isctype.c,v 1.9 2002/08/17 20:03:44 ache Exp $");
+
+#include "xlocale_private.h"
+#include <ctype.h>
+
+#undef digittoint_l
+int
+digittoint_l(c, l)
+ int c;
+ locale_t l;
+{
+ return (__maskrune_l(c, 0xFF, l));
+}
+
+#undef isalnum_l
+int
+isalnum_l(c, l)
+ int c;
+ locale_t l;
+{
+ return (__istype_l(c, _CTYPE_A|_CTYPE_D, l));
+}
+
+#undef isalpha_l
+int
+isalpha_l(c, l)
+ int c;
+ locale_t l;
+{
+ return (__istype_l(c, _CTYPE_A, l));
+}
+
+#undef isblank_l
+int
+isblank_l(c, l)
+ int c;
+ locale_t l;
+{
+ return (__istype_l(c, _CTYPE_B, l));
+}
+
+#undef iscntrl_l
+int
+iscntrl_l(c, l)
+ int c;
+ locale_t l;
+{
+ return (__istype_l(c, _CTYPE_C, l));
+}
+
+#undef isdigit_l
+int
+isdigit_l(c, l)
+ int c;
+ locale_t l;
+{
+ return (__istype_l(c, _CTYPE_D, l));
+}
+
+#undef isgraph_l
+int
+isgraph_l(c, l)
+ int c;
+ locale_t l;
+{
+ return (__istype_l(c, _CTYPE_G, l));
+}
+
+#undef ishexnumber_l
+int
+ishexnumber_l(c, l)
+ int c;
+ locale_t l;
+{
+ return (__istype_l(c, _CTYPE_X, l));
+}
+
+#undef isideogram_l
+int
+isideogram_l(c, l)
+ int c;
+ locale_t l;
+{
+ return (__istype_l(c, _CTYPE_I, l));
+}
+
+#undef islower_l
+int
+islower_l(c, l)
+ int c;
+ locale_t l;
+{
+ return (__istype_l(c, _CTYPE_L, l));
+}
+
+#undef isnumber_l
+int
+isnumber_l(c, l)
+ int c;
+ locale_t l;
+{
+ return (__istype_l(c, _CTYPE_D, l));
+}
+
+#undef isphonogram_l
+int
+isphonogram_l(c, l)
+ int c;
+ locale_t l;
+{
+ return (__istype_l(c, _CTYPE_Q, l));
+}
+
+#undef isprint_l
+int
+isprint_l(c, l)
+ int c;
+ locale_t l;
+{
+ return (__istype_l(c, _CTYPE_R, l));
+}
+
+#undef ispunct_l
+int
+ispunct_l(c, l)
+ int c;
+ locale_t l;
+{
+ return (__istype_l(c, _CTYPE_P, l));
+}
+
+#undef isrune_l
+int
+isrune_l(c, l)
+ int c;
+ locale_t l;
+{
+ return (__istype_l(c, 0xFFFFFF00L, l));
+}
+
+#undef isspace_l
+int
+isspace_l(c, l)
+ int c;
+ locale_t l;
+{
+ return (__istype_l(c, _CTYPE_S, l));
+}
+
+#undef isspecial_l
+int
+isspecial_l(c, l)
+ int c;
+ locale_t l;
+{
+ return (__istype_l(c, _CTYPE_T, l));
+}
+
+#undef isupper_l
+int
+isupper_l(c, l)
+ int c;
+ locale_t l;
+{
+ return (__istype_l(c, _CTYPE_U, l));
+}
+
+#undef isxdigit_l
+int
+isxdigit_l(c, l)
+ int c;
+ locale_t l;
+{
+ return (__istype_l(c, _CTYPE_X, l));
+}
+
+#undef tolower_l
+int
+tolower_l(c, l)
+ int c;
+ locale_t l;
+{
+ return (__tolower_l(c, l));
+}
+
+#undef toupper_l
+int
+toupper_l(c, l)
+ int c;
+ locale_t l;
+{
+ return (__toupper_l(c, l));
+}
+
--- /dev/null
+.\" $NetBSD: iswalnum.3,v 1.5 2002/07/10 14:46:10 yamt Exp $
+.\"
+.\" Copyright (c) 1991 The Regents of the University of California.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" the American National Standards Committee X3, on Information
+.\" Processing Systems.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" @(#)isalnum.3 5.2 (Berkeley) 6/29/91
+.\" $FreeBSD: src/lib/libc/locale/iswalnum.3,v 1.5 2002/11/29 17:35:09 ru Exp $
+.\"
+.Dd March 11, 2005
+.Dt ISWALNUM_L 3
+.Os
+.Sh NAME
+.Nm iswalnum_l ,
+.Nm iswalpha_l ,
+.Nm iswblank_l ,
+.Nm iswcntrl_l ,
+.Nm iswdigit_l ,
+.Nm iswgraph_l ,
+.Nm iswhexnumber_l ,
+.Nm iswideogram_l ,
+.Nm iswlower_l ,
+.Nm iswnumber_l ,
+.Nm iswphonogram_l ,
+.Nm iswprint_l ,
+.Nm iswpunct_l ,
+.Nm iswrune_l ,
+.Nm iswspace_l ,
+.Nm iswspecial_l ,
+.Nm iswupper_l ,
+.Nm iswxdigit_l
+.Nd wide character classification utilities
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In wctype.h
+.In xlocale.h
+.Ft int
+.Fn iswalnum_l "wint_t wc" "locale_t loc"
+.Ft int
+.Fn iswalpha_l "wint_t wc" "locale_t loc"
+.Ft int
+.Fn iswascii_l "wint_t wc" "locale_t loc"
+.Ft int
+.Fn iswblank_l "wint_t wc" "locale_t loc"
+.Ft int
+.Fn iswcntrl_l "wint_t wc" "locale_t loc"
+.Ft int
+.Fn iswdigit_l "wint_t wc" "locale_t loc"
+.Ft int
+.Fn iswgraph_l "wint_t wc" "locale_t loc"
+.Ft int
+.Fn iswhexnumber_l "wint_t wc" "locale_t loc"
+.Ft int
+.Fn iswideogram_l "wint_t wc" "locale_t loc"
+.Ft int
+.Fn iswlower_l "wint_t wc" "locale_t loc"
+.Ft int
+.Fn iswnumber_l "wint_t wc" "locale_t loc"
+.Ft int
+.Fn iswphonogram_l "wint_t wc" "locale_t loc"
+.Ft int
+.Fn iswprint_l "wint_t wc" "locale_t loc"
+.Ft int
+.Fn iswpunct_l "wint_t wc" "locale_t loc"
+.Ft int
+.Fn iswrune_l "wint_t wc" "locale_t loc"
+.Ft int
+.Fn iswspace_l "wint_t wc" "locale_t loc"
+.Ft int
+.Fn iswspecial_l "wint_t wc" "locale_t loc"
+.Ft int
+.Fn iswupper_l "wint_t wc" "locale_t loc"
+.Ft int
+.Fn iswxdigit_l "wint_t wc" "locale_t loc"
+.Sh DESCRIPTION
+These
+functions are extended locale versions of the corresponding functions in
+.Xr iswalnum 3 .
+Also, see
+.Xr xlocale 3 for more information about extended locales.
+.Sh SEE ALSO
+.Xr iswalnum 3 ,
+.Xr xlocale 3
--- /dev/null
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Paul Borman at Krystal Technologies.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/libc/locale/iswctype.c,v 1.6 2002/08/17 20:30:34 ache Exp $");
+
+#include "xlocale_private.h"
+#include <wctype.h>
+
+#undef iswalnum_l
+int
+iswalnum_l(wc, l)
+ wint_t wc;
+ locale_t l;
+{
+ return (__istype_l(wc, _CTYPE_A|_CTYPE_D, l));
+}
+
+#undef iswalpha_l
+int
+iswalpha_l(wc, l)
+ wint_t wc;
+ locale_t l;
+{
+ return (__istype_l(wc, _CTYPE_A, l));
+}
+
+#undef iswblank_l
+int
+iswblank_l(wc, l)
+ wint_t wc;
+ locale_t l;
+{
+ return (__istype_l(wc, _CTYPE_B, l));
+}
+
+#undef iswcntrl_l
+int
+iswcntrl_l(wc, l)
+ wint_t wc;
+ locale_t l;
+{
+ return (__istype_l(wc, _CTYPE_C, l));
+}
+
+#undef iswdigit_l
+int
+iswdigit_l(wc, l)
+ wint_t wc;
+ locale_t l;
+{
+ return (__istype_l(wc, _CTYPE_D, l));
+}
+
+#undef iswgraph_l
+int
+iswgraph_l(wc, l)
+ wint_t wc;
+ locale_t l;
+{
+ return (__istype_l(wc, _CTYPE_G, l));
+}
+
+#undef iswhexnumber_l
+int
+iswhexnumber_l(wc, l)
+ wint_t wc;
+ locale_t l;
+{
+ return (__istype_l(wc, _CTYPE_X, l));
+}
+
+#undef iswideogram_l
+int
+iswideogram_l(wc, l)
+ wint_t wc;
+ locale_t l;
+{
+ return (__istype_l(wc, _CTYPE_I, l));
+}
+
+#undef iswlower_l
+int
+iswlower_l(wc, l)
+ wint_t wc;
+ locale_t l;
+{
+ return (__istype_l(wc, _CTYPE_L, l));
+}
+
+#undef iswnumber_l
+int
+iswnumber_l(wc, l)
+ wint_t wc;
+ locale_t l;
+{
+ return (__istype_l(wc, _CTYPE_D, l));
+}
+
+#undef iswphonogram_l
+int
+iswphonogram_l(wc, l)
+ wint_t wc;
+ locale_t l;
+{
+ return (__istype_l(wc, _CTYPE_Q, l));
+}
+
+#undef iswprint_l
+int
+iswprint_l(wc, l)
+ wint_t wc;
+ locale_t l;
+{
+ return (__istype_l(wc, _CTYPE_R, l));
+}
+
+#undef iswpunct_l
+int
+iswpunct_l(wc, l)
+ wint_t wc;
+ locale_t l;
+{
+ return (__istype_l(wc, _CTYPE_P, l));
+}
+
+#undef iswrune_l
+int
+iswrune_l(wc, l)
+ wint_t wc;
+ locale_t l;
+{
+ return (__istype_l(wc, 0xFFFFFF00L, l));
+}
+
+#undef iswspace_l
+int
+iswspace_l(wc, l)
+ wint_t wc;
+ locale_t l;
+{
+ return (__istype_l(wc, _CTYPE_S, l));
+}
+
+#undef iswspecial_l
+int
+iswspecial_l(wc, l)
+ wint_t wc;
+ locale_t l;
+{
+ return (__istype_l(wc, _CTYPE_T, l));
+}
+
+#undef iswupper_l
+int
+iswupper_l(wc, l)
+ wint_t wc;
+ locale_t l;
+{
+ return (__istype_l(wc, _CTYPE_U, l));
+}
+
+#undef iswxdigit_l
+int
+iswxdigit_l(wc, l)
+ wint_t wc;
+ locale_t l;
+{
+ return (__istype_l(wc, _CTYPE_X, l));
+}
+
+#undef towlower_l
+wint_t
+towlower_l(wc, l)
+ wint_t wc;
+ locale_t l;
+{
+ return (__tolower_l(wc, l));
+}
+
+#undef towupper_l
+wint_t
+towupper_l(wc, l)
+ wint_t wc;
+ locale_t l;
+{
+ return (__toupper_l(wc, l));
+}
+
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+.\" Copyright (c) 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Paul Borman at Krystal Technologies.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" @(#)mbrune.3 8.2 (Berkeley) 4/19/94
+.\" $FreeBSD: src/lib/libc/locale/mbrune.3,v 1.15 2003/02/06 11:04:46 charnier Exp $
+.\"
+.Dd April 19, 1994
+.Dt MBRUNE 3
+.Os
+.Sh NAME
+.Nm mbrune ,
+.Nm mbrrune ,
+.Nm mbmb
+.Nd multibyte rune support for C
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In rune.h
+.Ft char *
+.Fn mbrune "const char *string" "rune_t rune"
+.Ft char *
+.Fn mbrrune "const char *string" "rune_t rune"
+.Ft char *
+.Fn mbmb "const char *string" "char *pattern"
+.Sh DESCRIPTION
+.Bf Em
+The
+.Bx 4.4
+.Dq rune
+functions have been deprecated in favour of the
+.Tn ISO
+C99 extended multibyte and wide character facilities
+and should not be used in new applications.
+.Ef
+Consider working with wide characters instead, and using
+.Xr wcschr 3 ,
+.Xr wcsrchr 3 ,
+and
+.Xr wcsstr 3
+instead of these functions.
+.Pp
+These routines provide the corresponding functionality of
+.Fn strchr ,
+.Fn strrchr
+and
+.Fn strstr
+for multibyte strings.
+.Pp
+The
+.Fn mbrune
+function locates the first occurrence of
+.Fn rune
+in the string pointed to by
+.Fa string .
+The terminating
+.Dv NUL
+character is considered part of the string.
+If
+.Fa rune
+is
+.Ql \e0 ,
+.Fn mbrune
+locates the terminating
+.Ql \e0 .
+.Pp
+The
+.Fn mbrrune
+function
+locates the last occurrence of
+.Fa rune
+in the string
+.Fa string .
+If
+.Fa rune
+is
+.Ql \e0 ,
+.Fn mbrune
+locates the terminating
+.Ql \e0 .
+.Pp
+The
+.Fn mbmb
+function locates the first occurrence of the null-terminated string
+.Fa pattern
+in the null-terminated string
+.Fa string .
+If
+.Fa pattern
+is the empty string,
+.Fn mbmb
+returns
+.Fa string ;
+if
+.Fa pattern
+occurs nowhere in
+.Fa string ,
+.Fn mbmb
+returns
+.Dv NULL ;
+otherwise
+.Fn mbmb
+returns a pointer to the first character of the first occurrence of
+.Fa pattern .
+.Sh RETURN VALUES
+The function
+.Fn mbrune
+returns a pointer to the located character, or
+.Dv NULL
+if the character does not appear in the string.
+.Pp
+The
+.Fn mbrrune
+function
+returns a pointer to the character, or
+.Dv NULL
+if the character does not appear in the string.
+.Pp
+The
+.Fn mbmb
+function
+returns a pointer to the
+.Fa pattern ,
+or
+.Dv NULL
+if the
+.Fa pattern
+does not appear in the string.
+.Sh SEE ALSO
+.Xr rune 3 ,
+.Xr setlocale 3 ,
+.Xr euc 4 ,
+.Xr utf2 4 ,
+.Xr utf8 5
+.Sh HISTORY
+The
+.Fn mbrune ,
+.Fn mbrrune ,
+and
+.Fn mbmb
+functions
+first appeared in Plan 9 from Bell Labs as
+.Fn utfrune ,
+.Fn utfrrune ,
+and
+.Fn utfutf .
--- /dev/null
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Paul Borman at Krystal Technologies.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)mbrune.c 8.1 (Berkeley) 6/27/93";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/libc/locale/mbrune.c,v 1.3 2002/09/18 06:11:21 tjr Exp $");
+
+#include <limits.h>
+#include <rune.h>
+#include <stddef.h>
+#include <string.h>
+#include "runedepreciated.h"
+
+char *
+mbrune(string, c)
+ const char *string;
+ rune_t c;
+{
+ char const *result;
+ rune_t r;
+ static int warn_depreciated = 1;
+
+ if (warn_depreciated) {
+ warn_depreciated = 0;
+ fprintf(stderr, __rune_depreciated_msg, "mbrune");
+ }
+
+ while ((r = __sgetrune(string, MB_LEN_MAX, &result))) {
+ if (r == c)
+ return ((char *)string);
+ string = result == string ? string + 1 : result;
+ }
+
+ return (c == *string ? (char *)string : NULL);
+}
+
+char *
+mbrrune(string, c)
+ const char *string;
+ rune_t c;
+{
+ const char *last = 0;
+ char const *result;
+ rune_t r;
+ static int warn_depreciated = 1;
+
+ if (warn_depreciated) {
+ warn_depreciated = 0;
+ fprintf(stderr, __rune_depreciated_msg, "mbrrune");
+ }
+
+ while ((r = __sgetrune(string, MB_LEN_MAX, &result))) {
+ if (r == c)
+ last = string;
+ string = result == string ? string + 1 : result;
+ }
+ return (c == *string ? (char *)string : (char *)last);
+}
+
+char *
+mbmb(string, pattern)
+ const char *string;
+ char *pattern;
+{
+ rune_t first, r;
+ size_t plen, slen;
+ char const *result;
+ static int warn_depreciated = 1;
+
+ if (warn_depreciated) {
+ warn_depreciated = 0;
+ fprintf(stderr, __rune_depreciated_msg, "mbmb");
+ }
+
+ plen = strlen(pattern);
+ slen = strlen(string);
+ if (plen > slen)
+ return (0);
+
+ first = __sgetrune(pattern, plen, &result);
+ if (result == string)
+ return (0);
+
+ while (slen >= plen && (r = __sgetrune(string, slen, &result))) {
+ if (r == first) {
+ if (strncmp(string, pattern, slen) == 0)
+ return ((char *) string);
+ }
+ if (result == string) {
+ --slen;
+ ++string;
+ } else {
+ slen -= result - string;
+ string = result;
+ }
+ }
+ return (0);
+}
--- /dev/null
+.Dd March 11, 2005
+.Dt NEWLOCALE 3
+.Os
+.Sh NAME
+.Nm newlocale
+.Nd Create a new locale
+.Sh SYNOPSIS
+.In xlocale.h
+.Ft locale_t
+.Fn newlocale "int mask" "const char * locale" "locale_t base"
+.Sh DESCRIPTION
+Creates a new
+.Vt locale_t
+based off the locale specified by
+.Va base .
+The categories specified by
+.Va mask
+will be replaced to correspond with the named
+.Va locale .
+.Pp
+The
+.Va mask
+is the logical OR of the following:
+.Bl -tag -width LC_MONETARY_MASK
+.It Dv LC_COLLATE_MASK
+Collation
+.It Dv LC_CTYPE_MASK
+Character type
+.It Dv LC_MESSAGES_MASK
+Messages
+.It Dv LC_MONETARY_MASK
+Monetary
+.It Dv LC_NUMERIC_MASK
+Numeric
+.It Dv LC_TIME_MASK
+Time
+.It Dv LC_ALL_MASK
+The logical OR of all of the above
+.El
+.Pp
+The
+.Va locale
+string is typically the name of one of the directories in
+.Pa /usr/share/locale .
+If
+.Va locale
+is
+.Dv NULL ,
+then the C locale is used. If
+.Va locale
+is an empty string, then it will look for environment variables:
+LC_ALL, then LC_* if the corresponding LC_*_MASK bit is set, then
+the LANG environment variable. If none of these are found, it
+will default to the C locale.
+.Pp
+If
+.Va base
+is
+.Dv NULL ,
+the current locale is used. If
+.Va base
+is
+.Dv LC_GLOBAL_LOCALE ,
+the global locale is used.
+.Pp
+If
+.Va mask
+is
+.Dv LC_ALL_MASK ,
+.Va base
+is ignored. In order to create a C
+.Vt locale_t
+value, use
+.Fn newlocale "LC_ALL_MASK" "NULL" "NULL" .
+.Sh RETURN VALUES
+Returns a new
+.Vt locale_t ,
+or
+.Dv NULL
+in case of error.
+New locales should be freed with
+.Xr freelocale 3 .
+.Sh SEE ALSO
+.Xr xlocale 3 ,
+.Xr duplocale 3 ,
+.Xr freelocale 3 ,
+.Xr querylocale 3 ,
+.Xr uselocale 3
--- /dev/null
+.Dd March 11, 2005
+.Dt QUERYLOCALE 3
+.Os
+.Sh NAME
+.Nm querylocale
+.Nd Get locale name for a specified category
+.Sh SYNOPSIS
+.In xlocale.h
+.Ft const char *
+.Fn querylocale "int mask" "locale_t loc"
+.Sh DESCRIPTION
+Returns the name of the locale for the category specified by
+.Va mask .
+The
+.Va mask
+is scanned starting at the least significant bit,
+until the first set bit is found. This happens
+to scan the categories alphabetically, not
+including
+.Dv LC_ALL_MASK ,
+but it is best to specify one category at a time.
+The available categories are documented in
+.Xr xlocale 3
+and
+.Xr newlocale 3 .
+.Sh SEE ALSO
+.Xr xlocale 3 ,
+.Xr duplocale 3 ,
+.Xr freelocale 3 ,
+.Xr newlocale 3 ,
+.Xr uselocale 3
--- /dev/null
+.\" Copyright (c) 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Paul Borman at Krystal Technologies.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" @(#)rune.3 8.2 (Berkeley) 12/11/93
+.\" $FreeBSD: src/lib/libc/locale/rune.3,v 1.22 2002/12/19 09:40:22 ru Exp $
+.\"
+.Dd October 6, 2002
+.Dt RUNE 3
+.Os
+.Sh NAME
+.Nm setrunelocale ,
+.Nm setinvalidrune ,
+.Nm sgetrune ,
+.Nm sputrune ,
+.Nm fgetrune ,
+.Nm fungetrune ,
+.Nm fputrune
+.Nd rune support for C
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In rune.h
+.In errno.h
+.Ft int
+.Fn setrunelocale "char *locale"
+.Ft void
+.Fn setinvalidrune "rune_t rune"
+.Ft rune_t
+.Fn sgetrune "const char *string" "size_t n" "char const **result"
+.Ft int
+.Fn sputrune "rune_t rune" "char *string" "size_t n" "char **result"
+.Pp
+.In stdio.h
+.Ft long
+.Fn fgetrune "FILE *stream"
+.Ft int
+.Fn fungetrune "rune_t rune" "FILE *stream"
+.Ft int
+.Fn fputrune "rune_t rune" "FILE *stream"
+.Sh DESCRIPTION
+.Bf Em
+The
+.Bx 4.4
+.Dq rune
+functions have been deprecated in favour of the
+.Tn ISO
+C99 extended multibyte and wide character facilities
+and should not be used in new applications.
+.Ef
+Consider using
+.Xr setlocale 3 ,
+.Xr mbrtowc 3 ,
+.Xr wcrtomb 3 ,
+.Xr fgetwc 3 ,
+.Xr ungetwc 3 ,
+and
+.Xr fputwc 3
+instead.
+.Pp
+The
+.Fn setrunelocale
+controls the type of encoding used to represent runes as multibyte strings
+as well as the properties of the runes as defined in
+.Aq Pa ctype.h .
+The
+.Fa locale
+argument indicates which locale to load.
+If the locale is successfully loaded,
+.Dv 0
+is returned, otherwise an errno value is returned to indicate the
+type of error.
+.Pp
+The
+.Fn setinvalidrune
+function sets the value of the global value
+.Dv _INVALID_RUNE
+to be
+.Fa rune .
+.Pp
+The
+.Fn sgetrune
+function tries to read a single multibyte character from
+.Fa string ,
+which is at most
+.Fa n
+bytes long.
+If
+.Fn sgetrune
+is successful, the rune is returned.
+If
+.Fa result
+is not
+.Dv NULL ,
+.Fa *result
+will point to the first byte which was not converted in
+.Fa string .
+If the first
+.Fa n
+bytes of
+.Fa string
+do not describe a full multibyte character,
+.Dv _INVALID_RUNE
+is returned and
+.Fa *result
+will point to
+.Fa string .
+If there is an encoding error at the start of
+.Fa string ,
+.Dv _INVALID_RUNE
+is returned and
+.Fa *result
+will point to the second character of
+.Fa string .
+.Pp
+the
+.Fn sputrune
+function tries to encode
+.Fa rune
+as a multibyte string and store it at
+.Fa string ,
+but no more than
+.Fa n
+bytes will be stored.
+If
+.Fa result
+is not
+.Dv NULL ,
+.Fa *result
+will be set to point to the first byte in string following the new
+multibyte character.
+If
+.Fa string
+is
+.Dv NULL ,
+.Fa *result
+will point to
+.Dv "(char *)0 +"
+.Fa x ,
+where
+.Fa x
+is the number of bytes that would be needed to store the multibyte value.
+If the multibyte character would consist of more than
+.Fa n
+bytes and
+.Fa result
+is not
+.Dv NULL ,
+.Fa *result
+will be set to
+.Dv NULL .
+In all cases,
+.Fn sputrune
+will return the number of bytes which would be needed to store
+.Fa rune
+as a multibyte character.
+.Pp
+The
+.Fn fgetrune
+function operates the same as
+.Fn sgetrune
+with the exception that it attempts to read enough bytes from
+.Fa stream
+to decode a single rune. It returns either
+.Dv EOF
+on end of file,
+.Dv _INVALID_RUNE
+on an encoding error, or the rune decoded if all went well.
+.Pp
+The
+.Fn fungetrune
+function pushes the multibyte encoding, as provided by
+.Fn sputrune ,
+of
+.Fa rune
+onto
+.Fa stream
+such that the next
+.Fn fgetrune
+call will return
+.Fa rune .
+It returns
+.Dv EOF
+if it fails and
+.Dv 0
+on success.
+.Pp
+The
+.Fn fputrune
+function writes the multibyte encoding of
+.Fa rune ,
+as provided by
+.Fn sputrune ,
+onto
+.Fa stream .
+It returns
+.Dv EOF
+on failure and
+.Dv 0
+on success.
+.Sh RETURN VALUES
+The
+.Fn setrunelocale
+function returns one of the following values:
+.Bl -tag -width Er
+.It Er 0
+The
+.Fn setrunelocale
+function
+was successful.
+.It Bq Er EINVAL
+The
+.Fa locale
+name was incorrect.
+.It Bq Er ENOENT
+The locale could not be found.
+.It Bq Er EFTYPE
+The file found was not a valid file.
+.El
+.Pp
+The
+.Fn sgetrune
+function either returns the rune read or
+.Dv _INVALID_RUNE .
+The
+.Fn sputrune
+function returns the number of bytes needed to store
+.Fa rune
+as a multibyte string.
+.Sh FILES
+.Bl -tag -width /usr/share/locale/locale/LC_CTYPE -compact
+.It Pa $PATH_LOCALE/ Ns Em locale Ns /LC_CTYPE
+.It Pa /usr/share/locale/ Ns Em locale Ns /LC_CTYPE
+binary LC_CTYPE file for the locale
+.Em locale .
+.El
+.Sh SEE ALSO
+.Xr mbrune 3 ,
+.Xr setlocale 3 ,
+.Xr euc 4 ,
+.Xr utf2 4 ,
+.Xr utf8 5
+.Sh HISTORY
+These functions first appeared in
+.Bx 4.4 .
+.Pp
+The
+.Fn setrunelocale
+function and the other non-ANSI rune functions were inspired by
+.Sy "Plan 9 from Bell Labs" .
+.\"They were conceived at the San Diego 1993 Summer USENIX conference by
+.\"Paul Borman of Krystal Technologies, Keith Bostic of CSRG and Andrew Hume
+.\"of Bell Labs.
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include "xlocale_private.h"
+
+#include <string.h>
+#include <rune.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include "runedepreciated.h"
+
+__private_extern__ const char __rune_depreciated_msg[] = "\
+%s and other functions prototyped in rune.h are depreciated in favor of\n\
+the ISO C99 extended multibyte and wide character facilities and should not\n\
+be used in new applications.\n\
+";
+
+__private_extern__ rune_t
+__sgetrune(const char *string, size_t n, char const **result)
+{
+ wchar_t wc;
+ size_t converted = mbrtowc(&wc, string, n, NULL);
+ __darwin_rune_t invalid_rune = __current_locale()->__lc_ctype->_CurrentRuneLocale.__invalid_rune;
+
+ switch (converted) {
+ case (size_t)-2: /* incomplete */
+ if (result)
+ *result = string;
+ return invalid_rune;
+ case (size_t)-1: /* invalid */
+ if (result)
+ *result = string + 1;
+ return invalid_rune;
+ case (size_t)0: /* null wide character */
+ {
+ int i;
+
+ for (i = 1; i < n; i++)
+ if (mbrtowc(&wc, string, n, NULL) == (size_t)0)
+ break;
+ if (result)
+ *result = string + i;
+ return (rune_t)0;
+ }
+ default:
+ if (result)
+ *result = string + converted;
+ return (rune_t)wc;
+ }
+ /* NOTREACHED */
+}
+
+__private_extern__ int
+__sputrune(rune_t rune, char *string, size_t n, char **result)
+{
+ char buf[MB_CUR_MAX];
+ size_t converted = wcrtomb(buf, rune, NULL);
+
+ if (converted < 0) {
+ if (result)
+ *result = string;
+ } else if (n >= converted) {
+ if (string)
+ bcopy(buf, string, converted);
+ if (result)
+ *result = string + converted;
+ } else if (result)
+ *result = NULL;
+ return (converted < 0 ? 0 : converted);
+}
+
+__private_extern__ rune_t
+sgetrune(const char *string, size_t n, char const **result)
+{
+ static int warn_depreciated = 1;
+
+ if (warn_depreciated) {
+ warn_depreciated = 0;
+ fprintf(stderr, __rune_depreciated_msg, "sgetrune");
+ }
+ return __sgetrune(string, n, result);
+}
+
+__private_extern__ int
+sputrune(rune_t rune, char *string, size_t n, char **result)
+{
+ static int warn_depreciated = 1;
+
+ if (warn_depreciated) {
+ warn_depreciated = 0;
+ fprintf(stderr, __rune_depreciated_msg, "sputrune");
+ }
+ return __sputrune(rune, string, n, result);
+}
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#undef sgetrune
+#undef sputrune
+#undef __sgetrune
+#undef __sputrune
+
+extern const char __rune_depreciated_msg[];
+
+/* The real, depreciated routines, that don't print the depreciated message */
+extern rune_t __sgetrune(const char *, size_t, char const **);
+extern int __sputrune(rune_t, char *, size_t, char **);
--- /dev/null
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Paul Borman at Krystal Technologies.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/libc/locale/setinvalidrune.c,v 1.3 2002/09/24 09:25:37 tjr Exp $");
+
+#include "xlocale_private.h"
+
+#include <rune.h>
+#include "runedepreciated.h"
+
+void
+setinvalidrune(ir)
+ rune_t ir;
+{
+ static int warn_depreciated = 1;
+ locale_t loc = __current_locale();
+
+ if (warn_depreciated) {
+ warn_depreciated = 0;
+ fprintf(stderr, __rune_depreciated_msg, "setinvalidrune");
+ }
+
+ if (loc->__lc_ctype->_CurrentRuneLocale.__invalid_rune != ir) {
+ struct __xlocale_st_runelocale *new = (struct __xlocale_st_runelocale *)malloc(loc->__lc_ctype->__datasize);
+ if (!new)
+ return;
+ *new = *loc->__lc_ctype;
+ new->__refcount = 1;
+ new->_CurrentRuneLocale.__invalid_rune = ir;
+ XL_RELEASE(loc->__lc_ctype);
+ loc->__lc_ctype = new;
+ }
+}
--- /dev/null
+.Dd March 11, 2005
+.Dt USELOCALE 3
+.Os
+.Sh NAME
+.Nm uselocale
+.Nd Set the per-thread locale
+.Sh SYNOPSIS
+.In xlocale.h
+.Ft locale_t
+.Fn uselocale "locale_t loc"
+.Sh DESCRIPTION
+Sets the per-thread locale to
+.Va loc .
+Specify
+.Dv LC_GLOBAL_LOCALE
+to turn off any per-thread locale.
+Pass
+.Dv NULL
+to return the current value of the per-thread locale (or
+.Dv LC_GLOBAL_LOCALE )
+without changing the locale.
+.Sh RETURN VALUES
+Returns the previous locale, or
+.Dv LC_GLOBAL_LOCALE
+if no per-thread locale was in effect.
+.Sh SEE ALSO
+.Xr xlocale 3 ,
+.Xr duplocale 3 ,
+.Xr freelocale 3 ,
+.Xr newlocale 3 ,
+.Xr querylocale 3
--- /dev/null
+.\" Copyright (c) 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Paul Borman at Krystal Technologies.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" @(#)utf2.4 8.1 (Berkeley) 6/4/93
+.\" $FreeBSD: src/lib/libc/locale/utf2.4,v 1.10 2002/10/10 22:56:18 tjr Exp $
+.\"
+.Dd October 11, 2002
+.Dt UTF2 5
+.Os
+.Sh NAME
+.Nm utf2
+.Nd "Universal character set Transformation Format encoding of runes
+.Sh SYNOPSIS
+.Nm ENCODING
+.Qq UTF2
+.Sh DESCRIPTION
+.Bf Em
+The UTF2 encoding has been deprecated in favour of UTF-8.
+.Ef
+New applications should not use UTF2.
+.Pp
+The
+.Nm UTF2
+encoding is based on a proposed X-Open multibyte
+\s-1FSS-UCS-TF\s+1 (File System Safe Universal Character Set Transformation Format) encoding as used in
+.Sy "Plan 9 from Bell Labs" .
+Although it is capable of representing more than 16 bits,
+the current implementation is limited to 16 bits as defined by the
+Unicode Standard.
+.Pp
+.Nm UTF2
+representation is backwards compatible with ASCII, so 0x00-0x7f refer to the
+ASCII character set. The multibyte encoding of runes between 0x0080 and 0xffff
+consist entirely of bytes whose high order bit is set. The actual
+encoding is represented by the following table:
+.Bd -literal
+[0x0000 - 0x007f] [00000000.0bbbbbbb] -> 0bbbbbbb
+[0x0080 - 0x07ff] [00000bbb.bbbbbbbb] -> 110bbbbb, 10bbbbbb
+[0x0800 - 0xffff] [bbbbbbbb.bbbbbbbb] -> 1110bbbb, 10bbbbbb, 10bbbbbb
+.Ed
+.Pp
+If more than a single representation of a value exists (for example,
+0x00; 0xC0 0x80; 0xE0 0x80 0x80) the shortest representation is always
+used (but the longer ones will be correctly decoded).
+.Pp
+The final three encodings provided by X-Open:
+.Bd -literal
+[00000000.000bbbbb.bbbbbbbb.bbbbbbbb] ->
+ 11110bbb, 10bbbbbb, 10bbbbbb, 10bbbbbb
+
+[000000bb.bbbbbbbb.bbbbbbbb.bbbbbbbb] ->
+ 111110bb, 10bbbbbb, 10bbbbbb, 10bbbbbb, 10bbbbbb
+
+[0bbbbbbb.bbbbbbbb.bbbbbbbb.bbbbbbbb] ->
+ 1111110b, 10bbbbbb, 10bbbbbb, 10bbbbbb, 10bbbbbb, 10bbbbbb
+.Ed
+.Pp
+which provides for the entire proposed ISO-10646 31 bit standard are currently
+not implemented.
+.Sh "SEE ALSO"
+.Xr mklocale 1 ,
+.Xr setlocale 3 ,
+.Xr utf8 5
--- /dev/null
+.\" Copyright (c) 2002, 2003 Tim J. Robbins
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/locale/wcstod.3,v 1.4 2003/05/22 13:02:27 ru Exp $
+.\"
+.Dd March 11, 2005
+.Dt WCSTOD_L 3
+.Os
+.Sh NAME
+.Nm wcstof_l ,
+.Nm wcstod_l ,
+.Nm wcstold_l
+.Nd convert string to
+.Vt float , double
+or
+.Vt "long double"
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In wchar.h
+.In xlocale.h
+.Ft float
+.Fn wcstof_l "const wchar_t * restrict nptr" "wchar_t ** restrict endptr" "locale_t loc"
+.Ft "long double"
+.Fn wcstold_l "const wchar_t * restrict nptr" "wchar_t ** restrict endptr" "locale_t loc"
+.Ft double
+.Fn wcstod_l "const wchar_t * restrict nptr" "wchar_t ** restrict endptr" "locale_t loc"
+.Sh DESCRIPTION
+The
+.Fn wcstof_l ,
+.Fn wcstod_l ,
+and
+.Fn wcstold_l
+functions are extended locale versions of the
+.Fn wcstof ,
+.Fn wcstod ,
+and
+.Fn wcstold
+functions, respectively.
+Refer to their manual pages for details.
+Also, see
+.Xr xlocale 3 for more information about extended locales.
+.Sh SEE ALSO
+.Xr wcstod 3 ,
+.Xr xlocale 3
--- /dev/null
+.\" Copyright (c) 2002 Tim J. Robbins
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/locale/wcstol.3,v 1.4 2002/11/29 17:35:09 ru Exp $
+.\"
+.Dd March 11, 2005
+.Dt WCSTOL_L 3
+.Os
+.Sh NAME
+.Nm wcstol_l , wcstoul_l ,
+.Nm wcstoll_l , wcstoull_l ,
+.Nm wcstoimax_l , wcstoumax_l
+.Nd "convert a wide character string value to a"
+.Vt long ,
+.Vt "unsigned long" ,
+.Vt "long long" ,
+.Vt "unsigned long long" ,
+.Vt intmax_t
+or
+.Vt uintmax_t
+integer
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In wchar.h
+.In xlocale.h
+.Ft long
+.Fn wcstol_l "const wchar_t * restrict nptr" "wchar_t ** restrict endptr" "int base" "locale_t loc"
+.Ft "unsigned long"
+.Fn wcstoul_l "const wchar_t * restrict nptr" "wchar_t ** restrict endptr" "int base" "locale_t loc"
+.Ft "long long"
+.Fn wcstoll_l "const wchar_t * restrict nptr" "wchar_t ** restrict endptr" "int base" "locale_t loc"
+.Ft "unsigned long long"
+.Fn wcstoull_l "const wchar_t * restrict nptr" "wchar_t ** restrict endptr" "int base" "locale_t loc"
+.In inttypes.h
+.Ft intmax_t
+.Fn wcstoimax_l "const wchar_t * restrict nptr" "wchar_t ** restrict endptr" "int base" "locale_t loc"
+.Ft uintmax_t
+.Fn wcstoumax_l "const wchar_t * restrict nptr" "wchar_t ** restrict endptr" "int base" "locale_t loc"
+.Sh DESCRIPTION
+The
+.Fn wcstol_l ,
+.Fn wcstoul_l ,
+.Fn wcstoll_l ,
+.Fn wcstoull_l ,
+.Fn wcstoimax_l
+and
+.Fn wcstoumax_l
+functions are extended locale versions of the
+.Fn wcstol ,
+.Fn wcstoul ,
+.Fn wcstoll ,
+.Fn wcstoull ,
+.Fn wcstoimax
+and
+.Fn wcstoumax
+functions, respectively.
+Refer to their manual pages for details.
+Also, see
+.Xr xlocale 3 for more information about extended locales.
+.Sh SEE ALSO
+.Xr wcstol 3 ,
+.Xr xlocale 3
--- /dev/null
+.Dd March 11, 2005
+.Dt XLOCALE 3
+.Os
+.Sh NAME
+.Nm xlocale
+.Nd Extended locale support.
+.Sh LIBRARY
+.Lb libc
+.Sh DESCRIPTION
+Include
+.Aq xlocale.h
+for extended locale support.
+It can be used alone or with the POSIX locale API in
+.Aq locale.h .
+.Pp
+The extended locale, or "xlocale" API consists of five basic routines, which are documented separately:
+.Xr duplocale 3 ,
+.Xr freelocale 3 ,
+.Xr newlocale 3 ,
+.Xr querylocale 3 ,
+and
+.Xr uselocale 3 .
+For each of these routines, if a NULL
+.Vt locale_t
+is given, the current locale is used.
+.Pp
+In addition,
+.Aq xlocale.h
+defines a few macros:
+.Pp
+.Bl -dash
+.It
+LC_GLOBAL_LOCALE - A special
+.Vt locale_t
+value that corresponds to the global, process-wide locale.
+.It
+MB_CUR_MAX - This macro is traditionally defined as an integer containing the value of the
+longest multi-byte string that a single-wide character in the global locale
+can translate into.
+With extended locales, this macro is replaced with a function that returns the
+value of the longest multi-byte string that a single-wide character in the current
+locale (per-thread or global) can translate into.
+.It
+MB_CUR_MAX_L(loc) - This macro is equivalent to MB_CUR_MAX, except that it may be passed
+a specific locale directly.
+.El
+.Sh CAVEATS
+The POSIX
+.Xr setlocale 3
+function only affects the global locale, so using it when a per-thread locale
+is in effect will not change locale behavior for that thread. However, it will
+change behavior for threads with no per-thread locale in effect.
+.Pp
+The routines defined in
+.Aq rune.h
+are deprecated, and may not be fully consistent with the xlocale API.
+Of particular note is
+.Fn setinvalidrune ,
+which would normally modify the value in the global locale.
+Since this value resides in a sub-structure of
+.Vt locale_t
+and sub-structures may be shared by multiple locales,
+.Fn setinvalidrune
+has been modified to make a copy of the sub-structure.
+This prevents it from affecting other locales.
+.Sh SEE ALSO
+.Xr localeconv 3 ,
+.Xr duplocale 3 ,
+.Xr freelocale 3 ,
+.Xr newlocale 3 ,
+.Xr querylocale 3 ,
+.Xr uselocale 3
+.Sh CONVENIENCE FUNCTIONS
+The xlocale API also includes "convenience functions"; functions that can be
+executed using a given locale, rather than the current locale. These functions all take one extra
+.Vt locale_t
+argument at the end of the traditional argument list, except in the case of variable-argument functions, in which case the extra argument comes before the format string.
+If a NULL
+.Vt locale_t
+is passed, the C locale will be used.
+.Pp
+For completeness,
+the convenience functions are listed here (organized by the header file that contains the original function).
+.Pp
+.Bl -tag -width monetary.h
+.It Aq _wctype.h
+.Xr iswalnum_l 3 ,
+.Xr iswalpha_l 3 ,
+.Xr iswcntrl_l 3 ,
+.Xr iswctype_l 3 ,
+.Xr iswdigit_l 3 ,
+.Xr iswgraph_l 3 ,
+.Xr iswlower_l 3 ,
+.Xr iswprint_l 3 ,
+.Xr iswpunct_l 3 ,
+.Xr iswspace_l 3 ,
+.Xr iswupper_l 3 ,
+.Xr iswxdigit_l 3 ,
+.Xr towlower_l 3 ,
+.Xr towupper_l 3 ,
+.Xr wctype_l 3
+.It Aq ctype.h
+.Xr digittoint_l 3 ,
+.Xr isalnum_l 3 ,
+.Xr isalpha_l 3 ,
+.Xr isblank_l 3 ,
+.Xr iscntrl_l 3 ,
+.Xr isdigit_l 3 ,
+.Xr isgraph_l 3 ,
+.Xr ishexnumber_l 3 ,
+.Xr isideogram_l 3 ,
+.Xr islower_l 3 ,
+.Xr isnumber_l 3 ,
+.Xr isphonogram_l 3 ,
+.Xr isprint_l 3 ,
+.Xr ispunct_l 3 ,
+.Xr isrune_l 3 ,
+.Xr isspace_l 3 ,
+.Xr isspecial_l 3 ,
+.Xr isupper_l 3 ,
+.Xr isxdigit_l 3 ,
+.Xr tolower_l 3 ,
+.Xr toupper_l 3
+.It Aq inttypes.h
+.Xr strtoimax_l 3 ,
+.Xr strtoumax_l 3 ,
+.Xr wcstoimax_l 3 ,
+.Xr wcstoumax_l 3
+.It Aq langinfo.h
+.Xr nl_langinfo_l 3
+.It Aq monetary.h
+.Xr strfmon_l 3
+.It Aq stdio.h
+.Xr asprintf_l 3 ,
+.Xr fprintf_l 3 ,
+.Xr fscanf_l 3 ,
+.Xr printf_l 3 ,
+.Xr scanf_l 3 ,
+.Xr snprintf_l 3 ,
+.Xr sprintf_l 3 ,
+.Xr sscanf_l 3 ,
+.Xr vasprintf_l 3 ,
+.Xr vfprintf_l 3 ,
+.Xr vfscanf_l 3 ,
+.Xr vprintf_l 3 ,
+.Xr vscanf_l 3 ,
+.Xr vsnprintf_l 3 ,
+.Xr vsprintf_l 3 ,
+.Xr vsscanf_l 3
+.It Aq stdlib.h
+.Xr atof_l 3 ,
+.Xr atoi_l 3 ,
+.Xr atol_l 3 ,
+.Xr atoll_l 3 ,
+.Xr mblen_l 3 ,
+.Xr mbstowcs_l 3 ,
+.Xr mbtowc_l 3 ,
+.Xr strtod_l 3 ,
+.Xr strtof_l 3 ,
+.Xr strtol_l 3 ,
+.Xr strtold_l 3 ,
+.Xr strtoll_l 3 ,
+.Xr strtoq_l 3 ,
+.Xr strtoul_l 3 ,
+.Xr strtoull_l 3 ,
+.Xr strtouq_l 3 ,
+.Xr wcstombs_l 3 ,
+.Xr wctomb_l 3
+.It Aq string.h
+.Xr strcoll_l 3 ,
+.Xr strxfrm_l 3 ,
+.Xr strcasecmp_l 3 ,
+.Xr strcasestr_l 3 ,
+.Xr strncasecmp_l 3
+.It Aq time.h
+.Xr strftime_l 3 ,
+.Xr strptime_l 3
+.It Aq wchar.h
+.Xr btowc_l 3 ,
+.Xr fgetwc_l 3 ,
+.Xr *fgetws_l 3 ,
+.Xr fputwc_l 3 ,
+.Xr fputws_l 3 ,
+.Xr fwprintf_l 3 ,
+.Xr fwscanf_l 3 ,
+.Xr getwc_l 3 ,
+.Xr getwchar_l 3 ,
+.Xr mbrlen_l 3 ,
+.Xr mbrtowc_l 3 ,
+.Xr mbsinit_l 3 ,
+.Xr mbsnrtowcs_l 3 ,
+.Xr mbsrtowcs_l 3 ,
+.Xr putwc_l 3 ,
+.Xr putwchar_l 3 ,
+.Xr swprintf_l 3 ,
+.Xr swscanf_l 3 ,
+.Xr ungetwc_l 3 ,
+.Xr vfwprintf_l 3 ,
+.Xr vfwscanf_l 3 ,
+.Xr vswprintf_l 3 ,
+.Xr vswscanf_l 3 ,
+.Xr vwprintf_l 3 ,
+.Xr vwscanf_l 3 ,
+.Xr wcrtomb_l 3 ,
+.Xr wcscoll_l 3 ,
+.Xr wcsftime_l 3 ,
+.Xr wcsnrtombs_l 3 ,
+.Xr wcsrtombs_l 3 ,
+.Xr wcstod_l 3 ,
+.Xr wcstof_l 3 ,
+.Xr wcstol_l 3 ,
+.Xr wcstold_l 3 ,
+.Xr wcstoll_l 3 ,
+.Xr wcstoul_l 3 ,
+.Xr wcstoull_l 3 ,
+.Xr wcswidth_l 3 ,
+.Xr wcsxfrm_l 3 ,
+.Xr wctob_l 3 ,
+.Xr wcwidth_l 3 ,
+.Xr wprintf_l 3 ,
+.Xr wscanf_l 3
+.It Aq wctype.h
+.Xr iswblank_l 3 ,
+.Xr iswhexnumber_l 3 ,
+.Xr iswideogram_l 3 ,
+.Xr iswnumber_l 3 ,
+.Xr iswphonogram_l 3 ,
+.Xr iswrune_l 3 ,
+.Xr iswspecial_l 3 ,
+.Xr nextwctype_l 3 ,
+.Xr towctrans_l 3 ,
+.Xr wctrans_l 3
+.It Aq xlocale.h
+.Xr localeconv_l 3
+.El
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include "xlocale_private.h"
+#include <errno.h>
+#include <stddef.h>
+#include <string.h>
+#include "ldpart.h"
+
+#define NMBSTATET 10
+#define C_LOCALE_INITIALIZER { \
+ {}, {}, {}, {}, {}, \
+ {}, {}, {}, {}, {}, \
+ XMAGIC, \
+ 1, 0, 0, 0, 0, 0, 1, 1, \
+ NULL, \
+ &_DefaultRuneXLocale, \
+}
+
+static char C[] = "C";
+static const struct _xlocale __c_locale = C_LOCALE_INITIALIZER;
+const locale_t _c_locale = (const locale_t)&__c_locale;
+__private_extern__ struct _xlocale __global_locale = C_LOCALE_INITIALIZER;
+__private_extern__ pthread_key_t __locale_key = (pthread_key_t)-1;
+
+extern int __collate_load_tables(const char *, locale_t);
+extern int __detect_path_locale(void);
+extern const char *__get_locale_env(int);
+extern int __messages_load_locale(const char *, locale_t);
+extern int __monetary_load_locale(const char *, locale_t);
+extern int __numeric_load_locale(const char *, locale_t);
+extern int __setrunelocale(const char *, locale_t);
+extern int __time_load_locale(const char *, locale_t);
+
+/*
+ * check that the encoding is the right size, isn't . or .. and doesn't
+ * contain any slashes
+ */
+static inline __attribute__((always_inline)) int
+_checkencoding(const char *encoding)
+{
+ return (encoding && (strlen(encoding) > ENCODING_LEN
+ || (encoding[0] == '.' && (encoding[1] == 0
+ || (encoding[1] == '.' && encoding[2] == 0)))
+ || strchr(encoding, '/') != NULL)) ? -1 : 0;
+}
+
+/*
+ * check that the locale has the right magic number
+ */
+static inline __attribute__((always_inline)) int
+_checklocale(const locale_t loc)
+{
+ if (!loc)
+ return 0;
+ return (loc == LC_GLOBAL_LOCALE || loc->__magic == XMAGIC) ? 0 : -1;
+}
+
+/*
+ * copy a locale_t except anything before the magic value
+ */
+static inline __attribute__((always_inline)) void
+_copylocale(locale_t dst, const locale_t src)
+{
+ memcpy(&dst->__magic, &src->__magic, sizeof(*dst) - offsetof(struct _xlocale, __magic));
+}
+
+/*
+ * Make a copy of a locale_t, locking/unlocking the source as determined
+ * by the lock flag. A NULL locale_t means to make a copy of the current
+ * locale while LC_GLOBAL_LOCALE means to copy the global locale. If
+ * &__c_locale is passed (meaning a C locale is desired), just make
+ * a copy.
+ */
+static locale_t
+_duplocale(locale_t loc)
+{
+ locale_t new;
+
+ if ((new = (locale_t)malloc(sizeof(struct _xlocale))) == NULL)
+ return NULL;
+ if (loc == NULL)
+ loc = __current_locale();
+ else if (loc == LC_GLOBAL_LOCALE)
+ loc = &__global_locale;
+ else if (loc == &__c_locale) {
+ *new = __c_locale;
+ return new;
+ }
+ _copylocale(new, loc);
+ /* __mbs_mblen is the first of NMBSTATET mbstate_t buffers */
+ bzero(&new->__mbs_mblen, NMBSTATET * sizeof(new->__mbs_mblen));
+ /* collate */
+ XL_RETAIN(new->__lc_collate);
+ /* ctype */
+ XL_RETAIN(new->__lc_ctype);
+ /* messages */
+ XL_RETAIN(new->__lc_messages);
+ /* monetary */
+ XL_RETAIN(new->__lc_monetary);
+ /* numeric */
+ XL_RETAIN(new->__lc_numeric);
+ /* time */
+ XL_RETAIN(new->__lc_time);
+ /* newale_t */
+ XL_RETAIN(new->__lc_localeconv);
+
+ return new;
+}
+
+/*
+ * Modify a locale_t, setting the parts specified in the mask
+ * to the locale specified by the string. If the string is NULL, the C
+ * locale is used. If the string is empty, the value is determined from
+ * the environment. -1 is returned on error, and loc is in a partial state.
+ */
+static int
+_modifylocale(locale_t loc, int mask, __const char *locale)
+{
+ int m, ret;
+ const char *enc = NULL;
+ char *oenc;
+
+ if (!locale)
+ locale = C;
+
+ ret = __detect_path_locale();
+ if (ret) {
+ errno = ret;
+ return -1;
+ }
+
+ if (*locale)
+ enc = locale;
+ for(m = 1; m <= _LC_LAST_MASK; m <<= 1) {
+ if (m & mask) {
+ switch(m) {
+ case LC_COLLATE_MASK:
+ if (!*locale) {
+ enc = __get_locale_env(LC_COLLATE);
+ if (_checkencoding(enc) < 0) {
+ errno = EINVAL;
+ return -1;
+ }
+ }
+ oenc = (loc->__collate_load_error ? C : loc->__lc_collate->__encoding);
+ if (strcmp(enc, oenc) != 0 && __collate_load_tables(enc, loc) == _LDP_ERROR)
+ return -1;
+ break;
+ case LC_CTYPE_MASK:
+ if (!*locale) {
+ enc = __get_locale_env(LC_CTYPE);
+ if (_checkencoding(enc) < 0) {
+ errno = EINVAL;
+ return -1;
+ }
+ }
+ if (strcmp(enc, loc->__lc_ctype->__ctype_encoding) != 0 && (ret = __setrunelocale(enc, loc)) != 0) {
+ errno = ret;
+ return -1;
+ }
+ break;
+ case LC_MESSAGES_MASK:
+ if (!*locale) {
+ enc = __get_locale_env(LC_MESSAGES);
+ if (_checkencoding(enc) < 0) {
+ errno = EINVAL;
+ return -1;
+ }
+ }
+ oenc = (loc->_messages_using_locale ? loc->__lc_messages->_messages_locale_buf : C);
+ if (strcmp(enc, oenc) != 0 && __messages_load_locale(enc, loc) == _LDP_ERROR)
+ return -1;
+ break;
+ case LC_MONETARY_MASK:
+ if (!*locale) {
+ enc = __get_locale_env(LC_MONETARY);
+ if (_checkencoding(enc) < 0) {
+ errno = EINVAL;
+ return -1;
+ }
+ }
+ oenc = (loc->_monetary_using_locale ? loc->__lc_monetary->_monetary_locale_buf : C);
+ if (strcmp(enc, oenc) != 0 && __monetary_load_locale(enc, loc) == _LDP_ERROR)
+ return -1;
+ break;
+ case LC_NUMERIC_MASK:
+ if (!*locale) {
+ enc = __get_locale_env(LC_NUMERIC);
+ if (_checkencoding(enc) < 0) {
+ errno = EINVAL;
+ return -1;
+ }
+ }
+ oenc = (loc->_numeric_using_locale ? loc->__lc_numeric->_numeric_locale_buf : C);
+ if (strcmp(enc, oenc) != 0 && __numeric_load_locale(enc, loc) == _LDP_ERROR)
+ return -1;
+ break;
+ case LC_TIME_MASK:
+ if (!*locale) {
+ enc = __get_locale_env(LC_TIME);
+ if (_checkencoding(enc) < 0) {
+ errno = EINVAL;
+ return -1;
+ }
+ }
+ oenc = (loc->_time_using_locale ? loc->__lc_time->_time_locale_buf : C);
+ if (strcmp(enc, oenc) != 0 && __time_load_locale(enc, loc) == _LDP_ERROR)
+ return -1;
+ break;
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * release all the memory objects (the memory will be freed when the refcount
+ * becomes zero)
+ */
+static void
+_releaselocale(locale_t loc)
+{
+ /* collate */
+ XL_RELEASE(loc->__lc_collate);
+ /* ctype */
+ XL_RELEASE(loc->__lc_ctype);
+ /* messages */
+ XL_RELEASE(loc->__lc_messages);
+ /* monetary */
+ XL_RELEASE(loc->__lc_monetary);
+ /* numeric */
+ XL_RELEASE(loc->__lc_numeric);
+ /* time */
+ XL_RELEASE(loc->__lc_time);
+ /* locale_t */
+ XL_RELEASE(loc->__lc_localeconv);
+}
+
+/*
+ * EXTERNAL: Duplicate a (non-NULL) locale_t. LC_GLOBAL_LOCALE means the
+ * global locale, while NULL means the current locale. NULL is returned
+ * on error.
+ */
+locale_t
+duplocale(locale_t loc)
+{
+ if (_checklocale(loc) < 0) {
+ errno = EINVAL;
+ return NULL;
+ }
+ return _duplocale(loc);
+}
+
+/*
+ * EXTERNAL: Free a locale_t, releasing all memory objects. Don't free
+ * illegal locale_t's or the global locale.
+ */
+int
+freelocale(locale_t loc)
+{
+ if (!loc || _checklocale(loc) < 0 || loc == &__global_locale
+ || loc == LC_GLOBAL_LOCALE) {
+ errno = EINVAL;
+ return -1;
+ }
+ _releaselocale(loc);
+ free(loc);
+ return 0;
+}
+
+/*
+ * EXTERNAL: Create a new locale_t, based on the base locale_t, and modified
+ * by the mask and locale string. If the base is NULL, the current locale
+ * is used as the base. If locale is NULL, changes are made from the C locale
+ * for categories set in mask.
+ */
+locale_t
+newlocale(int mask, __const char *locale, locale_t base)
+{
+ locale_t new;
+ int lcmask = (mask & LC_ALL_MASK);
+
+ if (_checkencoding(locale) < 0) {
+ errno = EINVAL;
+ return NULL;
+ }
+ if (lcmask == LC_ALL_MASK)
+ base = (locale_t)&__c_locale;
+ else if (_checklocale(base) < 0) {
+ errno = EINVAL;
+ return NULL;
+ }
+ new = _duplocale(base);
+ if (new == NULL)
+ return NULL;
+ if (lcmask == 0 || (lcmask == LC_ALL_MASK && locale == NULL))
+ return new;
+ if (_modifylocale(new, lcmask, locale) < 0) {
+ freelocale(new);
+ return NULL;
+ }
+ return new;
+}
+
+/*
+ * EXTERNAL: Returns the locale string for the part specified in mask. The
+ * least significant bit is used. If loc is NULL, the current per-thread
+ * locale is used.
+ */
+const char *
+querylocale(int mask, locale_t loc)
+{
+ int m;
+
+ if (_checklocale(loc) < 0 || (mask & LC_ALL_MASK) == 0) {
+ errno = EINVAL;
+ return NULL;
+ }
+ if (loc == NULL)
+ loc = __current_locale();
+ else if (loc == LC_GLOBAL_LOCALE)
+ loc = &__global_locale;
+ for(m = 1; m <= _LC_LAST_MASK; m <<= 1) {
+ if (m & mask) {
+ switch(m) {
+ case LC_COLLATE_MASK:
+ return (loc->__collate_load_error ? C : loc->__lc_collate->__encoding);
+ case LC_CTYPE_MASK:
+ return loc->__lc_ctype->__ctype_encoding;
+ case LC_MESSAGES_MASK:
+ return (loc->_messages_using_locale ? loc->__lc_messages->_messages_locale_buf : C);
+ case LC_MONETARY_MASK:
+ return (loc->_monetary_using_locale ? loc->__lc_monetary->_monetary_locale_buf : C);
+ case LC_NUMERIC_MASK:
+ return (loc->_numeric_using_locale ? loc->__lc_numeric->_numeric_locale_buf : C);
+ case LC_TIME_MASK:
+ return (loc->_time_using_locale ? loc->__lc_time->_time_locale_buf : C);
+ }
+ }
+ }
+ /* should never get here */
+ errno = EINVAL;
+ return NULL;
+}
+
+/*
+ * EXTERNAL: Set the thread-specific locale. The previous locale is returned.
+ * Use LC_GLOBAL_LOCALE to set the global locale. LC_GLOBAL_LOCALE
+ * may also be returned if there was no previous thread-specific locale in
+ * effect. If loc is NULL, the current locale is returned, but no locale
+ * chance is made. NULL is returned on error.
+ */
+locale_t
+uselocale(locale_t loc)
+{
+ locale_t orig;
+
+ if (loc == NULL)
+ orig = (locale_t)pthread_getspecific(__locale_key);
+ else {
+ if (_checklocale(loc) < 0) {
+ errno = EINVAL;
+ return NULL;
+ }
+ if (loc == &__global_locale) /* should never happen */
+ loc = LC_GLOBAL_LOCALE;
+ orig = pthread_getspecific(__locale_key);
+ pthread_setspecific(__locale_key, loc == LC_GLOBAL_LOCALE ? NULL : loc);
+ }
+ return (orig ? orig : LC_GLOBAL_LOCALE);
+}
+
+/*
+ * EXTERNAL: Used by the MB_CUR_MAX macro to determine the thread-specific
+ * value.
+ */
+int
+___mb_cur_max(void)
+{
+ return __current_locale()->__lc_ctype->__mb_cur_max;
+}
+
+/*
+ * EXTERNAL: Used by the MB_CUR_MAX_L macro to determine the thread-specific
+ * value, from the given locale_t.
+ */
+int
+___mb_cur_max_l(locale_t loc)
+{
+ return __locale_ptr(loc)->__lc_ctype->__mb_cur_max;
+}
+
+/*
+ * Called from the Libc initializer to setup the thread-specific key.
+ */
+__private_extern__ void
+__xlocale_init(void)
+{
+ if (__locale_key == (pthread_key_t)-1)
+ pthread_key_create(&__locale_key, NULL);
+}
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef _XLOCALE_PRIVATE_H_
+#define _XLOCALE_PRIVATE_H_
+
+#include <sys/cdefs.h>
+#include <xlocale.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <libkern/OSAtomic.h>
+#include <pthread.h>
+#include "setlocale.h"
+#include "collate.h"
+#include "runetype.h"
+#include "lmessages.h"
+#include "lmonetary.h"
+#include "lnumeric.h"
+#include "timelocal.h"
+
+#undef MB_CUR_MAX
+#define MB_CUR_MAX (__current_locale()->__lc_ctype->__mb_cur_max)
+#undef MB_CUR_MAX_L
+#define MB_CUR_MAX_L(x) ((x)->__lc_ctype->__mb_cur_max)
+
+extern int __is_threaded;
+
+typedef void (*__free_extra_t)(void *);
+
+#define XPERMANENT ((__free_extra_t)-1)
+#define XMAGIC 0x786c6f63616c6530LL /* 'xlocale0' */
+
+#define __STRUCT_COMMON \
+ int32_t __refcount; \
+ __free_extra_t __free_extra;
+
+struct __xlocale_st_collate {
+ __STRUCT_COMMON
+ char __encoding[ENCODING_LEN + 1];
+ unsigned char __substitute_table[UCHAR_MAX + 1][STR_LEN];
+ struct __collate_st_char_pri __char_pri_table[UCHAR_MAX + 1];
+ struct __collate_st_chain_pri *__chain_pri_table;
+};
+struct __xlocale_st_runelocale {
+ __STRUCT_COMMON
+ char __ctype_encoding[ENCODING_LEN + 1];
+ int __mb_cur_max;
+ size_t (*__mbrtowc)(wchar_t * __restrict, const char * __restrict,
+ size_t, __darwin_mbstate_t * __restrict, struct _xlocale *);
+ int (*__mbsinit)(const __darwin_mbstate_t *, struct _xlocale *);
+ size_t (*__mbsnrtowcs)(wchar_t * __restrict, const char ** __restrict,
+ size_t, size_t, __darwin_mbstate_t * __restrict, struct _xlocale *);
+ size_t (*__wcrtomb)(char * __restrict, wchar_t,
+ __darwin_mbstate_t * __restrict, struct _xlocale *);
+ size_t (*__wcsnrtombs)(char * __restrict, const wchar_t ** __restrict,
+ size_t, size_t, __darwin_mbstate_t * __restrict, struct _xlocale *);
+ int __datasize;
+ _RuneLocale _CurrentRuneLocale;
+};
+struct __xlocale_st_ldpart {
+ __STRUCT_COMMON
+ char *_locale_buf;
+};
+/*
+ * the next four structures must have the first three fields of the same
+ * as the _xlocale_st_ldpart structure above.
+ */
+struct __xlocale_st_messages {
+ __STRUCT_COMMON
+ char *_messages_locale_buf;
+ struct lc_messages_T _messages_locale;
+};
+struct __xlocale_st_monetary {
+ __STRUCT_COMMON
+ char *_monetary_locale_buf;
+ struct lc_monetary_T _monetary_locale;
+};
+struct __xlocale_st_numeric {
+ __STRUCT_COMMON
+ char *_numeric_locale_buf;
+ struct lc_numeric_T _numeric_locale;
+};
+struct __xlocale_st_time {
+ __STRUCT_COMMON
+ char *_time_locale_buf;
+ struct lc_time_T _time_locale;
+};
+
+struct __xlocale_st_localeconv {
+ __STRUCT_COMMON
+ struct lconv __ret;
+};
+
+/* the extended locale structure */
+struct _xlocale {
+/* The item(s) before __magic are not copied when duplicating locale_t's */
+ /* 10 independent mbstate_t buffers! */
+ __darwin_mbstate_t __mbs_mblen;
+ __darwin_mbstate_t __mbs_mbrlen;
+ __darwin_mbstate_t __mbs_mbrtowc;
+ __darwin_mbstate_t __mbs_mbsnrtowcs;
+ __darwin_mbstate_t __mbs_mbsrtowcs;
+ __darwin_mbstate_t __mbs_mbtowc;
+ __darwin_mbstate_t __mbs_wcrtomb;
+ __darwin_mbstate_t __mbs_wcsnrtombs;
+ __darwin_mbstate_t __mbs_wcsrtombs;
+ __darwin_mbstate_t __mbs_wctomb;
+/* magic (Here up to the end is copied when duplicating locale_t's) */
+ int64_t __magic;
+/* flags */
+ unsigned char __collate_load_error;
+ unsigned char __collate_substitute_nontrivial;
+ unsigned char _messages_using_locale;
+ unsigned char _monetary_using_locale;
+ unsigned char _numeric_using_locale;
+ unsigned char _time_using_locale;
+ unsigned char __mlocale_changed;
+ unsigned char __nlocale_changed;
+/* collate */
+ struct __xlocale_st_collate *__lc_collate;
+/* ctype */
+ struct __xlocale_st_runelocale *__lc_ctype;
+/* messages */
+ struct __xlocale_st_messages *__lc_messages;
+/* monetary */
+ struct __xlocale_st_monetary *__lc_monetary;
+/* numeric */
+ struct __xlocale_st_numeric *__lc_numeric;
+/* time */
+ struct __xlocale_st_time *__lc_time;
+/* localeconv */
+ struct __xlocale_st_localeconv *__lc_localeconv;
+};
+
+#define NORMALIZE_LOCALE(x) if ((x) == NULL) { \
+ (x) = _c_locale; \
+ } else if ((x) == LC_GLOBAL_LOCALE) { \
+ (x) = &__global_locale; \
+ }
+
+#define XL_RELEASE(x) if ((x) && (x)->__free_extra != XPERMANENT && OSAtomicDecrement32Barrier(&(x)->__refcount) <= 0) { \
+ if ((x)->__free_extra) \
+ (*(x)->__free_extra)((x)); \
+ free((x)); \
+ }
+#define XL_RETAIN(x) if ((x) && (x)->__free_extra != XPERMANENT) { OSAtomicIncrement32Barrier(&(x)->__refcount); }
+
+__private_extern__ struct __xlocale_st_runelocale _DefaultRuneXLocale;
+__private_extern__ struct _xlocale __global_locale;
+__private_extern__ pthread_key_t __locale_key;
+
+__BEGIN_DECLS
+
+void __ldpart_free_extra(struct __xlocale_st_ldpart *);
+void __xlocale_init(void);
+
+static inline __attribute__((always_inline)) locale_t
+__current_locale(void)
+{
+ locale_t __locale = (locale_t)pthread_getspecific(__locale_key);
+ return (__locale ? __locale : &__global_locale);
+}
+
+static inline __attribute__((always_inline)) locale_t
+__locale_ptr(locale_t __loc)
+{
+ return (__loc == LC_GLOBAL_LOCALE ? &__global_locale : __loc);
+}
+
+__END_DECLS
+
+#endif /* _XLOCALE_PRIVATE_H_ */
CLEANFILES += ${MIGHDRS} ${MIGSRCS} ${MD_MIGDEFS:.defs=Server.c} \
${MIGDEFS:.defs=Server.c} exc.h excUser.c excServer.c \
notify.h notifyUser.c notifyServer.c
+
+.if ${LIB} == "c"
+
+MAN2 += brk.2
+
+MLINKS += brk.2 sbrk.2
+
+.endif
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+.\" $NetBSD: brk.2,v 1.7 1995/02/27 12:31:57 cgd Exp $
+.\"
+.\" Copyright (c) 1980, 1991, 1993
+.\" The Regents of the University of California. 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" @(#)brk.2 8.2 (Berkeley) 12/11/93
+.\"
+.Dd December 11, 1993
+.Dt BRK 2
+.Os BSD 4
+.Sh NAME
+.Nm brk ,
+.Nm sbrk
+.Nd change data segment size
+.Sh SYNOPSIS
+.Fd #include <unistd.h>
+.Ft void *
+.Fn brk "const void *addr"
+.Ft void *
+.Fn sbrk "int incr"
+.Sh DESCRIPTION
+.Bf -symbolic
+The brk and sbrk functions are historical curiosities
+left over from earlier days before the advent of virtual memory management.
+.Ef
+The
+.Fn brk
+function
+sets the break or lowest address
+of a process's data segment (uninitialized data) to
+.Fa addr
+(immediately above bss).
+Data addressing is restricted between
+.Fa addr
+and the lowest stack pointer to the stack segment.
+Memory is allocated by
+.Fa brk
+in page size pieces;
+if
+.Fa addr
+is not evenly divisible by the system page size, it is
+increased to the next page boundary.
+.Pp
+.\" The
+.\" .Nm sbrk
+.\" function
+.\" allocates chunks of
+.\" .Fa incr
+.\" bytes
+.\" to the process's data space
+.\" and returns an address pointer.
+.\" The
+.\" .Xr malloc 3
+.\" function utilizes
+.\" .Nm sbrk .
+.\" .Pp
+The current value of the program break is reliably returned by
+.Dq Li sbrk(0)
+(see also
+.Xr end 3 ) .
+The
+.Xr getrlimit 2
+system call may be used to determine
+the maximum permissible size of the
+.Em data
+segment;
+it will not be possible to set the break
+beyond the
+.Em rlim_max
+value returned from a call to
+.Xr getrlimit ,
+e.g.
+.Dq qetext + rlp\(->rlim_max.
+(see
+.Xr end 3
+for the definition of
+.Em etext ) .
+.Sh RETURN VALUES
+.Nm Brk
+returns a pointer to the new end of memory if successful;
+otherwise -1 with
+.Va errno
+set to indicate why the allocation failed.
+The
+.Nm sbrk
+function returns a pointer to the base of the new storage if successful;
+otherwise -1 with
+.Va errno
+set to indicate why the allocation failed.
+.Sh ERRORS
+.Xr Sbrk
+will fail and no additional memory will be allocated if
+one of the following are true:
+.Bl -tag -width Er
+.It Bq Er ENOMEM
+The limit, as set by
+.Xr setrlimit 2 ,
+was exceeded.
+.It Bq Er ENOMEM
+The maximum possible size of a data segment (compiled into the
+system) was exceeded.
+.It Bq Er ENOMEM
+Insufficient space existed in the swap area
+to support the expansion.
+.El
+.Sh SEE ALSO
+.Xr execve 2 ,
+.Xr getrlimit 2 ,
+.Xr malloc 3 ,
+.Xr mmap 2 ,
+.Xr end 3
+.Sh BUGS
+Setting the break may fail due to a temporary lack of
+swap space. It is not possible to distinguish this
+from a failure caused by exceeding the maximum size of
+the data segment without consulting
+.Xr getrlimit .
+.Sh HISTORY
+A
+.Fn brk
+function call appeared in
+.At v7 .
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
/*
- * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
/*
* @OSF_COPYRIGHT@
*/
+#ifndef _MACH_EXTERNS_H_
+#define _MACH_EXTERNS_H_
-#include <mach/boolean.h>
-#include <mach/error.h>
-#include <mach/message.h>
-#include <mach/vm_types.h>
+#include <mach/mach_types.h>
+#include <sys/cdefs.h>
+__BEGIN_DECLS
extern void mig_init(void *);
extern void mach_init_ports(void);
-extern void mig_allocate(vm_address_t *, vm_size_t);
-extern void mig_deallocate(vm_address_t, vm_size_t);
+__END_DECLS
+#endif /* _MACH_EXTERNS_H_ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999-2005 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#include <mach/rpc.h> /* for compatibility only */
#include <mach/mig.h>
+
#include <mach/mig_errors.h>
+#include <mach/mach_error.h>
#include <sys/cdefs.h>
mach_port_t,
mach_msg_options_t);
-#ifdef MACH_KERNEL
-extern void *sbrk(int);
-
-extern int brk(void *);
-
-#endif
/*
* Prototypes for compatibility
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#include <sys/cdefs.h>
-__BEGIN_DECLS
/*
* Kernel-related ports; how a task/thread controls itself
*/
-extern mach_port_t mach_task_self_;
-
+__BEGIN_DECLS
extern mach_port_t mach_task_self(void);
extern mach_port_t mach_host_self(void);
extern mach_port_t mach_thread_self(void);
+__END_DECLS
+extern mach_port_t mach_task_self_;
#define mach_task_self() mach_task_self_
-
#define current_task() mach_task_self()
#include <mach/mach_traps.h>
+
/*
* Other important ports in the Mach user environment
*/
* error messages, this can be overridden by a user
* application to point to a user-specified output function
*/
-
+__BEGIN_DECLS
extern int (*vprintf_stderr_func)(const char *format, va_list ap);
__END_DECLS
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
__BEGIN_DECLS
extern void port_obj_init(int);
+__END_DECLS
+
extern struct port_obj_tentry *port_obj_table;
extern int port_obj_table_size;
-__END_DECLS
#ifndef PORT_OBJ_ASSERT
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
static void mach_atfork_child_routine(void);
static boolean_t first = TRUE;
static void (*previous_atfork_child_routine)(void);
+static boolean_t mach_init_inited = FALSE;
extern int mach_init(void);
extern void _pthread_set_self(void *);
extern void cthread_set_self(void *);
+extern void other_libc_init(void);
static void mach_atfork_child_routine(void)
if (previous_atfork_child_routine) {
(*previous_atfork_child_routine)();
}
+ mach_init_inited = FALSE;
mach_init();
}
VM_PROT_NONE, VM_PROT_NONE, VM_INHERIT_COPY);
/* ignore result, we don't care if it failed */
}
+
return(0);
}
+#ifdef __DYNAMIC__
+/* libc_initializer is the dyld initializer for libc (3760827) */
+static void libc_initializer() __attribute__((constructor));
+static void
+libc_initializer()
+{
+ mach_init();
+}
+#endif /* __DYNAMIC__ */
+
+/* mach_init may get called from the initializer and from crt.c, but only
+ * call mach_init_doit() once */
int mach_init(void)
{
- return(mach_init_doit(0));
+ int ret;
+
+ if (mach_init_inited)
+ return(0);
+ mach_init_inited = TRUE;
+ ret = mach_init_doit(0);
+
+ /* Do other Libc initialization */
+ other_libc_init();
+
+ return ret;
}
int (*mach_init_routine)(void) = mach_init;
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
mach_port_t name_server_port = MACH_PORT_NULL;
mach_port_t environment_port = MACH_PORT_NULL;
mach_port_t service_port = MACH_PORT_NULL;
+semaphore_t clock_sem = MACH_PORT_NULL;
mach_port_t clock_port = MACH_PORT_NULL;
mach_port_t thread_recycle_port = MACH_PORT_NULL;
/* Get the clock service port for nanosleep */
host = mach_host_self();
kr = host_get_clock_service(host, SYSTEM_CLOCK, &clock_port);
+ if (kr != KERN_SUCCESS) {
+ abort();
+ }
+ kr = semaphore_create(mach_task_self(), &clock_sem, SYNC_POLICY_FIFO, 0);
if (kr != KERN_SUCCESS) {
abort();
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999-2004 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* Memory allocation routine for MiG interfaces.
*/
#include <mach/mach.h>
-#include <mach/vm_statistics.h>
-#include "externs.h"
void
mig_allocate(vm_address_t *addr_p, vm_size_t size)
/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999-2004 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* Memory deallocation routine for MiG interfaces.
*/
#include <mach/mach.h>
-#include "externs.h"
void
mig_deallocate(vm_address_t addr, vm_size_t size)
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#include <mach/mach.h> /* for vm_allocate, vm_offset_t */
#include <mach/vm_statistics.h>
-#include <sys/types.h> /* for caddr_t */
static int sbrk_needs_init = TRUE;
static vm_size_t sbrk_region_size = 4*1024*1024; /* Well, what should it be? */
static vm_address_t sbrk_curbrk;
-caddr_t sbrk(size)
+void *sbrk(size)
int size;
{
kern_return_t ret;
ret = vm_allocate(mach_task_self(), &sbrk_curbrk, sbrk_region_size,
VM_MAKE_TAG(VM_MEMORY_SBRK)|TRUE);
if (ret != KERN_SUCCESS)
- return((caddr_t)-1);
+ return((void *)-1);
}
if (size <= 0)
- return((caddr_t)sbrk_curbrk);
+ return((void *)sbrk_curbrk);
else if (size > sbrk_region_size)
- return((caddr_t)-1);
+ return((void *)-1);
sbrk_curbrk += size;
sbrk_region_size -= size;
- return((caddr_t)(sbrk_curbrk - size));
+ return((void *)(sbrk_curbrk - size));
}
-caddr_t brk(x)
- caddr_t x;
+void *brk(x)
+ void *x;
{
- return((caddr_t)-1);
+ return((void *)-1);
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+#!/usr/bin/perl
+#
+# Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+#
+# @APPLE_LICENSE_HEADER_START@
+#
+# This file contains Original Code and/or Modifications of Original Code
+# as defined in and that are subject to the Apple Public Source License
+# Version 2.0 (the 'License'). You may not use this file except in
+# compliance with the License. Please obtain a copy of the License at
+# http://www.opensource.apple.com/apsl/ and read it before using this
+# file.
+#
+# The Original Code and all software distributed under the License are
+# distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+# Please see the License for the specific language governing rights and
+# limitations under the License.
+#
+# @APPLE_LICENSE_HEADER_END@
+
+use strict;
+
+# combine arguments without a slash, with the preceding argument with a slash
+# use @ instead of space for separator
+my @args;
+my $prev;
+for(@ARGV) {
+ if(m,/,) {
+ push(@args, $prev) if $prev;
+ $prev = $_;
+ } else {
+ $prev .= "\@$_";
+ }
+}
+push(@args, $prev) if $prev;
+
+# now make all unique combinations
+my %combos;
+foreach my $variant (@args) {
+ my($v, $defines) = split('/', $variant, 2);
+ my %new;
+ @new{$v, map("$_-$v", keys %combos)} = ($defines, map("$_\@$defines", values %combos));
+ %combos = (%combos, %new);
+}
+for(sort keys(%combos)) {
+ printf "%s/%s\n", $_, $combos{$_};
+}
--- /dev/null
+#! /bin/sh -x
+
+libc_ldbl128=$1
+suffix=$2
+destdir=$3
+usr_local_lib_system=$4
+
+libldbl128=libldbl128$suffix.a
+objdir=`dirname $libc_ldbl128`
+tmpdir=$objdir/tmp
+libm=libm$suffix.a
+libgcc=libgcc
+libgccppc=$libgcc-ppc.a
+libm128='ArcHyperbolicDD.o ArcSinCosDD.o ArcTanDD.o AuxiliaryDD.o ErfDD.o ExpDD.o ExpTableLD.o GammaDD.o HyperbolicDD.o LogDD.o LogTableLD.o PowerDD.o SinCosTanDD.o SqrtDD.o complex.o complexld64.o d3ops.o floating.o fpmacros.o ld64.o'
+
+mkdir -p $tmpdir
+cd $tmpdir
+rm -f *
+lipo -thin ppc -output $libm $usr_local_lib_system/$libm
+ar x $libm $libm128
+rm -f $libm
+ar x $libc_ldbl128
+rm -f __.*
+mkdir -p $destdir
+ar cq $destdir/$libldbl128 `lorder * | tsort -q`
+ranlib $destdir/$libldbl128
+if [ -z "$suffix" ]; then
+ lib=`gcc-3.5 -arch ppc -print-file-name=$libgcc.a`
+ cp $lib $destdir/$libgccppc
+fi
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#ifndef __NBSD_COMPAT__H_
+#define __NBSD_COMPAT__H_
+
+#define _DIAGASSERT(x) /* */
+#define __warn_references(x,y) /* */
+
+#endif /* __NBSD_COMPAT__H_ */
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+/*
+ * This file left intentionally blank
+ */
.\" SUCH DAMAGE.
.\"
.\" $ANA: addr2ascii.3,v 1.1 1996/06/13 18:41:46 wollman Exp $
-.\" $FreeBSD: src/lib/libc/net/addr2ascii.3,v 1.13 2002/12/19 09:40:22 ru Exp $
+.\" $FreeBSD: src/lib/libc/net/addr2ascii.3,v 1.17 2004/10/09 17:13:58 maxim Exp $
.\"
.Dd June 13, 1996
.Dt ADDR2ASCII 3
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
-.In sys/types.h
-.In netinet/in.h
.In arpa/inet.h
.Ft "char *"
.Fn addr2ascii "int af" "const void *addrp" "int len" "char *buf"
and
.Fn ascii2addr
are used to convert network addresses between binary form and a
-printable form appropriate to the address family. Both functions take
+printable form appropriate to the address family.
+Both functions take
an
.Fa af
argument, specifying the address family to be used in the conversion
.Fn addr2ascii
function
is used to convert binary, network-format addresses into printable
-form. In addition to
+form.
+In addition to
.Fa af ,
-there are three other arguments. The
+there are three other arguments.
+The
.Fa addrp
argument is a pointer to the network address to be converted.
The
.Fa len
-argument is the length of the address. The
+argument is the length of the address.
+The
.Fa buf
argument is an optional pointer to a caller-allocated buffer to hold
the result; if a null pointer is passed,
The
.Fa ascii
argument is a pointer to the string which is to be converted into
-binary. The
+binary.
+The
.Fa result
argument is a pointer to an appropriate network address structure for
the specified family.
.It Dv AF_INET
.Li struct in_addr
(in
-.Aq Pa netinet/in.h )
+.In arpa/inet.h )
.It Dv AF_LINK
.Li struct sockaddr_dl
(in
-.Aq Pa net/if_dl.h )
+.In net/if_dl.h )
.\" .It Dv AF_INET6
.\" .Li struct in6_addr
.\" (in
-.\" .Aq Pa netinet6/in6.h )
+.\" .In netinet6/in6.h )
.El
+.Pp
+.Dv AF_INET and AF_LINK constants are defined in
+.In sys/socket.h
.Sh RETURN VALUES
The
.Fn addr2ascii
.Fn inet_aton
could be implemented thusly:
.Bd -literal -offset indent
-#include <sys/types.h>
#include <sys/socket.h>
-#include <netinet/in.h>
#include <arpa/inet.h>
char *
.Xr inet 4
.Sh HISTORY
An interface close to this one was originally suggested by Craig
-Partridge. This particular interface originally appeared in the
+Partridge.
+This particular interface originally appeared in the
.Tn INRIA
.Tn IPv6
implementation.
.An Garrett A. Wollman ,
MIT Laboratory for Computer Science.
.Sh BUGS
-The original implementations supported IPv6. This support should
-eventually be resurrected. The
+The original implementations supported IPv6.
+This support should
+eventually be resurrected.
+The
.Tn NRL
implementation also included support for the
.Dv AF_ISO
.Dv AF_NS
address families.
.Pp
-The genericity of this interface is somewhat questionable. A truly
+The genericity of this interface is somewhat questionable.
+A truly
generic interface would provide a means for determining the length of
the buffer to be used so that it could be dynamically allocated, and
would always require a
.Dq Li "struct sockaddr"
-to hold the binary address. Unfortunately, this is incompatible with existing
-practice. This limitation means that a routine for printing network
+to hold the binary address.
+Unfortunately, this is incompatible with existing
+practice.
+This limitation means that a routine for printing network
addresses from arbitrary address families must still have internal
knowledge of the maximum buffer length needed and the appropriate part
of the address to use as the binary address.
.\" SUCH DAMAGE.
.\"
.\" From: @(#)inet.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/net/inet.3,v 1.25 2002/09/06 11:23:49 tjr Exp $
+.\" $FreeBSD: src/lib/libc/net/inet.3,v 1.29 2004/07/02 23:52:11 ru Exp $
.\"
-.Dd June 17, 1996
+.Dd June 14, 2004
.Dt INET 3
.Os
.Sh NAME
.Pp
The function
.Fn inet_ntop
-converts an address from network format (usually a
+converts an address
+.Fa *src
+from network format
+(usually a
.Ft struct in_addr
or some other binary form, in network byte order) to presentation format
(suitable for external display purposes).
+The
+.Fa size
+argument specifies the size, in bytes, of the buffer
+.Fa *dst .
It returns NULL if a system error occurs (in which case,
.Va errno
will have been set), or it returns a pointer to the destination string.
.Tn ASCII
string representing the address in
.Ql .\&
-notation. The routine
+notation.
+The routine
.Fn inet_makeaddr
takes an Internet network number and a local
network address and constructs an Internet address
-from it. The routines
+from it.
+The routines
.Fn inet_netof
and
.Fn inet_lnaof
.Pp
When four parts are specified, each is interpreted
as a byte of data and assigned, from left to right,
-to the four bytes of an Internet address. Note
+to the four bytes of an Internet address.
+Note
that when an Internet address is viewed as a 32-bit
integer quantity on the
.Tn VAX
.Fn inet_ntoa
functions are semi-deprecated in favor of the
.Xr addr2ascii 3
-family. However, since those functions are not yet widely implemented,
+family.
+However, since those functions are not yet widely implemented,
portable programs cannot rely on their presence and will continue
to use the
.Xr inet 3
and
.Fn inet_network
for malformed requests.
+.Sh ERRORS
+The
+.Fn inet_ntop
+call fails if:
+.Bl -tag -width Er
+.It Bq Er ENOSPC
+.Fa size
+was not large enough to store the presentation form of the address.
+.It Bq Er EAFNOSUPPORT
+.Fa *src
+was not an
+.Dv AF_INET
+or
+.Dv AF_INET6
+family address.
+.El
.Sh SEE ALSO
.Xr addr2ascii 3 ,
.Xr byteorder 3 ,
--- /dev/null
+--- inet_addr.c.orig 2003-05-20 15:22:14.000000000 -0700
++++ inet_addr.c 2005-02-24 17:08:54.000000000 -0800
+@@ -61,6 +61,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/net/inet_addr.c,v 1.16 2002/04/19 04:46:20 suz Exp $");
+
++#include "xlocale_private.h"
++
+ #include <sys/param.h>
+
+ #include <netinet/in.h>
+@@ -103,6 +105,7 @@
+ char *c;
+ char *endptr;
+ int gotend, n;
++ locale_t loc = __current_locale();
+
+ c = (char *)cp;
+ n = 0;
+@@ -113,7 +116,7 @@
+ gotend = 0;
+ while (!gotend) {
+ errno = 0;
+- val = strtoul(c, &endptr, 0);
++ val = strtoul_l(c, &endptr, 0, loc);
+
+ if (errno == ERANGE) /* Fail completely if it overflowed. */
+ return (0);
+@@ -144,7 +147,7 @@
+ break;
+
+ default:
+- if (isspace((unsigned char)*c)) {
++ if (isspace_l((unsigned char)*c, loc)) {
+ gotend = 1;
+ break;
+ } else
static const char orig_rcsid[] = "From Id: inet_net_pton.c,v 1.8 1996/11/21 10:28:12 vixie Exp $";
#endif
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/net/inet_net_pton.c,v 1.8 2002/03/22 21:52:29 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/net/inet_net_pton.c,v 1.9 2003/09/15 23:38:06 fenner Exp $");
#include <sys/types.h>
#include <sys/socket.h>
else /* Class A */
bits = 8;
/* If imputed mask is narrower than specified octets, widen. */
- if (bits >= 8 && bits < ((dst - odst) * 8))
+ if (bits < ((dst - odst) * 8))
bits = (dst - odst) * 8;
}
/* Extend network to cover the actual mask. */
--- /dev/null
+--- inet_net_pton.c.orig 2004-11-25 11:38:29.000000000 -0800
++++ inet_net_pton.c 2005-02-24 16:53:40.000000000 -0800
+@@ -21,6 +21,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/net/inet_net_pton.c,v 1.9 2003/09/15 23:38:06 fenner Exp $");
+
++#include "xlocale_private.h"
++
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+@@ -97,19 +99,20 @@
+ digits[] = "0123456789";
+ int n, ch, tmp, dirty, bits;
+ const u_char *odst = dst;
++ locale_t loc = __current_locale();
+
+ ch = *src++;
+ if (ch == '0' && (src[0] == 'x' || src[0] == 'X')
+- && isascii(src[1]) && isxdigit(src[1])) {
++ && isascii(src[1]) && isxdigit_l(src[1], loc)) {
+ /* Hexadecimal: Eat nybble string. */
+ if (size <= 0)
+ goto emsgsize;
+ *dst = 0, dirty = 0;
+ src++; /* skip x or X. */
+ while ((ch = *src++) != '\0' &&
+- isascii(ch) && isxdigit(ch)) {
+- if (isupper(ch))
+- ch = tolower(ch);
++ isascii(ch) && isxdigit_l(ch, loc)) {
++ if (isupper_l(ch, loc))
++ ch = tolower_l(ch, loc);
+ n = strchr(xdigits, ch) - xdigits;
+ assert(n >= 0 && n <= 15);
+ *dst |= n;
+@@ -122,7 +125,7 @@
+ }
+ if (dirty)
+ size--;
+- } else if (isascii(ch) && isdigit(ch)) {
++ } else if (isascii(ch) && isdigit_l(ch, loc)) {
+ /* Decimal: eat dotted digit string. */
+ for (;;) {
+ tmp = 0;
+@@ -134,7 +137,7 @@
+ if (tmp > 255)
+ goto enoent;
+ } while ((ch = *src++) != '\0' &&
+- isascii(ch) && isdigit(ch));
++ isascii(ch) && isdigit_l(ch, loc));
+ if (size-- <= 0)
+ goto emsgsize;
+ *dst++ = (u_char) tmp;
+@@ -143,14 +146,14 @@
+ if (ch != '.')
+ goto enoent;
+ ch = *src++;
+- if (!isascii(ch) || !isdigit(ch))
++ if (!isascii(ch) || !isdigit_l(ch, loc))
+ goto enoent;
+ }
+ } else
+ goto enoent;
+
+ bits = -1;
+- if (ch == '/' && isascii(src[0]) && isdigit(src[0]) && dst > odst) {
++ if (ch == '/' && isascii(src[0]) && isdigit_l(src[0], loc) && dst > odst) {
+ /* CIDR width specifier. Nothing can follow it. */
+ ch = *src++; /* Skip over the /. */
+ bits = 0;
+@@ -159,7 +162,7 @@
+ assert(n >= 0 && n <= 9);
+ bits *= 10;
+ bits += n;
+- } while ((ch = *src++) != '\0' && isascii(ch) && isdigit(ch));
++ } while ((ch = *src++) != '\0' && isascii(ch) && isdigit_l(ch, loc));
+ if (ch != '\0')
+ goto enoent;
+ if (bits > 32)
--- /dev/null
+--- inet_network.c.orig 2003-05-20 15:22:14.000000000 -0700
++++ inet_network.c 2005-02-24 16:50:11.000000000 -0800
+@@ -37,6 +37,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/net/inet_network.c,v 1.9 2002/03/22 21:52:29 obrien Exp $");
+
++#include "xlocale_private.h"
++
+ #include <sys/types.h>
+ #include <netinet/in.h>
+ #include <arpa/inet.h>
+@@ -55,6 +57,7 @@
+ char c;
+ in_addr_t parts[4], *pp = parts;
+ int i;
++ locale_t loc = __current_locale();
+
+ again:
+ val = 0; base = 10;
+@@ -63,13 +66,13 @@
+ if (*cp == 'x' || *cp == 'X')
+ base = 16, cp++;
+ while ((c = *cp) != 0) {
+- if (isdigit((unsigned char)c)) {
++ if (isdigit_l((unsigned char)c, loc)) {
+ val = (val * base) + (c - '0');
+ cp++;
+ continue;
+ }
+- if (base == 16 && isxdigit((unsigned char)c)) {
+- val = (val << 4) + (c + 10 - (islower((unsigned char)c) ? 'a' : 'A'));
++ if (base == 16 && isxdigit_l((unsigned char)c, loc)) {
++ val = (val << 4) + (c + 10 - (islower_l((unsigned char)c, loc) ? 'a' : 'A'));
+ cp++;
+ continue;
+ }
+@@ -81,7 +84,7 @@
+ *pp++ = val, cp++;
+ goto again;
+ }
+- if (*cp && !isspace((unsigned char)*cp))
++ if (*cp && !isspace_l((unsigned char)*cp, loc))
+ return (INADDR_NONE);
+ *pp++ = val;
+ n = pp - parts;
.\" SUCH DAMAGE.
.\"
.\" From: @(#)linkaddr.3 8.1 (Berkeley) 7/28/93
-.\" $FreeBSD: src/lib/libc/net/linkaddr.3,v 1.13 2002/12/18 12:45:09 ru Exp $
+.\" $FreeBSD: src/lib/libc/net/linkaddr.3,v 1.14 2004/07/03 22:30:08 ru Exp $
.\"
.Dd June 17, 1996
.Dt LINK_ADDR 3
and
.Fn link_ntoa
functions appeared in
-.Bx 4.3 Reno .
+.Bx 4.3 Reno .
.Sh BUGS
The returned values for link_ntoa
reside in a static memory area.
---- nsap_addr.c.orig Fri Mar 22 13:52:29 2002
-+++ nsap_addr.c Sat May 3 14:17:44 2003
-@@ -26,6 +26,7 @@
+--- nsap_addr.c.orig 2003-05-20 15:22:14.000000000 -0700
++++ nsap_addr.c 2005-02-24 16:48:08.000000000 -0800
+@@ -18,6 +18,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/net/nsap_addr.c,v 1.9 2002/03/22 21:52:29 obrien Exp $");
+
++#include "xlocale_private.h"
++
+ #include <sys/types.h>
+ #include <sys/param.h>
+ #include <sys/socket.h>
+@@ -26,6 +28,7 @@
#include <arpa/nameser.h>
#include <ctype.h>
#include <resolv.h>
static char
xtob(c)
-@@ -78,9 +79,14 @@
+@@ -42,20 +45,21 @@
+ {
+ u_char c, nib;
+ u_int len = 0;
++ locale_t loc = __current_locale();
+
+ while ((c = *ascii++) != '\0' && len < (u_int)maxlen) {
+ if (c == '.' || c == '+' || c == '/')
+ continue;
+ if (!isascii(c))
+ return (0);
+- if (islower(c))
+- c = toupper(c);
+- if (isxdigit(c)) {
++ if (islower_l(c, loc))
++ c = toupper_l(c, loc);
++ if (isxdigit_l(c, loc)) {
+ nib = xtob(c);
+ c = *ascii++;
+ if (c != '\0') {
+- c = toupper(c);
+- if (isxdigit(c)) {
++ c = toupper_l(c, loc);
++ if (isxdigit_l(c, loc)) {
+ *binary++ = (nib << 4) | xtob(c);
+ len++;
+ } else
+@@ -78,9 +82,14 @@
{
int nib;
int i;
recv.c send.c
.include "Makefile.fbsd_end"
+UNIX03SRCS+= recv.c send.c
+
CFLAGS+= -I${.OBJDIR}
# machine-dependent net sources
******************************************************************/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/nls/msgcat.c,v 1.45 2002/10/27 17:44:33 wollman Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/nls/msgcat.c,v 1.48 2003/10/29 10:45:01 tjr Exp $");
/*
* We need a better way of handling errors than printing text. I need
pcode = cptr;
}
- if ((nlspath = getenv("NLSPATH")) == NULL
-#ifndef __NETBSD_SYSCALLS
- || issetugid()
-#endif
- )
+ if ((nlspath = getenv("NLSPATH")) == NULL || issetugid())
nlspath = _DEFAULT_NLS_PATH;
if ((base = cptr = strdup(nlspath)) == NULL) {
---- msgcat.c.orig Sun Oct 27 09:44:33 2002
-+++ msgcat.c Sat May 3 14:19:40 2003
+--- msgcat.c.orig 2004-11-25 11:38:30.000000000 -0800
++++ msgcat.c 2005-02-27 12:06:52.000000000 -0800
+@@ -45,7 +45,7 @@
+ #include <errno.h>
+ #include <fcntl.h>
+ #include <limits.h>
+-#include <locale.h>
++#include <xlocale.h>
+ #include <nl_types.h>
+ #include <stdio.h>
+ #include <stdlib.h>
@@ -54,7 +54,7 @@
#include "un-namespace.h"
#define _DEFAULT_NLS_PATH "/usr/share/nls/%L/%N.cat:/usr/share/nls/%N/%L:/usr/local/share/nls/%L/%N.cat:/usr/local/share/nls/%N/%L"
+@@ -87,7 +87,7 @@
+ return (loadCat(name));
+
+ if (type == NL_CAT_LOCALE)
+- lang = setlocale(LC_MESSAGES, NULL);
++ lang = (char *)querylocale(LC_MESSAGES_MASK, NULL);
+ else
+ lang = getenv("LANG");
+
-# $FreeBSD: src/lib/libc/posix1e/Makefile.inc,v 1.6 2001/09/01 00:00:50 rwatson Exp $
+.PATH: ${.CURDIR}/posix1e
-MAINTAINER= rwatson@FreeBSD.org
-
-.PATH: ${.CURDIR}/../libc/posix1e
-
-MISRCS+= acl_calc_mask.c \
- acl_copy.c \
- acl_delete.c \
- acl_delete_entry.c \
- acl_entry.c \
- acl_free.c \
- acl_from_text.c \
- acl_get.c \
- acl_init.c \
- acl_perm.c \
- acl_set.c \
- acl_support.c \
- acl_to_text.c \
- acl_valid.c \
- cap_clear.c \
- cap_cmp.c \
- cap_copy.c \
- cap_dup.c \
- cap_free.c \
- cap_get_fd.c \
- cap_get_file.c \
- cap_get_flag.c \
- cap_get_proc.c \
- cap_init.c \
- cap_set_fd.c \
- cap_set_file.c \
- cap_set_flag.c \
- cap_set_proc.c \
- cap_text.c
+MISRCS+= acl.c \
+ acl_entry.c \
+ acl_file.c \
+ acl_flag.c \
+ acl_perm.c \
+ acl_translate.c
.if ${LIB} == "c"
-MAN+= acl.3 \
+MAN3 += acl.3 \
+ acl_add_flag_np.3 \
acl_add_perm.3 \
- acl_calc_mask.3 \
+ acl_clear_flags_np.3 \
acl_clear_perms.3 \
acl_copy_entry.3 \
acl_create_entry.3 \
acl_delete.3 \
acl_delete_entry.3 \
+ acl_delete_flag_np.3 \
acl_delete_perm.3 \
acl_dup.3 \
acl_free.3 \
acl_from_text.3 \
acl_get.3 \
acl_get_entry.3 \
+ acl_get_flagset_np.3 \
acl_get_permset.3 \
acl_get_perm_np.3 \
acl_get_qualifier.3 \
acl_get_tag_type.3 \
acl_init.3 \
acl_set.3 \
+ acl_set_flagset_np.3 \
acl_set_permset.3 \
acl_set_qualifier.3 \
acl_set_tag_type.3 \
acl_to_text.3 \
- acl_valid.3 \
- cap.3 \
- cap_clear.3 \
- cap_copy_ext.3 \
- cap_copy_int.3 \
- cap_dup.3 \
- cap_free.3 \
- cap_from_text.3 \
- cap_get_flag.3 \
- cap_get_proc.3 \
- cap_init.3 \
- cap_set_flag.3 \
- cap_set_proc.3 \
- cap_to_text.3 \
- posix1e.3
+ acl_valid.3
-MLINKS+=acl_delete.3 acl_delete_def_file.3 \
+MLINKS+=acl_create_entry.3 acl_create_entry_np.3 \
acl_delete.3 acl_delete_file_np.3 \
acl_delete.3 acl_delete_fd_np.3 \
acl_get.3 acl_get_file.3 \
acl_set.3 acl_set_fd.3 \
acl_set.3 acl_set_fd_np.3 \
acl_valid.3 acl_valid_file_np.3 \
- acl_valid.3 acl_valid_fd_np.3 \
- cap_copy_ext.3 cap_size.3
+ acl_valid.3 acl_valid_fd_np.3
.endif
--- /dev/null
+.\"-
+.\" Copyright (c) 2000, 2001, 2002 Robert N. M. Watson
+.\" All rights reserved.
+.\"
+.\" This software was developed by Robert Watson for the TrustedBSD Project.
+.\"
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl.3,v 1.22 2003/02/06 11:04:46 charnier Exp $
+.\"
+.Dd December 18, 2002
+.Dt ACL 3
+.Os
+.Sh NAME
+.Nm acl
+.Nd introduction to the POSIX.1e ACL security API
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Sh DESCRIPTION
+The system permits file systems to export Access Control Lists via the VFS, and
+provides a library for userland access to and manipulation of these ACLs.
+Not all file systems provide support for ACLs, and some may require that
+ACL support be explicitly enabled by the administrator.
+The library calls include routines to allocate, duplicate, retrieve, set,
+and validate ACLs associated with file objects.
+.Pp
+This implementation of the POSIX.1e library differs from the standard
+in a number of non-portable ways in order to support the MacOS/Darwin
+ACL semantic. Where possible, these differences are implemented using
+the mechanisms provided in the standard for such extensions.
+Where routines are non-standard, they are suffixed with _np to indicate that
+they are not portable.
+.Pp
+POSIX.1e describes a set of ACL manipulation routines to manage the
+contents of ACLs, as well as their relationships with files; almost
+all of these support routines are implemented.
+.Pp
+Available functions, sorted by behavior, include:
+.Bl -tag -width indent
+.It Fn acl_add_perm
+This function is described in
+.Xr acl_add_perm 3 ,
+and may be used to add permissions to a permission set.
+.It Fn acl_clear_perms
+This function is described in
+.Xr acl_clear_perms 3 ,
+and may be used to clear all permissions from a permission set.
+.It Fn acl_copy_entry
+This function is described in
+.Xr acl_copy_entry 3 ,
+and may be used to copy the contents of an ACL entry.
+.It Fn acl_create_entry
+This function is described in
+.Xr acl_create_entry 3 ,
+and may be used to create an empty entry in an ACL.
+.It Xo
+.Fn acl_delete_fd_np ,
+.Fn acl_delete_file_np ,
+.Fn acl_delete_link_np
+.Xc
+These functions are described in
+.Xr acl_delete 3 ,
+and may be used to delete ACLs from file system objects.
+.It Fn acl_delete_entry
+This function is described in
+.Xr acl_delete_entry 3 ,
+and may be used to delete an entry from an ACL.
+.It Fn acl_delete_perm
+This function is described in
+.Xr acl_delete_perm 3 ,
+and may be used to delete permissions from a permset.
+.It Fn acl_dup
+This function is described in
+.Xr acl_dup 3 ,
+and may be used to duplicate an ACL structure.
+.It Fn acl_free
+This function is described in
+.Xr acl_free 3 ,
+and may be used to free userland working ACL storage.
+.It Fn acl_from_text
+This function is described in
+.Xr acl_from_text 3 ,
+and may be used to convert a text-form ACL into working ACL state, if
+the ACL has POSIX.1e semantics.
+.It Fn acl_get_entry
+This function is described in
+.Xr acl_get_entry 3 ,
+and may be used to retrieve a designated ACL entry from an ACL.
+.It Xo
+.Fn acl_get_fd ,
+.Fn acl_get_fd_np ,
+.Fn acl_get_file ,
+.Fn acl_get_link_np
+.Xc
+These functions are described in
+.Xr acl_get 3 ,
+and may be used to retrieve ACLs from file system objects.
+.It Fn acl_get_permset
+This function is described in
+.Xr acl_get_permset 3 ,
+and may be used to retrieve a permset from an ACL entry.
+.It Fn acl_get_qualifier
+This function is described in
+.Xr acl_get_qualifier 3 ,
+and may be used to retrieve the qualifier from an ACL entry.
+.It Fn acl_get_tag_type
+This function is described in
+.Xr acl_get_tag_type 3 ,
+and may be used to retrieve the tag type from an ACL entry.
+.It Fn acl_init
+This function is described in
+.Xr acl_init 3 ,
+and may be used to allocate a fresh (empty) ACL structure.
+.It Xo
+.Fn acl_set_fd ,
+.Fn acl_set_fd_np ,
+.Fn acl_set_file ,
+.Fn acl_set_link_np
+.Xc
+These functions are described in
+.Xr acl_set 3 ,
+and may be used to assign an ACL to a file system object.
+.It Fn acl_set_permset
+This function is described in
+.Xr acl_set_permset 3 ,
+and may be used to set the permissions of an ACL entry from a permset.
+.It Fn acl_set_qualifier
+This function is described in
+.Xr acl_set_qualifier 3 ,
+and may be used to set the qualifier of an ACL.
+.It Fn acl_set_tag_type
+This function is described in
+.Xr acl_set_tag_type 3 ,
+and may be used to set the tag type of an ACL.
+.It Fn acl_to_text
+This function is described in
+.Xr acl_to_text 3 ,
+and may be used to generate a text-form of a POSIX.1e semantics ACL.
+.It Xo
+.Fn acl_valid ,
+.Fn acl_valid_fd_np ,
+.Fn acl_valid_file_np ,
+.Fn acl_valid_link_np
+.Xc
+These functions are described in
+.Xr acl_valid 3 ,
+and may be used to validate an ACL as correct POSIX.1e-semantics, or
+as appropriate for a particular file system object regardless of semantics.
+.El
+.Pp
+Documentation of the internal kernel interfaces backing these calls may
+be found in
+.Xr acl 9 .
+The syscalls between the internal interfaces and the public library
+routines may change over time, and as such are not documented.
+They are not intended to be called directly without going through the
+library.
+.Sh SEE ALSO
+.Xr getfacl 1 ,
+.Xr setfacl 1 ,
+.Xr acl_add_perm 3 ,
+.Xr acl_clear_perms 3 ,
+.Xr acl_copy_entry 3 ,
+.Xr acl_create_entry 3 ,
+.Xr acl_delete_entry 3 ,
+.Xr acl_delete_perm 3 ,
+.Xr acl_dup 3 ,
+.Xr acl_free 3 ,
+.Xr acl_from_text 3 ,
+.Xr acl_get 3 ,
+.Xr acl_get_permset 3 ,
+.Xr acl_get_qualifier 3 ,
+.Xr acl_get_tag_type 3 ,
+.Xr acl_init 3 ,
+.Xr acl_set 3 ,
+.Xr acl_set_permset 3 ,
+.Xr acl_set_qualifier 3 ,
+.Xr acl_set_tag_type 3 ,
+.Xr acl_to_text 3 ,
+.Xr acl_valid 3 ,
+.Xr posix1e 3 ,
+.Xr acl 9
+.Sh UNSUPPORTED FUNCTIONS
+.Xr acl_calc_mask 3 ,
+.Fn acl_delete_def_file
+.Sh STANDARDS
+POSIX.1e assigns security labels to all objects, extending the security
+functionality described in POSIX.1.
+These additional labels provide fine-grained discretionary access control,
+fine-grained capabilities, and labels necessary for mandatory access
+control.
+POSIX.2c describes a set of userland utilities for manipulating these
+labels.
+.Pp
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh HISTORY
+This manpage is closely derived from the
+.Fx
+manpage by
+.An Robert N M Watson
+.Sh AUTHORS
+.An Michael Smith
+.An Robert N M Watson
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include <sys/appleapiopts.h>
+#include <sys/types.h>
+#include <sys/acl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "aclvar.h"
+
+acl_t
+acl_dup(acl_t acl)
+{
+ struct _acl *ap;
+
+ if (!_ACL_VALID_ACL(acl)) {
+ errno = EINVAL;
+ return(NULL);
+ }
+
+ if ((ap = malloc(sizeof(*ap))) != NULL)
+ bcopy(acl, ap, sizeof(*ap));
+ return(ap);
+}
+
+int
+acl_free(void *obj)
+{
+ /*
+ * Without tracking the addresses of text buffers and qualifiers,
+ * we can't validate the obj argument here at all.
+ */
+ free(obj);
+ return(0);
+}
+
+acl_t
+acl_init(int count)
+{
+ struct _acl *ap;
+
+ /* validate count */
+ if (count < 0) {
+ errno = EINVAL;
+ return(NULL);
+ }
+ if (count > ACL_MAX_ENTRIES) {
+ errno = ENOMEM;
+ return(NULL);
+ }
+
+ if ((ap = malloc(sizeof (*ap))) != NULL) {
+ bzero(ap, sizeof(*ap));
+ ap->a_magic = _ACL_ACL_MAGIC;
+ ap->a_last_get = -1;
+ }
+ return(ap);
+}
+
+int
+acl_valid(acl_t acl)
+{
+ _ACL_VALIDATE_ACL(acl);
+
+ /* XXX */
+ return(0);
+}
+
+int
+acl_valid_fd_np(int fd, acl_type_t type, acl_t acl)
+{
+ errno = ENOTSUP; /* XXX */
+ return(-1);
+}
+
+int
+acl_valid_file_np(const char *path, acl_type_t type, acl_t acl)
+{
+ errno = ENOTSUP; /* XXX */
+ return(-1);
+}
+
+int
+acl_valid_link(const char *path, acl_type_t type, acl_t acl)
+{
+ errno = ENOTSUP; /* XXX */
+ return(-1);
+}
+
+/*
+ * Not applicable; not supportedl
+ */
+int
+acl_calc_mask(__unused acl_t *acl_p)
+{
+ errno = ENOTSUP;
+ return(-1);
+}
--- /dev/null
+.\"-
+.\" Copyright (c) 2001 Chris D. Faulhaber
+.\" 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 THE VOICES IN HIS HEAD 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_add_perm.3,v 1.6 2002/12/18 12:45:09 ru Exp $
+.\"
+.Dd March 10, 2001
+.Dt ACL_ADD_FLAG_NP 3
+.Os
+.Sh NAME
+.Nm acl_add_flag_np
+.Nd add flags to an flag set
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_add_flag_np "acl_flagset_t flagset_d" "acl_flag_t flag"
+.Sh DESCRIPTION
+The
+.Fn acl_add_flag_np
+function
+is a nonstandard extension that adds the flag contained in
+.Fa flag
+to the flag set
+.Fa flagset_d .
+.Pp
+Note: it is not considered an error to attempt to add flags
+that already exist in the flag set.
+.Sh RETURN VALUES
+.Rv -std acl_add_flags_np
+.Sh ERRORS
+The
+.Fn acl_add_flags_np
+function fails if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Fa flagset_d
+is not a valid descriptor for a flag set.
+Argument
+.Fa flag
+does not contain an
+.Vt acl_flag_t
+value valid for the flagset
+.Fa flagset_d .
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_clear_entry_flagset_np 3 ,
+.Xr acl_delete_entry_flag_np 3 ,
+.Xr acl_get_entry_flagset_np 3 ,
+.Xr acl_set_entry_permset_np 3 ,
+.Xr posix1e 3
+.Sh AUTHORS
+.An Michael Smith
+.An Chris D Fulhaber
--- /dev/null
+.\"-
+.\" Copyright (c) 2001 Chris D. Faulhaber
+.\" 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 THE VOICES IN HIS HEAD 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_add_perm.3,v 1.6 2002/12/18 12:45:09 ru Exp $
+.\"
+.Dd March 10, 2001
+.Dt ACL_ADD_PERM 3
+.Os
+.Sh NAME
+.Nm acl_add_perm
+.Nd add permissions to a permission set
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_add_perm "acl_permset_t permset_d" "acl_perm_t perm"
+.Sh DESCRIPTION
+The
+.Fn acl_add_perm
+function
+is a POSIX.1e call that adds the permission contained in
+.Fa perm
+to the permission set
+.Fa permset_d .
+.Pp
+Note: it is not considered an error to attempt to add permissions
+that already exist in the permission set.
+.Sh RETURN VALUES
+.Rv -std acl_add_perm
+.Sh ERRORS
+The
+.Fn acl_add_perm
+function fails if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Fa permset_d
+is not a valid descriptor for a permission set within an ACL entry.
+Argument
+.Fa perm
+does not contain a valid
+.Vt acl_perm_t
+value.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_clear_perms 3 ,
+.Xr acl_delete_perm 3 ,
+.Xr acl_get_permset 3 ,
+.Xr acl_set_permset 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Chris D Fulhaber
--- /dev/null
+.\"-
+.\" Copyright (c) 2001 Chris D. Faulhaber
+.\" 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 THE VOICES IN HIS HEAD 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_clear_perms.3,v 1.5 2002/12/18 12:45:09 ru Exp $
+.\"
+.Dd March 10, 2001
+.Dt ACL_CLEAR_FLAGS_NP 3
+.Os
+.Sh NAME
+.Nm acl_clear_flags_np
+.Nd clear flags from a flag set
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_clear_flags_np "acl_flagset_t flagset_d"
+.Sh DESCRIPTION
+The
+.Fn acl_clear_flags_np
+function
+is a nonstandard extension that clears all flags from flag set
+.Fa flagset_d .
+.Sh RETURN VALUES
+.Rv -std acl_clear_flags_np
+.Sh ERRORS
+The
+.Fn acl_clear_flags_np
+function fails if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Fa flagset_d
+is not a valid descriptor for a flag set.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_add_flag_np 3 ,
+.Xr acl_delete_flag_np 3 ,
+.Xr acl_get_flagset_np 3 ,
+.Xr acl_set_flagset_np 3 ,
+.Sh AUTHORS
+.An Michael Smith
+.An Chris D Fulhaber
--- /dev/null
+.\"-
+.\" Copyright (c) 2001 Chris D. Faulhaber
+.\" 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 THE VOICES IN HIS HEAD 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_clear_perms.3,v 1.5 2002/12/18 12:45:09 ru Exp $
+.\"
+.Dd March 10, 2001
+.Dt ACL_CLEAR_PERMS 3
+.Os
+.Sh NAME
+.Nm acl_clear_perms
+.Nd clear permissions from a permission set
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_clear_perms "acl_permset_t permset_d"
+.Sh DESCRIPTION
+The
+.Fn acl_clear_perms
+function
+is a POSIX.1e call that clears all permissions from permissions set
+.Fa permset_d .
+.Sh RETURN VALUES
+.Rv -std acl_clear_perms
+.Sh ERRORS
+The
+.Fn acl_clear_perms
+function fails if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Fa permset_d
+is not a valid descriptor for a permission set.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_add_perm 3 ,
+.Xr acl_delete_perm 3 ,
+.Xr acl_get_permset 3 ,
+.Xr acl_set_permset 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Chris D Fulhaber
--- /dev/null
+.\"-
+.\" Copyright (c) 2001 Chris D. Faulhaber
+.\" 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 THE VOICES IN HIS HEAD 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_copy_entry.3,v 1.5 2002/12/18 12:45:09 ru Exp $
+.\"
+.Dd March 10, 2001
+.Dt ACL_COPY_ENTRY 3
+.Os
+.Sh NAME
+.Nm acl_copy_entry
+.Nd copy an ACL entry to another ACL entry
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_copy_entry "acl_entry_t dest_d" "acl_entry_t src_d"
+.Sh DESCRIPTION
+The
+.Fn acl_copy_entry
+function
+is a POSIX.1e call that copies the contents of ACL entry
+.Fa src_d
+to ACL entry
+.Fa dest_d .
+.Sh RETURN VALUES
+.Rv -std acl_copy_entry
+.Sh ERRORS
+The
+.Fn acl_copy_entry
+function fails if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Fa src_d
+or
+.Fa dest_d
+is not a valid descriptor for an ACL entry, or
+arguments
+.Fa src_d
+and
+.Fa dest_d
+reference the same ACL entry.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_get_entry 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Chris D Fulhaber
--- /dev/null
+.\"-
+.\" Copyright (c) 2001 Chris D. Faulhaber
+.\" 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 THE VOICES IN HIS HEAD 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_create_entry.3,v 1.5 2002/12/18 12:45:09 ru Exp $
+.\"
+.Dd March 16, 2001
+.Dt ACL_CREATE_ENTRY 3
+.Os
+.Sh NAME
+.Nm acl_create_entry ,
+.Nm acl_create_entry_np
+.Nd create a new ACL entry
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_create_entry "acl_t *acl_p" "acl_entry_t *entry_p"
+.Ft int
+.Fn acl_create_entry_np "acl_t *acl_p" "acl_entry_t *entry_p" "int entry_index"
+.Sh DESCRIPTION
+The
+.Fn acl_create_entry
+function
+is a POSIX.1e call that creates a new ACL entry in the ACL
+pointed to by
+.Fa acl_p .
+.Pp
+The
+.Fn acl_create_entry_np
+function is a non-portable extension which allows the caller to specify the
+position of the created entry within the ACL. If
+.Fa entry_index
+is
+.Dv ACL_FIRST_ENTRY
+the entry will be created at the head of the ACL. If
+.Fa entry_index
+is
+.Dv ACL_LAST_ENTRY
+the entry will be created at the end of the ACL. After inserting an ACL entry with an
+.Fa entry_index
+other than
+.Dv ACL_LAST_ENTRY
+the behaviour of any acl_entry_t's previously obtained from the ACL
+by
+.Fn acl_create_entry
+or
+.Fn acl_get_entry
+is undefined.
+.Sh RETURN VALUES
+.Rv -std acl_create_entry
+.Sh ERRORS
+The
+.Fn acl_create_entry
+and
+.Fn acl_create_entry_np
+functions fail if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Fa acl_p
+does not point to a pointer to a valid ACL.
+.It Bq Er ENOMEM
+The ACL working storage requires more memory than is
+allowed by the hardware or system-imposed memory
+management constraints.
+.It Bq Er ERANGE
+The
+.Fa entry_index
+argument to
+.Fn acl_create_entry_np
+is greater than the number of entries in the ACL.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_delete_entry 3 ,
+.Xr acl_get_entry 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Chris D Fulhaber
--- /dev/null
+.\"-
+.\" Copyright (c) 2000, 2002 Robert N. M. Watson
+.\" All rights reserved.
+.\"
+.\" This software was developed by Robert Watson for the TrustedBSD Project.
+.\"
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_delete.3,v 1.16 2003/02/23 01:44:37 ru Exp $
+.\"
+.Dd December 29, 2002
+.Dt ACL_DELETE 3
+.Os
+.Sh NAME
+.Nm acl_delete_fd_np ,
+.Nm acl_delete_file_np
+.Nm acl_delete_link_np
+.Nd delete an ACL from a file
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_delete_fd_np "int filedes" "acl_type_t type"
+.Ft int
+.Fn acl_delete_file_np "const char *path_p" "acl_type_t type"
+.Ft int
+.Fn acl_delete_link_np "const char *path_p" "acl_type_t type"
+.Sh DESCRIPTION
+The
+.Fn acl_delete_fd_np ,
+.Fn acl_delete_file_np ,
+and
+.Fn acl_delete_link_np
+each allow the deletion of an ACL from a file.
+These functions are non-portable extensions
+that permit the deletion of arbitrary ACL types from a file/directory
+either by path name or file descriptor.
+The
+.Fn _file
+variations follow a symlink if it occurs in the last segment of the
+path name; the
+.Fn _link
+variations operate on the symlink itself.
+.Sh RETURN VALUES
+.Rv -std
+.Sh ERRORS
+If any of the following conditions occur, these functions shall return -1
+and set
+.Va errno
+to the corresponding value:
+.Bl -tag -width Er
+.It Bq Er EACCES
+Search permission is denied for a component of the path prefix, or the
+object exists and the process does not have appropriate access rights.
+.It Bq Er EBADF
+The
+.Va fd
+argument is not a valid file descriptor.
+.It Bq Er EINVAL
+The ACL type passed is invalid for this file object.
+.It Bq Er ENAMETOOLONG
+A component of a pathname exceeded 255 characters, or an
+entire path name exceeded 1023 characters.
+.It Bq Er ENOENT
+The named object does not exist, or the
+.Va path_p
+argument points to an empty string.
+.It Bq Er ENOMEM
+Insufficient memory available to fulfill request.
+.It Bq Er ENOTDIR
+A component of the path prefix is not a directory.
+.Pp
+Argument
+.Va path_p
+must be a directory, and is not.
+.It Bq Er EOPNOTSUPP
+The file system does not support ACL deletion.
+.It Bq Er EPERM
+The process does not have appropriate privilege to perform the operation
+to delete an ACL.
+.It Bq Er EROFS
+The file system is read-only.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_get 3 ,
+.Xr acl_set 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Robert N M Watson
--- /dev/null
+.\"-
+.\" Copyright (c) 2001 Chris D. Faulhaber
+.\" 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 THE VOICES IN HIS HEAD 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_delete_entry.3,v 1.5 2002/12/18 12:45:09 ru Exp $
+.\"
+.Dd March 10, 2001
+.Dt ACL_DELETE_ENTRY 3
+.Os
+.Sh NAME
+.Nm acl_delete_entry
+.Nd delete an ACL entry from an ACL
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_delete_entry "acl_t acl" "acl_entry_t entry_d"
+.Sh DESCRIPTION
+The
+.Fn acl_delete_entry
+function
+is a POSIX.1e call that removes the ACL entry
+.Fa entry_d
+from ACL
+.Fa acl .
+.Sh RETURN VALUES
+.Rv -std acl_delete_entry
+.Sh ERRORS
+The
+.Fn acl_delete_entry
+function fails if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Fa acl
+does not point to a valid ACL. Argument
+.Fa entry_d
+is not a valid descriptor for an ACL entry in
+.Fa acl .
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_copy_entry 3 ,
+.Xr acl_get_entry 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Chris D Fulhaber
--- /dev/null
+.\"-
+.\" Copyright (c) 2001 Chris D. Faulhaber
+.\" 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 THE VOICES IN HIS HEAD 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_delete_entry_flag_np.3,v 1.5 2002/12/18 12:45:09 ru Exp $
+.\"
+.Dd March 10, 2001
+.Dt ACL_DELETE_FLAG_NP 3
+.Os
+.Sh NAME
+.Nm acl_delete_flag_np
+.Nd delete flags from a flag set
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_delete_flag_np "acl_flagset_t flagset_d" "acl_flag_t flag"
+.Sh DESCRIPTION
+The
+.Fn acl_delete_flag_np
+function
+is a nonstandard extension that removes the specific flag
+.Fa flag
+from the flag set
+.Fa flagset_d .
+.Sh RETURN VALUES
+.Rv -std acl_delete_flag_np
+.Sh ERRORS
+The
+.Fn acl_delete_flag_np
+function fails if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Fa flagset_d
+is not a valid descriptor for a flag set. Argument
+.Fa flag
+does not contain an
+.Vt acl_flag_t
+value that is valid for the
+.Fa flagset_d
+flagset.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_add_flag_np 3 ,
+.Xr acl_clear_flags_np 3 ,
+.Xr acl_get_flagset_np 3 ,
+.Xr acl_set_flagset_np 3 ,
+.Sh AUTHORS
+.An Michael Smith
+.An Chris D. Faulhaber
--- /dev/null
+.\"-
+.\" Copyright (c) 2001 Chris D. Faulhaber
+.\" 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 THE VOICES IN HIS HEAD 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_delete_perm.3,v 1.5 2002/12/18 12:45:09 ru Exp $
+.\"
+.Dd March 10, 2001
+.Dt ACL_DELETE_PERM 3
+.Os
+.Sh NAME
+.Nm acl_delete_perm
+.Nd delete permissions from a permission set
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_delete_perm "acl_permset_t permset_d" "acl_perm_t perm"
+.Sh DESCRIPTION
+The
+.Fn acl_delete_perm
+function
+is a POSIX.1e call that removes specific permissions from permissions set
+.Fa perm .
+.Sh RETURN VALUES
+.Rv -std acl_delete_perm
+.Sh ERRORS
+The
+.Fn acl_delete_perm
+function fails if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Fa permset_d
+is not a valid descriptor for a permission set. Argument
+.Fa perm
+does not contain a valid
+.Vt acl_perm_t
+value.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_add_perm 3 ,
+.Xr acl_clear_perms 3 ,
+.Xr acl_get_permset 3 ,
+.Xr acl_set_permset 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh HISTORY
+POSIX.1e support was introduced in
+.Fx 4.0 .
+The
+.Fn acl_delete_perm
+function was added in
+.Fx 5.0 .
+.Sh AUTHORS
+The
+.Fn acl_delete_perm
+function was written by
+.An Chris D. Faulhaber Aq jedgar@fxp.org .
--- /dev/null
+.\"-
+.\" Copyright (c) 2000, 2002 Robert N. M. Watson
+.\" All rights reserved.
+.\"
+.\" This software was developed by Robert Watson for the TrustedBSD Project.
+.\"
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_dup.3,v 1.12 2002/12/29 20:52:42 rwatson Exp $
+.\"
+.Dd January 28, 2000
+.Dt ACL_DUP 3
+.Os
+.Sh NAME
+.Nm acl_dup
+.Nd duplicate an ACL
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft acl_t
+.Fn acl_dup "acl_t acl"
+.Sh DESCRIPTION
+The
+.Fn acl_dup
+function returns a pointer to a copy of the ACL pointed to by the argument
+.Va acl .
+.Pp
+This function may cause memory to be allocated. The caller should free any
+releasable memory, when the new ACL is no longer required, by calling
+.Xr acl_free 3
+with the
+.Va (void*)acl_t
+as an argument.
+.Pp
+Any existing ACL pointers that refer to the ACL referred to by
+.Va acl
+shall continue to refer to the ACL.
+.Sh RETURN VALUES
+Upon successful completion, this function shall return a pointer to the
+duplicate ACL. Otherwise, a value of
+.Va (acl_t)NULL
+shall be returned, and
+.Va errno
+shall be set to indicate the error.
+.Sh ERRORS
+If any of the following conditions occur, the
+.Fn acl_init
+function shall return a value of
+.Va (acl_t)NULL
+and set
+.Va errno
+to the corresponding value:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Va acl
+does not point to a valid ACL.
+.It Bq Er ENOMEM
+The
+.Va acl_t
+to be returned requires more memory than is allowed by the hardware or
+system-imposed memory management constraints.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_free 3 ,
+.Xr acl_get 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Robert N M Watson
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include <sys/appleapiopts.h>
+#include <sys/types.h>
+#include <sys/acl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "aclvar.h"
+
+int
+acl_copy_entry(acl_entry_t dest, acl_entry_t src)
+{
+ /* validate arguments */
+ _ACL_VALIDATE_ENTRY(dest);
+ _ACL_VALIDATE_ENTRY(src);
+ if (dest == src) {
+ errno = EINVAL;
+ return(-1);
+ }
+ bcopy(src, dest, sizeof(*src));
+ return(0);
+}
+
+int
+acl_create_entry_np(acl_t *acl_p, acl_entry_t *entry_p, int index)
+{
+ struct _acl *ap = *acl_p;
+ int i;
+
+ /* validate arguments */
+ _ACL_VALIDATE_ACL(ap);
+ if (ap->a_entries >= ACL_MAX_ENTRIES) {
+ errno = ENOMEM;
+ return(-1);
+ }
+ if (index == ACL_LAST_ENTRY)
+ index = ap->a_entries;
+ if (index > ap->a_entries) {
+ errno = ERANGE;
+ return(-1);
+ }
+
+ /* move following entries out of the way */
+ for (i = ap->a_entries; i > index; i--)
+ ap->a_ace[i] = ap->a_ace[i - 1];
+ ap->a_entries++;
+
+ /* initialise new entry */
+ ap->a_ace[index].ae_magic = _ACL_ENTRY_MAGIC;
+ ap->a_ace[index].ae_tag = ACL_UNDEFINED_TAG;
+
+ *entry_p = &ap->a_ace[index];
+ return(0);
+}
+
+int
+acl_create_entry(acl_t *acl_p, acl_entry_t *entry_p)
+{
+ return(acl_create_entry_np(acl_p, entry_p, ACL_LAST_ENTRY));
+}
+
+int
+acl_delete_entry(acl_t acl, acl_entry_t entry)
+{
+ int i;
+
+ _ACL_VALIDATE_ACL(acl);
+ _ACL_VALIDATE_ENTRY(entry);
+ _ACL_VALIDATE_ENTRY_CONTAINED(acl, entry);
+
+ /* copy following entries down & invalidate last slot */
+ acl->a_entries--;
+ for (i = entry - &acl->a_ace[0]; i < acl->a_entries; i++)
+ acl->a_ace[i] = acl->a_ace[i + 1];
+ acl->a_ace[acl->a_entries].ae_magic = 0;
+ /* Sync up the iterator's position if necessary */
+ if (acl->a_last_get >= (entry - &acl->a_ace[0]))
+ acl->a_last_get--;
+
+ return(0);
+}
+
+int
+acl_get_entry(acl_t acl, int entry_id, acl_entry_t *entry_p)
+{
+
+ _ACL_VALIDATE_ACL(acl);
+ if ((entry_id != ACL_FIRST_ENTRY) &&
+ (entry_id != ACL_NEXT_ENTRY) &&
+ (entry_id != ACL_LAST_ENTRY) &&
+ ((entry_id < 0) || (entry_id >= acl->a_entries))) {
+ errno = EINVAL;
+ return(-1);
+ }
+ if (entry_id == ACL_FIRST_ENTRY)
+ entry_id = 0;
+ else
+ if (entry_id == ACL_NEXT_ENTRY) {
+ entry_id = acl->a_last_get + 1;
+ }
+ else
+ if (entry_id == ACL_LAST_ENTRY)
+ entry_id = acl->a_entries - 1;
+
+ if (entry_id >= acl->a_entries) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ *entry_p = &acl->a_ace[entry_id];
+ acl->a_last_get = entry_id;
+
+ return(0);
+}
+
+void *
+acl_get_qualifier(acl_entry_t entry)
+{
+ acl_tag_t tag_type;
+ void *result;
+ int error;
+
+ result = NULL;
+ if (!_ACL_VALID_ENTRY(entry)) {
+ errno = EINVAL;
+ } else if ((error = acl_get_tag_type(entry, &tag_type)) != 0) {
+ /* errno is set by acl_get_tag_type */
+ } else {
+ switch(tag_type) {
+ case ACL_EXTENDED_ALLOW:
+ case ACL_EXTENDED_DENY:
+ if ((result = malloc(sizeof(guid_t))) != NULL)
+ bcopy(&entry->ae_applicable, result, sizeof(guid_t));
+ break;
+ default:
+ errno = EINVAL;
+ break;
+ }
+ }
+ return(result);
+}
+
+int
+acl_get_tag_type(acl_entry_t entry, acl_tag_t *tag_type_p)
+{
+ _ACL_VALIDATE_ENTRY(entry);
+
+ *tag_type_p = entry->ae_tag;
+ return(0);
+}
+
+int
+acl_set_qualifier(acl_entry_t entry, const void *tag_qualifier_p)
+{
+ acl_tag_t tag_type;
+ int error;
+
+ _ACL_VALIDATE_ENTRY(entry);
+ if ((error = acl_get_tag_type(entry, &tag_type)) != 0)
+ return(error);
+
+ switch(tag_type) {
+ case ACL_EXTENDED_ALLOW:
+ case ACL_EXTENDED_DENY:
+ bcopy(tag_qualifier_p, &entry->ae_applicable, sizeof(guid_t));
+ error = 0;
+ break;
+ default:
+ error = EINVAL;
+ }
+ return(error);
+}
+
+int
+acl_set_tag_type(acl_entry_t entry, acl_tag_t tag_type)
+{
+ _ACL_VALIDATE_ENTRY(entry);
+
+ switch(tag_type) {
+ case ACL_EXTENDED_ALLOW:
+ case ACL_EXTENDED_DENY:
+ entry->ae_tag = tag_type;
+ break;
+ default:
+ return(EINVAL);
+ }
+ return(0);
+}
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/* XXX temporary implementation using __acl__ file */
+
+#include <sys/appleapiopts.h>
+#include <sys/types.h>
+#include <sys/acl.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "aclvar.h"
+
+static acl_t acl_get_file1(const char *path, acl_type_t acl_type, int follow);
+static int acl_set_file1(const char *path, acl_type_t acl_type, acl_t acl, int follow);
+
+int
+acl_delete_fd_np(int filedes, acl_type_t type)
+{
+ errno = ENOTSUP;
+ return(-1);
+}
+
+int
+acl_delete_file_np(const char *path, acl_type_t type)
+{
+ errno = ENOTSUP;
+ return(-1);
+}
+
+int
+acl_delete_link_np(const char *path, acl_type_t type)
+{
+ errno = ENOTSUP;
+ return(-1);
+}
+
+acl_t
+acl_get_fd(int fd)
+{
+ return(acl_get_fd_np(fd, ACL_TYPE_EXTENDED));
+}
+
+acl_t
+acl_get_fd_np(int fd, acl_type_t type)
+{
+ filesec_t fsec;
+ acl_t acl;
+ struct stat sb;
+
+ if ((fsec = filesec_init()) == NULL)
+ return(NULL);
+
+ acl = NULL;
+ if (fstatx_np(fd, &sb, fsec) == 0)
+ filesec_get_property(fsec, FILESEC_ACL, &acl);
+ filesec_free(fsec);
+ return(acl);
+}
+
+static acl_t
+acl_get_file1(const char *path, acl_type_t acl_type, int follow)
+{
+ filesec_t fsec;
+ acl_t acl;
+ struct stat sb;
+
+ if ((fsec = filesec_init()) == NULL)
+ return(NULL);
+
+ acl = NULL;
+ if ((follow ? statx_np(path, &sb, fsec) : lstatx_np(path, &sb, fsec)) == 0)
+ filesec_get_property(fsec, FILESEC_ACL, &acl);
+ filesec_free(fsec);
+ return(acl);
+}
+
+acl_t
+acl_get_file(const char *path, acl_type_t type)
+{
+ return(acl_get_file1(path, type, 1 /* follow */));
+}
+
+acl_t
+acl_get_link_np(const char *path, acl_type_t type)
+{
+ return(acl_get_file1(path, type, 0 /* no follow */));
+}
+
+int
+acl_set_fd_np(int fd, acl_t acl, acl_type_t type)
+{
+ filesec_t fsec;
+ int error;
+
+ if ((fsec = filesec_init()) == NULL)
+ return(-1);
+ if ((filesec_set_property(fsec, FILESEC_ACL, &acl)) != 0) {
+ filesec_free(fsec);
+ return(-1);
+ }
+ error = fchmodx_np(fd, fsec);
+ filesec_free(fsec);
+ return((error == 0) ? 0 : -1);
+}
+
+int
+acl_set_fd(int fd, acl_t acl)
+{
+ return(acl_set_fd_np(fd, acl, ACL_TYPE_EXTENDED));
+}
+
+static int
+acl_set_file1(const char *path, acl_type_t acl_type, acl_t acl, int follow)
+{
+ filesec_t fsec;
+ int error;
+
+ if (follow == 0) { /* XXX this requires some thought - can links have ACLs? */
+ errno = ENOTSUP;
+ return(-1);
+ }
+
+ if ((fsec = filesec_init()) == NULL)
+ return(-1);
+ if (filesec_set_property(fsec, FILESEC_ACL, &acl) != 0) {
+ filesec_free(fsec);
+ return(-1);
+ }
+ error = chmodx_np(path, fsec);
+ filesec_free(fsec);
+ return((error == 0) ? 0 : -1);
+}
+
+int
+acl_set_file(const char *path, acl_type_t acl_type, acl_t acl)
+{
+ return(acl_set_file1(path, acl_type, acl, 1));
+}
+
+int
+acl_set_link_np(const char *path, acl_type_t acl_type, acl_t acl)
+{
+ return(acl_set_file1(path, acl_type, acl, 0));
+}
+
+/*
+ * Not applicable; not supported.
+ */
+int
+acl_delete_def_file(__unused const char *path)
+{
+ errno = ENOTSUP;
+ return(-1);
+}
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include <sys/appleapiopts.h>
+#include <sys/types.h>
+#include <sys/acl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "aclvar.h"
+
+int
+acl_add_flag_np(acl_flagset_t flags, acl_flag_t flag)
+{
+ /* XXX validate flags */
+ /* XXX validate flag */
+
+ flags->af_flags |= flag;
+ return(0);
+}
+
+int
+acl_clear_flags_np(acl_flagset_t flags)
+{
+ /* XXX validate flags */
+
+ flags->af_flags = 0;
+ return(0);
+}
+
+int
+acl_delete_flag_np(acl_flagset_t flags, acl_flag_t flag)
+{
+ /* XXX validate flags */
+ /* XXX validate flag */
+
+ flags->af_flags &= ~flag;
+ return(0);
+}
+
+int
+acl_get_flag_np(acl_flagset_t flagset, acl_flag_t flag)
+{
+ /* XXX validate flags */
+ /* XXX validate flag */
+
+ return((flag & flagset->af_flags) ? 1 : 0);
+}
+
+int
+acl_get_flagset_np(void *obj, acl_flagset_t *flagset_p)
+{
+ struct _acl *ap = (struct _acl *)obj;
+ struct _acl_entry *ep = (struct _acl_entry *)obj;
+
+ if (_ACL_VALID_ACL(ap)) {
+ *flagset_p = (acl_flagset_t)&ap->a_flags;
+ } else if (_ACL_VALID_ENTRY(ep)) {
+ *flagset_p = (acl_flagset_t)&ep->ae_flags;
+ } else {
+ errno = EINVAL;
+ return(-1);
+ }
+ return(0);
+}
+
+int
+acl_set_flagset_np(void *obj, acl_flagset_t flagset)
+{
+ struct _acl *ap = (struct _acl *)obj;
+ struct _acl_entry *ep = (struct _acl_entry *)obj;
+
+ if (_ACL_VALID_ACL(ap)) {
+ ap->a_flags = flagset->af_flags;
+ } else if (_ACL_VALID_ENTRY(ep)) {
+ ep->ae_flags = flagset->af_flags;
+ } else {
+ errno = EINVAL;
+ return(-1);
+ }
+
+ return(0);
+}
--- /dev/null
+.\"-
+.\" Copyright (c) 2000, 2002 Robert N. M. Watson
+.\" All rights reserved.
+.\"
+.\" This software was developed by Robert Watson for the TrustedBSD Project.
+.\"
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_free.3,v 1.12 2002/12/29 20:52:42 rwatson Exp $
+.\"
+.Dd January 28, 2000
+.Dt ACL_FREE 3
+.Os
+.Sh NAME
+.Nm acl_free
+.Nd free ACL working state
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_free "void *obj_p"
+.Sh DESCRIPTION
+The
+.Fn acl_free
+call allows the freeing of ACL working space, such as is allocated by
+.Xr acl_dup 3 ,
+or
+.Xr acl_from_text 3 .
+.Sh RETURN VALUES
+.Rv -std acl_free
+.Sh ERRORS
+If any of the following conditions occur, the
+.Fn acl_free
+function shall return -1 and set
+.Va errno
+to the corresponding value:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The value of the
+.Va obj_p
+argument is invalid.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_dup 3 ,
+.Xr acl_from_text 3 ,
+.Xr acl_get 3 ,
+.Xr acl_init 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Robert N M Watson
--- /dev/null
+.\"-
+.\" Copyright (c) 2000, 2002 Robert N. M. Watson
+.\" All rights reserved.
+.\"
+.\" This software was developed by Robert Watson for the TrustedBSD Project.
+.\"
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_from_text.3,v 1.15 2002/12/29 20:52:42 rwatson Exp $
+.\"
+.Dd January 28, 2000
+.Dt ACL_FROM_TEXT 3
+.Os
+.Sh NAME
+.Nm acl_from_text
+.Nd create an ACL from text
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft acl_t
+.Fn acl_from_text "const char *buf_p"
+.Sh DESCRIPTION
+The
+.Fn acl_from_text
+function converts the text form of an ACL referred to by
+.Va buf_p
+into the internal working structure for ACLs, appropriate for applying to
+files or manipulating.
+.Pp
+This function may cause memory to be allocated. The caller should free any
+releasable memory, when the new ACL is no longer required, by calling
+.Xr acl_free 3
+with the
+.Va (void *)acl_t
+as an argument.
+.Sh IMPLEMENTATION NOTES
+The ACL_TYPE_EXTENDE text format differs from the POSIX.1e format, and this
+function will not translate between formats.
+.Sh RETURN VALUES
+Upon successful completion, the function shall return a pointer to the
+internal representation of the ACL in working storage. Otherwise, a value
+of
+.Va (acl_t)NULL
+shall be returned, and
+.Va errno
+shall be set to indicate the error.
+.Sh ERRORS
+If any of the following conditions occur, the
+.Fn acl_from_text
+function shall return a value of
+.Va (acl_t)NULL
+and set
+.Va errno
+to the corresponding value:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Va buf_p
+cannot be translated into an ACL.
+.It Bq Er ENOMEM
+The ACL working storage requires more memory than is allowed by the
+hardware or system-imposed memory management constraints.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_free 3 ,
+.Xr acl_get 3 ,
+.Xr acl_to_text 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Robert N M Watson
--- /dev/null
+.\"-
+.\" Copyright (c) 2000, 2002 Robert N. M. Watson
+.\" All rights reserved.
+.\"
+.\" This software was developed by Robert Watson for the TrustedBSD Project.
+.\"
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_get.3,v 1.17 2003/02/23 01:43:45 ru Exp $
+.\"
+.Dd December 29, 2002
+.Dt ACL_GET 3
+.Os
+.Sh NAME
+.Nm acl_get_fd ,
+.Nm acl_get_fd_np ,
+.Nm acl_get_file ,
+.Nm acl_get_link_np
+.Nd get an ACL for a file
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft acl_t
+.Fn acl_get_fd "int fd"
+.Ft acl_t
+.Fn acl_get_fd_np "int fd" "acl_type_t type"
+.Ft acl_t
+.Fn acl_get_file "const char *path_p" "acl_type_t type"
+.Ft acl_t
+.Fn acl_get_link_np "const char *path_p" "acl_type_t type"
+.Sh DESCRIPTION
+The
+.Fn acl_get_fd ,
+.Fn acl_get_file ,
+.Fn acl_get_link_np ,
+and
+.Fn acl_get_fd_np
+each allow the retrieval of an ACL from a file.
+The
+.Fn acl_get_fd
+is a POSIX.1e call that allows the retrieval of an ACL of type
+ACL_TYPE_ACCESS
+from a file descriptor.
+The
+.Fn acl_get_fd_np
+function
+is a non-portable form of
+.Fn acl_get_fd
+that allows the retrieval of any type of ACL from a file descriptor.
+The
+.Fn acl_get_file
+function is a POSIX.1e call that allows the retrieval of a
+specified type of ACL from a file by name;
+.Fn acl_get_link_np
+is a non-portable variation on
+.Fn acl_get_file
+which does not follow a symlink if the target of the call is a
+symlink.
+.Pp
+These functions may cause memory to be allocated. The caller should free
+any releasable memory, when the new ACL is no longer required, by calling
+.Xr acl_free 3
+with the
+.Va (void *)acl_t
+as an argument.
+.Pp
+The ACL in the working storage is an independent copy of the ACL associated
+with the object referred to by
+.Va fd .
+The ACL in the working storage shall not participate in any access control
+decisions.
+.Sh RETURN VALUES
+Upon successful completion, the function shall return a pointer to the ACL
+that was retrieved. Otherwise, a value of
+.Va (acl_t)NULL
+shall be returned, and
+.Va errno
+shall be set to indicate the error.
+.Sh ERRORS
+If any of the following conditions occur, the
+.Fn acl_get_fd
+function shall return a value of
+.Va (acl_t)NULL
+and set
+.Va errno
+to the corresponding value:
+.Bl -tag -width Er
+.It Bq Er EACCES
+Search permission is denied for a component of the path prefix, or the
+object exists and the process does not have appropriate access rights.
+.It Bq Er EBADF
+The
+.Va fd
+argument is not a valid file descriptor.
+.It Bq Er EINVAL
+The ACL type passed is invalid for this file object.
+.It Bq Er ENAMETOOLONG
+A component of a pathname exceeded 255 characters, or an
+entire path name exceeded 1023 characters.
+.It Bq Er ENOENT
+The named object does not exist, or the
+.Va path_p
+argument points to an empty string.
+.It Bq Er ENOMEM
+Insufficient memory available to fulfill request.
+.It Bq Er EOPNOTSUPP
+The file system does not support ACL retrieval.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_free 3 ,
+.Xr acl_get 3 ,
+.Xr acl_set 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Robert N M Watson
--- /dev/null
+.\"-
+.\" Copyright (c) 2001 Chris D. Faulhaber
+.\" 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 THE VOICES IN HIS HEAD 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_get_entry.3,v 1.6 2002/12/18 12:45:09 ru Exp $
+.\"
+.Dd April 13, 2001
+.Dt ACL_GET_ENTRY 3
+.Os
+.Sh NAME
+.Nm acl_get_entry
+.Nd retrieve an ACL entry from an ACL
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_get_entry "acl_t acl" "int entry_id" "acl_entry_t *entry_p"
+.Sh DESCRIPTION
+The
+.Fn acl_get_entry
+function
+is a POSIX.1e call that retrieves a descriptor for an ACL entry
+specified by the argument
+.Fa entry_d
+within the ACL indicated by the argument
+.Fa acl .
+.Pp
+If the value of
+.Fa entry_id
+is
+.Dv ACL_FIRST_ENTRY ,
+then the function will return in
+.Fa entry_p
+a descriptor for the first ACL entry within
+.Fa acl .
+If a call is made to
+.Fn acl_get_entry
+with
+.Fa entry_id
+set to
+.Dv ACL_NEXT_ENTRY
+when there has not been either an initial successful call to
+.Fn acl_get_entry ,
+or a previous successfull call to
+.Fn acl_create_entry ,
+.Fn acl_delete_entry ,
+.Fn acl_dup ,
+.Fn acl_from_text ,
+.Fn acl_get_fd ,
+.Fn acl_get_file ,
+.Fn acl_set_fd ,
+.Fn acl_set_file ,
+or
+.Fn acl_valid ,
+then the result is unspecified.
+.Pp
+The caller may also set
+.Fa entry_id
+to the index of the desired entry within the ACL. This is a non-portable
+extension. A subsequent call with
+.Fa entry_id
+set to
+.Dv ACL_NEXT_ENTRY
+will return the entry following the previously nominated entry and so forth.
+.Sh RETURN VALUES
+If the
+.Fn acl_get_entry
+function successfully obtains an ACL entry, a value of 1 is returned.
+If the ACL has no ACL entries, the
+.Fn acl_get_entry
+returns a value of 0. If the value of
+.Fa entry_id
+is
+.Dv ACL_NEXT_ENTRY
+and the last ACL entry in the ACL has already been returned by a
+previous call to
+.Fn acl_get_entry ,
+a value of 0 will be returned until a successful call with
+.Fa entry_id
+of
+.Dv ACL_FIRST_ENTRY
+is made. Otherwise, a value of -1 will be returned and
+the global variable
+.Va errno
+will be set to indicate the error.
+.Sh ERRORS
+The
+.Fn acl_get_entry
+fails if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Fa acl
+does not point to a valid ACL. Argument
+.Fa entry_id
+is neither
+.Dv ACL_FIRST_ENTRY ,
+.Dv ACL_NEXT_ENTRY
+or a valid entry index.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_calc_mask 3 ,
+.Xr acl_create_entry 3 ,
+.Xr acl_delete_entry 3 ,
+.Xr acl_dup 3 ,
+.Xr acl_from_text 3 ,
+.Xr acl_get_fd 3 ,
+.Xr acl_get_file 3 ,
+.Xr acl_init 3 ,
+.Xr acl_set_fd 3 ,
+.Xr acl_set_file 3 ,
+.Xr acl_valid 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Chris D. Faulhaber
--- /dev/null
+.\"-
+.\" Copyright (c) 2000, 2002 Robert N. M. Watson
+.\" All rights reserved.
+.\"
+.\" This software was developed by Robert Watson for the TrustedBSD Project.
+.\"
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_get.3,v 1.17 2003/02/23 01:43:45 ru Exp $
+.\"
+.Dd December 29, 2002
+.Dt ACL_GET 3
+.Os
+.Sh NAME
+.Nm acl_get_fd ,
+.Nm acl_get_fd_np ,
+.Nm acl_get_file ,
+.Nm acl_get_link_np
+.Nd get an ACL for a file
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft acl_t
+.Fn acl_get_fd "int fd"
+.Ft acl_t
+.Fn acl_get_fd_np "int fd" "acl_type_t type"
+.Ft acl_t
+.Fn acl_get_file "const char *path_p" "acl_type_t type"
+.Ft acl_t
+.Fn acl_get_link_np "const char *path_p" "acl_type_t type"
+.Sh DESCRIPTION
+The
+.Fn acl_get_fd ,
+.Fn acl_get_file ,
+.Fn acl_get_link_np ,
+and
+.Fn acl_get_fd_np
+each allow the retrieval of an ACL from a file.
+The
+.Fn acl_get_fd
+is a POSIX.1e call that allows the retrieval of an ACL of type
+ACL_TYPE_ACCESS
+from a file descriptor.
+The
+.Fn acl_get_fd_np
+function
+is a non-portable form of
+.Fn acl_get_fd
+that allows the retrieval of any type of ACL from a file descriptor.
+The
+.Fn acl_get_file
+function is a POSIX.1e call that allows the retrieval of a
+specified type of ACL from a file by name;
+.Fn acl_get_link_np
+is a non-portable variation on
+.Fn acl_get_file
+which does not follow a symlink if the target of the call is a
+symlink.
+.Pp
+These functions may cause memory to be allocated. The caller should free
+any releasable memory, when the new ACL is no longer required, by calling
+.Xr acl_free 3
+with the
+.Va (void *)acl_t
+as an argument.
+.Pp
+The ACL in the working storage is an independent copy of the ACL associated
+with the object referred to by
+.Va fd .
+The ACL in the working storage shall not participate in any access control
+decisions.
+.Sh RETURN VALUES
+Upon successful completion, the function shall return a pointer to the ACL
+that was retrieved. Otherwise, a value of
+.Va (acl_t)NULL
+shall be returned, and
+.Va errno
+shall be set to indicate the error.
+.Sh ERRORS
+If any of the following conditions occur, the
+.Fn acl_get_fd
+function shall return a value of
+.Va (acl_t)NULL
+and set
+.Va errno
+to the corresponding value:
+.Bl -tag -width Er
+.It Bq Er EACCES
+Search permission is denied for a component of the path prefix, or the
+object exists and the process does not have appropriate access rights.
+.It Bq Er EBADF
+The
+.Va fd
+argument is not a valid file descriptor.
+.It Bq Er EINVAL
+The ACL type passed is invalid for this file object.
+.It Bq Er ENAMETOOLONG
+A component of a pathname exceeded 255 characters, or an
+entire path name exceeded 1023 characters.
+.It Bq Er ENOENT
+The named object does not exist, or the
+.Va path_p
+argument points to an empty string.
+.It Bq Er ENOMEM
+Insufficient memory available to fulfill request.
+.It Bq Er EOPNOTSUPP
+The file system does not support ACL retrieval.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_free 3 ,
+.Xr acl_get 3 ,
+.Xr acl_set 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+and development continues.
+.Sh AUTHORS
+.An Michael Smith
+.An Robert N M Watson
--- /dev/null
+.\"-
+.\" Copyright (c) 2001 Chris D. Faulhaber
+.\" 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 THE VOICES IN HIS HEAD 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_get_permset.3,v 1.5 2002/12/18 12:45:09 ru Exp $
+.\"
+.Dd March 10, 2001
+.Dt ACL_GET_FLAGSET_NP 3
+.Os
+.Sh NAME
+.Nm acl_get_flagset_np
+.Nd retrieve flag set from an ACL or ACL entry
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_get_flagset_np "void *obj" "acl_flagset_t *flagset_p"
+.Sh DESCRIPTION
+The
+.Fn acl_get_flagset_np
+function
+is a nonstandard extension that returns via
+.Fa flagset_p
+a descriptor to the flag set in the ACL or ACL entry
+.Fa obj .
+Subsequent operations using the returned flag set operate
+on the permission set within the ACL or ACL entry.
+.Sh RETURN VALUES
+.Rv -std acl_get_flagset
+.Sh ERRORS
+The
+.Fn acl_get_flagset
+function fails if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Fa obj
+is not a valid descriptor for an ACL or ACL entry.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_add_flag 3 ,
+.Xr acl_clear_flagss 3 ,
+.Xr acl_delete_flag 3 ,
+.Xr acl_set_flagset 3 ,
+.Sh AUTHORS
+.An Michael Smith
+.An Chris D. Faulhaber
--- /dev/null
+.\"-
+.\" Copyright (c) 2001 Chris D. Faulhaber
+.\" 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 THE VOICES IN HIS HEAD 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_get_perm_np.3,v 1.4 2002/12/18 12:45:09 ru Exp $
+.\"
+.Dd April 10, 2001
+.Dt ACL_GET_PERM_NP 3
+.Os
+.Sh NAME
+.Nm acl_get_perm_np
+.Nd "check if a permission is set in a permission set"
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_get_perm_np "acl_permset_t permset_d" "acl_perm_t perm"
+.Sh DESCRIPTION
+The
+.Fn acl_get_perm_np
+function
+is a non-portable function that checks if a permission is set in
+a permission set.
+.Sh RETURN VALUES
+If the permission in
+.Fa perm
+is set in the permission set
+.Fa permset_d ,
+a value of
+1
+is returned, otherwise a value of
+0
+is returned.
+.Sh ERRORS
+If any of the following conditions occur, the
+.Fn acl_get_perm_np
+function will return a value of
+\-1
+and set global variable
+.Va errno
+to the corresponding value:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Fa perm
+does not contain a valid ACL permission or argument
+.Fa permset_d
+is not a valid ACL permset.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_add_perm 3 ,
+.Xr acl_clear_perms 3 ,
+.Xr acl_delete_perm 3 ,
+.Xr acl_get_permset 3 ,
+.Xr acl_set_permset 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Chris D. Faulhaber
--- /dev/null
+.\"-
+.\" Copyright (c) 2001 Chris D. Faulhaber
+.\" 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 THE VOICES IN HIS HEAD 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_get_permset.3,v 1.5 2002/12/18 12:45:09 ru Exp $
+.\"
+.Dd March 10, 2001
+.Dt ACL_GET_PERMSET 3
+.Os
+.Sh NAME
+.Nm acl_get_permset
+.Nd retrieve permission set from an ACL entry
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_get_permset "acl_entry_t entry_d" "acl_permset_t *permset_p"
+.Sh DESCRIPTION
+The
+.Fn acl_get_permset
+function
+is a POSIX.1e call that returns via
+.Fa permset_p
+a descriptor to the permission set in the ACL entry
+.Fa entry_d .
+Subsequent operations using the returned permission set operate
+on the permission set within the ACL entry.
+.Sh RETURN VALUES
+.Rv -std acl_get_permset
+.Sh ERRORS
+The
+.Fn acl_get_permset
+function fails if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Fa entry_d
+is not a valid descriptor for an ACL entry.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_add_perm 3 ,
+.Xr acl_clear_perms 3 ,
+.Xr acl_delete_perm 3 ,
+.Xr acl_set_permset 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Chris D. Faulhaber
--- /dev/null
+.\"-
+.\" Copyright (c) 2001 Chris D. Faulhaber
+.\" 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 THE VOICES IN HIS HEAD 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_get_qualifier.3,v 1.6 2002/12/27 12:15:28 schweikh Exp $
+.\"
+.Dd March 13, 2001
+.Dt ACL_GET_QUALIFIER 3
+.Os
+.Sh NAME
+.Nm acl_get_qualifier
+.Nd retrieve the qualifier from an ACL entry
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft void *
+.Fn acl_get_qualifier "acl_entry_t entry_d"
+.Sh DESCRIPTION
+The
+.Fn acl_get_qualifier
+function
+is a POSIX.1e call that retrieves the qualifier of the tag for
+the ACL entry indicated by the argument
+.Fa entry_d
+into working storage and returns a pointer to that storage.
+.Pp
+If the value of the tag type in the ACL entry referred to by
+.Fa entry_d
+is
+.Dv ACL_EXTENDED_ALLOW
+or
+.Dv ACL_EXTENDED_DENY
+The value returned by
+.Fn acl_get_qualifier
+will be a pointer to type
+.Vt guid_t .
+.Pp
+If the value of the tag type in the ACL entry referred to by
+.Fa entry_d
+is
+.Dv ACL_UNDEFINED_TAG ,
+a tag type specified by POSIX.1e but not supported
+or an implementation-defined value for which a qualifier
+is not supported, then
+.Fn acl_get_qualifier
+will return a value of
+.Vt ( void * ) Ns Dv NULL
+and the function will fail.
+.Pp
+This function may cause memory to be allocated. The caller should
+free any releasable memory, when the new qualifier is no longer
+required, by calling
+.Fn acl_free
+with
+.Vt void *
+as the argument.
+.Sh RETURN VALUES
+The
+.Fn acl_get_qualifier
+function returns a pointer to the allocated storage if successful;
+otherwise a
+.Dv NULL
+pointer is returned and the global variable
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+The
+.Fn acl_get_qualifier
+fails if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Fa entry_d
+does not point to a valid descriptor for an ACL entry. The
+value of the tag type in the ACL entry referenced by argument
+.Fa entry_d
+is not
+.Dv ACL_EXTENDED_ALLOW
+or
+.Dv ACL_EXTENDED_DENY .
+.It Bq Er ENOMEM
+The value to be returned requires more memory than is allowed
+by the hardware or system-imposed memory management constraints.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_create_entry 3 ,
+.Xr acl_free 3 ,
+.Xr acl_get_entry 3 ,
+.Xr acl_get_tag_type 3 ,
+.Xr acl_set_qualifier 3 ,
+.Xr acl_set_tag_type 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Chris D. Faulhaber
--- /dev/null
+.\"-
+.\" Copyright (c) 2001 Chris D. Faulhaber
+.\" 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 THE VOICES IN HIS HEAD 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_get_tag_type.3,v 1.7 2002/12/27 12:15:28 schweikh Exp $
+.\"
+.Dd March 10, 2001
+.Dt ACL_GET_TAG_TYPE 3
+.Os
+.Sh NAME
+.Nm acl_get_tag_type
+.Nd retrieve the tag type from an ACL entry
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_get_tag_type "acl_entry_t entry_d" "acl_tag_t *tag_type_p"
+.Sh DESCRIPTION
+The
+.Fn acl_get_tag_type
+function
+is a POSIX.1e call that returns the tag type for the ACL entry
+.Fa entry_d .
+Upon successful completion, the location referred to by the argument
+.Fa tag_type_p
+will be set to the tag type of the ACL entry
+.Fa entry_d .
+.Sh RETURN VALUES
+.Rv -std acl_get_tag_type
+.Sh ERRORS
+The
+.Fn acl_get_tag_type
+function fails if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Fa entry_d
+is not a valid descriptor for an ACL entry;
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_create_entry 3 ,
+.Xr acl_get_entry 3 ,
+.Xr acl_get_qualifier 3 ,
+.Xr acl_init 3 ,
+.Xr acl_set_qualifier 3 ,
+.Xr acl_set_tag_type 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Chris D. Faulhaber
--- /dev/null
+.\"-
+.\" Copyright (c) 2000, 2002 Robert N. M. Watson
+.\" All rights reserved.
+.\"
+.\" This software was developed by Robert Watson for the TrustedBSD Project.
+.\"
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_init.3,v 1.13 2002/12/29 20:52:42 rwatson Exp $
+.\"
+.Dd January 28, 2000
+.Dt ACL_INIT 3
+.Os
+.Sh NAME
+.Nm acl_init
+.Nd initialize ACL working storage
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft acl_t
+.Fn acl_init "int count"
+.Sh DESCRIPTION
+The
+.Fn acl_init
+function allocates and initializes the working storage for an ACL of at
+least
+.Va count
+ACL entries. A pointer to the working storage is returned. The working
+storage allocated to contain the ACL is freed by a call to
+.Xr acl_free 3 .
+When the area is first allocated, it shall contain an ACL that contains
+no ACL entries.
+.Pp
+This function may cause memory to be allocated. The caller should free any
+releasable memory, when the new ACL is no longer required, by calling
+.Xr acl_free 3
+with the
+.Va (void*)acl_t
+as an argument.
+.Sh RETURN VALUES
+Upon successful completion, this function shall return a pointer to the
+working storage. Otherwise, a value of
+.Va (acl_t)NULL
+shall be returned, and
+.Va errno
+shall be set to indicate the error.
+.Sh ERRORS
+If any of the following conditions occur, the
+.Fn acl_init
+function shall return a value of
+.Va (acl_t)NULL
+and set
+.Va errno
+to the corresponding value:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The value of count is less than zero.
+.It Bq Er ENOMEM
+The
+.Va acl_t
+to be returned requires more memory than is allowed by the hardware or
+system-imposed memory management constraints.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_free 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Robert N M Watson
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include <sys/appleapiopts.h>
+#include <sys/types.h>
+#include <sys/acl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "aclvar.h"
+
+int
+acl_add_perm(acl_permset_t permset, acl_perm_t perm)
+{
+ /* XXX validate perms */
+ _ACL_VALIDATE_PERM(perm);
+
+ permset->ap_perms |= perm;
+ return(0);
+}
+
+int
+acl_clear_perms(acl_permset_t permset)
+{
+ /* XXX validate perms */
+
+ permset->ap_perms = 0;
+ return(0);
+}
+
+int
+acl_delete_perm(acl_permset_t permset, acl_perm_t perm)
+{
+ /* XXX validate perms */
+ _ACL_VALIDATE_PERM(perm);
+
+ permset->ap_perms &= ~perm;
+ return(0);
+}
+
+int
+acl_get_perm_np(acl_permset_t permset, acl_perm_t perm)
+{
+ _ACL_VALIDATE_PERM(perm);
+
+ return((perm & permset->ap_perms) ? 1 : 0);
+}
+
+int
+acl_get_permset(acl_entry_t entry, acl_permset_t *permset_p)
+{
+ _ACL_VALIDATE_ENTRY(entry);
+
+ *permset_p = (acl_permset_t)&entry->ae_perms;
+ return(0);
+}
+
+int
+acl_set_permset(acl_entry_t entry, acl_permset_t permset)
+{
+ _ACL_VALIDATE_ENTRY(entry);
+
+ entry->ae_perms = permset->ap_perms;
+ return(0);
+}
--- /dev/null
+.\"-
+.\" Copyright (c) 2000, 2002 Robert N. M. Watson
+.\" All rights reserved.
+.\"
+.\" This software was developed by Robert Watson for the TrustedBSD Project.
+.\"
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_set.3,v 1.16 2003/02/23 01:44:59 ru Exp $
+.\"
+.Dd December 29, 2002
+.Dt ACL_SET 3
+.Os
+.Sh NAME
+.Nm acl_set_fd ,
+.Nm acl_set_fd_np ,
+.Nm acl_set_file ,
+.Nm acl_set_link_np
+.Nd set an ACL for a file
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_set_fd "int fd" "acl_t acl"
+.Ft int
+.Fn acl_set_fd_np "int fd" "acl_t acl" "acl_type_t type"
+.Ft int
+.Fn acl_set_file "const char *path_p" "acl_type_t type" "acl_t acl"
+.Ft int
+.Fn acl_set_link_np "const char *path_p" "acl_type_t type" "acl_t acl"
+.Sh DESCRIPTION
+The
+.Fn acl_set_fd ,
+.Fn acl_set_fd_np ,
+.Fn acl_set_file ,
+and
+.Fn acl_set_link_np
+each associate an ACL with an object referred to by
+.Va fd
+or
+.Va path_p .
+The
+.Fn acl_set_fd_np
+and
+.Fn acl_set_link_np
+functions are not POSIX.1e calls.
+The
+.Fn acl_set_fd
+function allows only the setting of ACLs of type ACL_TYPE_EXTENDED
+where as
+.Fn acl_set_fd_np
+allows the setting of ACLs of any type.
+The
+.Fn acl_set_link_np
+function acts on a symlink rather than its target, if the target of the
+path is a symlink.
+.Sh RETURN VALUES
+.Rv -std
+.Sh ERRORS
+If any of the following conditions occur, these functions shall return
+-1 and set
+.Va errno
+to the corresponding value:
+.Bl -tag -width Er
+.It Bq Er EACCES
+Search permission is denied for a component of the path prefix, or the
+object exists and the process does not have appropriate access rights.
+.It Bq Er EBADF
+The
+.Va fd
+argument is not a valid file descriptor.
+.It Bq Er EINVAL
+Argument
+.Va acl
+does not point to a valid ACL for this object, or the ACL type
+specified in
+.Va type
+is invalid for this object, or both.
+.It Bq Er ENAMETOOLONG
+A component of a pathname exceeded 255 characters, or an
+entire path name exceeded 1023 characters.
+.It Bq Er ENOENT
+The named object does not exist, or the
+.Va path_p
+argument points to an empty string.
+.It Bq Er ENOMEM
+Insufficient memory available to fulfill request.
+.It Bq Er ENOSPC
+The directory or file system that would contain the new ACL cannot be
+extended, or the file system is out of file allocation resources.
+.It Bq Er EOPNOTSUPP
+The file system does not support ACL retrieval.
+.It Bq Er EROFS
+This function requires modification of a file system which is currently
+read-only.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_delete 3 ,
+.Xr acl_get 3 ,
+.Xr acl_valid 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Robert N M Watson
--- /dev/null
+.\"-
+.\" Copyright (c) 2001 Chris D. Faulhaber
+.\" 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 THE VOICES IN HIS HEAD 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_set_permset.3,v 1.6 2002/12/18 12:45:09 ru Exp $
+.\"
+.Dd March 10, 2001
+.Dt ACL_SET_FLAGSET 3
+.Os
+.Sh NAME
+.Nm acl_set_flagset
+.Nd set the flags of an ACL or ACL entry
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_set_flagset "void *obj" "acl_flagset_t flagset_d"
+.Sh DESCRIPTION
+The
+.Fn acl_set_flagset
+function
+is a nonstandard extension that sets the permissions of the ACL or ACL entry
+.Fa obj
+with the flags contained in
+.Fa flagset_d .
+.Sh RETURN VALUES
+.Rv -std acl_set_flagset
+.Sh ERRORS
+The
+.Fn acl_set_flagset
+function fails if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Fa obj
+is not a valid descriptor for an ACL or ACL entry. Argument
+.Fa flagset_d
+is not a valid flagset for
+.Fa obj .
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_add_flag 3 ,
+.Xr acl_clear_flags 3 ,
+.Xr acl_delete_flag 3 ,
+.Xr acl_get_flagset 3 ,
+.Sh AUTHORS
+.An Michael Smith
+.An Chris D. Faulhaber
--- /dev/null
+.\"-
+.\" Copyright (c) 2001 Chris D. Faulhaber
+.\" 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 THE VOICES IN HIS HEAD 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_set_permset.3,v 1.6 2002/12/18 12:45:09 ru Exp $
+.\"
+.Dd March 10, 2001
+.Dt ACL_SET_PERMSET 3
+.Os
+.Sh NAME
+.Nm acl_set_permset
+.Nd set the permissions of an ACL entry
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_set_permset "acl_entry_t entry_d" "acl_permset_t permset_d"
+.Sh DESCRIPTION
+The
+.Fn acl_set_permset
+function
+is a POSIX.1e call that sets the permissions of ACL entry
+.Fa entry_d
+with the permissions contained in
+.Fa permset_d .
+.Sh RETURN VALUES
+.Rv -std acl_set_permset
+.Sh ERRORS
+The
+.Fn acl_set_permset
+function fails if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Fa entry_d
+is not a valid descriptor for an ACL entry.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_add_perm 3 ,
+.Xr acl_clear_perms 3 ,
+.Xr acl_delete_perm 3 ,
+.Xr acl_get_permset 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Chris D. Faulhaber
--- /dev/null
+.\"-
+.\" Copyright (c) 2001 Chris D. Faulhaber
+.\" 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 THE VOICES IN HIS HEAD 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_set_qualifier.3,v 1.5 2002/12/18 12:45:09 ru Exp $
+.\"
+.Dd March 10, 2001
+.Dt ACL_SET_QUALIFIER 3
+.Os
+.Sh NAME
+.Nm acl_set_qualifier
+.Nd set ACL tag qualifier
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_set_qualifier "acl_entry_t entry_d" "const void *tag_qualifier_p"
+.Sh DESCRIPTION
+The
+.Fn acl_set_qualifier
+function
+is a POSIX.1e call that sets the qualifier of the tag for the ACL entry
+.Fa entry_d
+to the value referred to by
+.Fa tag_qualifier_p .
+.Sh RETURN VALUES
+.Rv -std acl_set_qualifier
+.Sh ERRORS
+The
+.Fn acl_set_qualifier
+function fails if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Fa entry_d
+is not a valid descriptor for an ACL entry. The tag type of the
+ACL entry
+.Fa entry_d
+is not
+.Dv ACL_EXTENDED_ALLOW
+or
+.Dv ACL_EXTENDED_DENY .
+The value pointed to by
+.Fa tag_qualifier_p
+is not valid.
+.It Bq Er ENOMEM
+The value to be returned requires more memory than is allowed
+by the hardware or system-imposed memory management constraints.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_get_qualifier 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Chris D. Faulhaber
--- /dev/null
+.\"-
+.\" Copyright (c) 2001 Chris D. Faulhaber
+.\" 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 THE VOICES IN HIS HEAD 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_set_tag_type.3,v 1.6 2002/12/18 12:45:09 ru Exp $
+.\"
+.Dd March 10, 2001
+.Dt ACL_SET_TAG_TYPE 3
+.Os
+.Sh NAME
+.Nm acl_set_tag_type
+.Nd set the tag type of an ACL entry
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_set_tag_type "acl_entry_t entry_d" "acl_tag_t tag_type"
+.Sh DESCRIPTION
+The
+.Fn acl_set_tag_type
+function
+is a POSIX.1e call that sets the ACL tag type of ACL entry
+.Fa entry_d
+to the value of
+.Fa tag_type .
+.Sh RETURN VALUES
+.Rv -std acl_set_tag_type
+.Sh ERRORS
+The
+.Fn acl_set_tag_type
+function fails if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Fa entry_d
+is not a valid descriptor for an ACL entry. Argument
+.Fa tag_type
+is not a valid ACL tag type.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_get_tag_type 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Chris D. Faulhaber
--- /dev/null
+.\"-
+.\" Copyright (c) 2000, 2002 Robert N. M. Watson
+.\" All rights reserved.
+.\"
+.\" This software was developed by Robert Watson for the TrustedBSD Project.
+.\"
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_to_text.3,v 1.15 2002/12/29 20:52:42 rwatson Exp $
+.\"
+.Dd January 28, 2000
+.Dt ACL_TO_TEXT 3
+.Os
+.Sh NAME
+.Nm acl_to_text
+.Nd convert an ACL to text
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft char *
+.Fn acl_to_text "acl_t acl" "ssize_t *len_p"
+.Sh DESCRIPTION
+The
+.Fn acl_to_text
+function translates the ACL pointed to by argument
+.Va acl
+into a NULL terminated character string. If the pointer
+.Va len_p
+is not NULL, then the function shall return the length of the string (not
+including the NULL terminator) in the location pointed to by
+.Va len_p .
+The format of the text string returned by
+.Fn acl_to_text
+for an ACL of type ACL_TYPE_EXTENDED differs from that specified by the
+POSIX.1e standard, and this function cannot translate between formats.
+.Pp
+This function allocates any memory necessary to contain the string and
+returns a pointer to the string. The caller should free any releasable
+memory, when the new string is no longer required, by calling
+.Xr acl_free 3
+with the
+.Va (void*)char
+as an argument.
+.Sh RETURN VALUES
+Upon successful completion, the function shall return a pointer to the
+long text form of an ACL. Otherwise, a value of
+.Va (char*)NULL
+shall be returned and
+.Va errno
+shall be set to indicate the error.
+.Sh ERRORS
+If any of the following conditions occur, the
+.Fn acl_to_text
+function shall return a value of
+.Va (acl_t)NULL
+and set
+.Va errno
+to the corresponding value:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+Argument
+.Va acl
+does not point to a valid ACL.
+.Pp
+The ACL denoted by
+.Va acl
+contains one or more improperly formed ACL entries, or for some other
+reason cannot be translated into a text form of an ACL.
+.It Bq Er ENOMEM
+The character string to be returned requires more memory than is allowed
+by the hardware or software-imposed memory management constraints.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_free 3 ,
+.Xr acl_from_text 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Robert N M Watson
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include <sys/appleapiopts.h>
+#include <sys/types.h>
+#include <sys/acl.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <membership.h>
+#include <pwd.h>
+#include <grp.h>
+
+#include "aclvar.h"
+
+ssize_t
+acl_copy_ext(void *buf, acl_t acl, ssize_t size)
+{
+ struct kauth_filesec *ext = (struct kauth_filesec *)buf;
+ ssize_t reqsize;
+ int i;
+
+ /* validate arguments, compute required size */
+ reqsize = acl_size(acl);
+ if (reqsize < 0)
+ return(-1);
+ if (reqsize > size) {
+ errno = ERANGE;
+ return(-1);
+ }
+
+ /* export the header */
+ ext->fsec_magic = KAUTH_FILESEC_MAGIC;
+ ext->fsec_entrycount = acl->a_entries;
+ ext->fsec_flags = acl->a_flags;
+ /* XXX owner? */
+
+ /* copy ACEs */
+ for (i = 0; i < acl->a_entries; i++) {
+ /* ACE contents are almost identical */
+ ext->fsec_ace[i].ace_applicable = acl->a_ace[i].ae_applicable;
+ ext->fsec_ace[i].ace_flags =
+ (acl->a_ace[i].ae_tag & KAUTH_ACE_KINDMASK) |
+ (acl->a_ace[i].ae_flags & ~KAUTH_ACE_KINDMASK);
+ ext->fsec_ace[i].ace_rights = acl->a_ace[i].ae_perms;
+ }
+
+ return(reqsize);
+}
+
+acl_t
+acl_copy_int(const void *buf)
+{
+ struct kauth_filesec *ext = (struct kauth_filesec *)buf;
+ acl_t ap;
+ int i;
+
+ if (ext->fsec_magic != KAUTH_FILESEC_MAGIC) {
+ errno = EINVAL;
+ return(NULL);
+ }
+
+ if ((ap = acl_init(ext->fsec_entrycount)) != NULL) {
+ /* copy useful header fields */
+ ap->a_flags = ext->fsec_flags;
+ ap->a_entries = ext->fsec_entrycount;
+ /* copy ACEs */
+ for (i = 0; i < ap->a_entries; i++) {
+ /* ACE contents are literally identical */
+/* XXX Consider writing the magic out to the persistent store
+ * to detect corruption
+ */
+ ap->a_ace[i].ae_magic = _ACL_ENTRY_MAGIC;
+ ap->a_ace[i].ae_applicable = ext->fsec_ace[i].ace_applicable;
+ ap->a_ace[i].ae_flags = ext->fsec_ace[i].ace_flags & ~KAUTH_ACE_KINDMASK;
+ ap->a_ace[i].ae_tag = ext->fsec_ace[i].ace_flags & KAUTH_ACE_KINDMASK;
+ ap->a_ace[i].ae_perms = ext->fsec_ace[i].ace_rights;
+ }
+ }
+ return(ap);
+}
+
+#define ACL_TYPE_DIR (1<<0)
+#define ACL_TYPE_FILE (1<<1)
+#define ACL_TYPE_ACL (1<<2)
+
+static struct {
+ acl_perm_t perm;
+ char *name;
+ int type;
+} acl_perms[] = {
+ {ACL_READ_DATA, "read", ACL_TYPE_FILE},
+// {ACL_LIST_DIRECTORY, "list", ACL_TYPE_DIR},
+ {ACL_WRITE_DATA, "write", ACL_TYPE_FILE},
+// {ACL_ADD_FILE, "add_file", ACL_TYPE_DIR},
+ {ACL_EXECUTE, "execute", ACL_TYPE_FILE},
+// {ACL_SEARCH, "search", ACL_TYPE_DIR},
+ {ACL_DELETE, "delete", ACL_TYPE_FILE | ACL_TYPE_DIR},
+ {ACL_APPEND_DATA, "append", ACL_TYPE_FILE},
+// {ACL_ADD_SUBDIRECTORY, "add_subdirectory", ACL_TYPE_DIR},
+ {ACL_DELETE_CHILD, "delete_child", ACL_TYPE_DIR},
+ {ACL_READ_ATTRIBUTES, "readattr", ACL_TYPE_FILE | ACL_TYPE_DIR},
+ {ACL_WRITE_ATTRIBUTES, "writeattr", ACL_TYPE_FILE | ACL_TYPE_DIR},
+ {ACL_READ_EXTATTRIBUTES, "readextattr", ACL_TYPE_FILE | ACL_TYPE_DIR},
+ {ACL_WRITE_EXTATTRIBUTES, "writeextattr", ACL_TYPE_FILE | ACL_TYPE_DIR},
+ {ACL_READ_SECURITY, "readsecurity", ACL_TYPE_FILE | ACL_TYPE_DIR},
+ {ACL_WRITE_SECURITY, "writesecurity", ACL_TYPE_FILE | ACL_TYPE_DIR},
+ {ACL_CHANGE_OWNER, "chown", ACL_TYPE_FILE | ACL_TYPE_DIR},
+ {0, NULL, 0}
+};
+
+static struct {
+ acl_flag_t flag;
+ char *name;
+ int type;
+} acl_flags[] = {
+ {ACL_FLAG_DEFER_INHERIT, "defer_inherit", ACL_TYPE_ACL},
+ {ACL_ENTRY_FILE_INHERIT, "file_inherit", ACL_TYPE_DIR},
+ {ACL_ENTRY_DIRECTORY_INHERIT, "directory_inherit", ACL_TYPE_DIR},
+ {ACL_ENTRY_LIMIT_INHERIT, "limit_inherit", ACL_TYPE_FILE | ACL_TYPE_DIR},
+ {ACL_ENTRY_ONLY_INHERIT, "only_inherit", ACL_TYPE_DIR},
+ {0, NULL, 0}
+};
+
+/*
+ * reallocing snprintf with offset
+ */
+
+static int
+raosnprintf(char **buf, size_t *size, ssize_t *offset, char *fmt, ...)
+{
+ va_list ap;
+ int ret;
+
+ do
+ {
+ if (*offset < *size)
+ {
+ va_start(ap, fmt);
+ ret = vsnprintf(*buf + *offset, *size - *offset, fmt, ap);
+ va_end(ap);
+ if (ret < *size)
+ {
+ *offset += ret;
+ return ret;
+ }
+ }
+ *buf = realloc(*buf, (*size *= 2));
+ } while (*buf);
+
+ //warn("realloc failure");
+ return 0;
+}
+
+static char *
+uuid_to_name(uuid_t *uu, uid_t *id, int *isgid)
+{
+ struct group *tgrp = NULL;
+ struct passwd *tpass = NULL;
+
+ if (0 == mbr_uuid_to_id(*uu, id, isgid))
+ {
+ switch (*isgid)
+ {
+ case ID_TYPE_UID:
+ if (!(tpass = getpwuid(*id)))
+ goto errout;
+ return strdup(tpass->pw_name);
+ break;
+ case ID_TYPE_GID:
+ if (!(tgrp = getgrgid((gid_t) *id)))
+ goto errout;
+ return strdup(tgrp->gr_name);
+ break;
+ default:
+errout: ; //warn("Unable to translate qualifier on ACL\n");
+ }
+ }
+ return "";
+}
+
+acl_t
+acl_from_text(const char *buf_p)
+{
+ int i, error = 0, need_tag = 1, ug_tag = -1;
+ char *buf;
+ char *entry, *field, *sub,
+ *last_field, *last_entry, *last_sub;
+ uuid_t *uu;
+ struct passwd *tpass = NULL;
+ struct group *tgrp = NULL;
+ acl_entry_t acl_entry;
+ acl_flagset_t flags = NULL;
+ acl_permset_t perms = NULL;
+ acl_tag_t tag;
+ acl_t acl_ret;
+
+ if ((acl_ret = acl_init(1)) == NULL)
+ return NULL;
+
+ if (buf_p == NULL)
+ return NULL;
+
+ if ((buf = strdup(buf_p)) == NULL)
+ return NULL;
+
+ /* acl flags */
+ if ((entry = strtok_r(buf, "\n", &last_entry)) != NULL)
+ {
+ /* stamp */
+ field = strtok_r(entry, " ", &last_field);
+ if (field && strncmp(field, "!#acl", strlen("!#acl")))
+ {
+ error = EINVAL;
+ goto exit;
+ }
+
+ /* version */
+ field = strtok_r(NULL, " ", &last_field);
+ errno = 0;
+ if (field == NULL || strtol(field, NULL, 0) != 1)
+ {
+ error = EINVAL;
+ goto exit;
+ }
+
+ /* optional flags */
+ if((field = strtok_r(NULL, " ", &last_field)) != NULL)
+ {
+ acl_get_flagset_np(acl_ret, &flags);
+ for (sub = strtok_r(field, ",", &last_sub); sub;
+ sub = strtok_r(NULL, ",", &last_sub))
+ {
+ for (i = 0; acl_flags[i].name != NULL; ++i)
+ {
+ if (acl_flags[i].type & ACL_TYPE_ACL
+ && !strcmp(acl_flags[i].name, sub))
+ {
+ acl_add_flag_np(flags, acl_flags[i].flag);
+ break;
+ }
+ }
+ if (acl_flags[i].name == NULL)
+ {
+ /* couldn't find flag */
+ error = EINVAL;
+ goto exit;
+ }
+ }
+ }
+ }
+
+ for (entry = strtok_r(NULL, "\n", &last_entry); entry;
+ entry = strtok_r(NULL, "\n", &last_entry))
+ {
+ field = strtok_r(entry, ":", &last_field);
+
+ if((uu = calloc(1, sizeof(uuid_t))) == NULL)
+ goto exit;
+
+ if(acl_create_entry(&acl_ret, &acl_entry))
+ goto exit;
+
+ acl_get_flagset_np(acl_entry, &flags);
+ acl_get_permset(acl_entry, &perms);
+
+ switch(*field)
+ {
+ case 'u':
+ if(!strncmp(buf, "user", strlen(field)))
+ ug_tag = ID_TYPE_UID;
+ break;
+ case 'g':
+ if(!strncmp(buf, "group", strlen(field)))
+ ug_tag = ID_TYPE_GID;
+ break;
+
+ }
+
+ /* uuid */
+ if ((field = strtok_r(NULL, ":", &last_field)) != NULL)
+ {
+ mbr_string_to_uuid(field, *uu);
+ need_tag = 0;
+ }
+ /* name */
+ if ((field = strtok_r(NULL, ":", &last_field)) != NULL && need_tag)
+ {
+ switch(ug_tag)
+ {
+ case ID_TYPE_UID:
+ if((tpass = getpwnam(field)) != NULL)
+ if (mbr_uid_to_uuid(tpass->pw_uid, *uu) != 0)
+ {
+ error = EINVAL;
+ goto exit;
+ }
+ break;
+ case ID_TYPE_GID:
+ if ((tgrp = getgrnam(field)) != NULL)
+ if (mbr_gid_to_uuid(tgrp->gr_gid, *uu) != 0)
+ {
+ error = EINVAL;
+ goto exit;
+ }
+ break;
+ }
+ need_tag = 0;
+ }
+ /* uid */
+ if ((field = strtok_r(NULL, ":", &last_field)) != NULL && need_tag)
+ {
+ uid_t id;
+ error = 0;
+
+ if((id = strtol(field, NULL, 10)) == 0 && error)
+ {
+ error = EINVAL;
+ goto exit;
+ }
+
+ switch(ug_tag)
+ {
+ case ID_TYPE_UID:
+ if((tpass = getpwuid((uid_t)id)) != NULL)
+ if (mbr_uid_to_uuid(tpass->pw_uid, *uu) != 0)
+ {
+ error = EINVAL;
+ goto exit;
+ }
+ break;
+ case ID_TYPE_GID:
+ if ((tgrp = getgrgid((gid_t)id)) != NULL)
+ if (mbr_gid_to_uuid(tgrp->gr_gid, *uu) != 0)
+ {
+ error = EINVAL;
+ goto exit;
+ }
+ break;
+ }
+ need_tag = 0;
+ }
+
+ /* nothing do set as qualifier */
+ if (need_tag)
+ {
+ error = EINVAL;
+ goto exit;
+ }
+
+ /* flags */
+ if((field = strtok_r(NULL, ":", &last_field)) == NULL)
+ {
+ error = EINVAL;
+ goto exit;
+ }
+
+ for (tag = 0, sub = strtok_r(field, ",", &last_sub); sub;
+ sub = strtok_r(NULL, ",", &last_sub))
+ {
+ if (!tag && !strcmp(sub, "allow")) {
+ tag = ACL_EXTENDED_ALLOW;
+ continue;
+ } else if (!tag && !strcmp(sub, "deny")) {
+ tag = ACL_EXTENDED_DENY;
+ continue;
+ }
+ for (i = 0; acl_flags[i].name != NULL; ++i)
+ {
+ if (acl_flags[i].type & (ACL_TYPE_FILE | ACL_TYPE_DIR)
+ && !strcmp(acl_flags[i].name, sub))
+ {
+ acl_add_flag_np(flags, acl_flags[i].flag);
+ break;
+ }
+ }
+ if (acl_flags[i].name == NULL)
+ {
+ /* couldn't find perm */
+ error = EINVAL;
+ goto exit;
+ }
+ }
+
+ if((field = strtok_r(NULL, ":", &last_field)) == NULL)
+ {
+ error = EINVAL;
+ goto exit;
+ }
+
+ for (sub = strtok_r(field, ",", &last_sub); sub;
+ sub = strtok_r(NULL, ",", &last_sub))
+ {
+ for (i = 0; acl_perms[i].name != NULL; i++)
+ {
+ if (acl_perms[i].type & (ACL_TYPE_FILE | ACL_TYPE_DIR)
+ && !strcmp(acl_perms[i].name, sub))
+ {
+ acl_add_perm(perms, acl_perms[i].perm);
+ break;
+ }
+ }
+ if (acl_perms[i].name == NULL)
+ {
+ /* couldn't find perm */
+ error = EINVAL;
+ goto exit;
+ }
+ }
+ acl_set_tag_type(acl_entry, tag);
+ acl_set_qualifier(acl_entry, *uu);
+ }
+exit:
+ free(buf);
+ if (error)
+ {
+ acl_free(acl_ret);
+ acl_ret = NULL;
+ errno = error;
+ }
+ return acl_ret;
+}
+
+char *
+acl_to_text(acl_t acl, ssize_t *len_p)
+{
+ uuid_t *uu;
+ acl_tag_t tag;
+ acl_entry_t entry = NULL;
+ acl_flagset_t flags;
+ acl_permset_t perms;
+ uid_t id;
+ char *str, uu_str[256];
+ int i, first;
+ int isgid;
+
+ size_t bufsize = 1024;
+ char *buf = malloc(bufsize);
+
+ if (len_p == NULL)
+ len_p = alloca(sizeof(ssize_t));
+
+ *len_p = 0;
+
+ if(!raosnprintf(&buf, &bufsize, len_p, "!#acl %d", 1))
+ return NULL;
+
+ if (acl_get_flagset_np(acl, &flags) == 0)
+ {
+ for (i = 0, first = 0; acl_flags[i].name != NULL; ++i)
+ {
+ if (acl_flags[i].type & ACL_TYPE_ACL
+ && acl_get_flag_np(flags, acl_flags[i].flag) != 0)
+ {
+ if(!raosnprintf(&buf, &bufsize, len_p, "%s%s",
+ first++ ? "," : " ", acl_flags[i].name))
+ return NULL;
+ }
+ }
+ }
+ for (;acl_get_entry(acl,
+ entry == NULL ? ACL_FIRST_ENTRY : ACL_NEXT_ENTRY, &entry) == 0;)
+ {
+ if (((uu = (uuid_t *) acl_get_qualifier(entry)) == NULL)
+ || (acl_get_tag_type(entry, &tag) != 0)
+ || (acl_get_flagset_np(entry, &flags) != 0)
+ || (acl_get_permset(entry, &perms) != 0))
+ continue;
+
+ str = uuid_to_name(uu, &id, &isgid);
+ mbr_uuid_to_string(uu, uu_str); // XXX how big should uu_str be? // XXX error?
+
+ if(!raosnprintf(&buf, &bufsize, len_p, "\n%s:%s:%s:%d:%s",
+ isgid ? "group" : "user",
+ uu_str,
+ str,
+ id,
+ (tag == ACL_EXTENDED_ALLOW) ? "allow" : "deny"))
+ return NULL;
+
+ free(str);
+
+ for (i = 0; acl_flags[i].name != NULL; ++i)
+ {
+ if (acl_flags[i].type & (ACL_TYPE_DIR | ACL_TYPE_FILE))
+ {
+ if(acl_get_flag_np(flags, acl_flags[i].flag) != 0)
+ {
+ if(!raosnprintf(&buf, &bufsize, len_p, ",%s",
+ acl_flags[i].name))
+ return NULL;
+ }
+ }
+ }
+
+ for (i = 0, first = 0; acl_perms[i].name != NULL; ++i)
+ {
+ if (acl_perms[i].type & (ACL_TYPE_DIR | ACL_TYPE_FILE))
+ {
+ if(acl_get_perm_np(perms, acl_perms[i].perm) != 0)
+ {
+ if(!raosnprintf(&buf, &bufsize, len_p, "%s%s",
+ first++ ? "," : ":",
+ acl_perms[i].name))
+ return NULL;
+ }
+ }
+ }
+ }
+ buf[(*len_p)++] = '\n';
+ buf[(*len_p)++] = 0;
+ return buf;
+}
+
+ssize_t
+acl_size(acl_t acl)
+{
+ _ACL_VALIDATE_ACL(acl);
+
+ return(_ACL_HEADER_SIZE + acl->a_entries * _ACL_ENTRY_SIZE);
+}
--- /dev/null
+.\"-
+.\" Copyright (c) 2000, 2002 Robert N. M. Watson
+.\" All rights reserved.
+.\"
+.\" This software was developed by Robert Watson for the TrustedBSD Project.
+.\"
+.\" 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.
+.\"
+.\" $FreeBSD: src/lib/libc/posix1e/acl_valid.3,v 1.14 2002/12/29 20:47:05 rwatson Exp $
+.\"
+.Dd December 29, 2002
+.Dt ACL_VALID 3
+.Os
+.Sh NAME
+.Nm acl_valid ,
+.Nm acl_valid_fd_np ,
+.Nm acl_valid_file_np ,
+.Nm acl_valid_link_np
+.Nd validate an ACL
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/types.h
+.In sys/acl.h
+.Ft int
+.Fn acl_valid "acl_t acl"
+.Ft int
+.Fn acl_valid_fd_np "int fd" "acl_type_t type" "acl_t acl"
+.Ft int
+.Fn acl_valid_file_np "const char *path_p" "acl_type_t type" "acl_t acl"
+.Ft int
+.Fn acl_valid_link_np "const char *path_p" "acl_type_t type" "acl_t acl"
+.Sh DESCRIPTION
+These functions check that the ACL referred to by the argument
+.Va acl
+is valid. The POSIX.1e routine,
+.Fn acl_valid ,
+checks assumes ACL_TYPE_EXTENDED, and disregard
+of the context in which the ACL is to be used. The non-portable forms,
+.Fn acl_valid_fd_np ,
+.Fn acl_valid_file_np ,
+and
+.Fn acl_valid_link_np
+allow an ACL to be checked in the context of a specific acl type,
+.Va type ,
+and file system object.
+In environments where additional ACL types are
+supported than just POSIX.1e, this makes more sense.
+Whereas
+.Fn acl_valid_file_np
+will follow the symlink if the specified path is to a symlink,
+.Fn acl_valid_link_np
+will not.
+.Pp
+The qualifier field shall be unique among all entries of
+the same POSIX.1e ACL facility defined tag type. The
+tag type field shall contain valid values including any
+implementation-defined values. Validation of the values
+of the qualifier field is implementation-defined.
+.Pp
+The POSIX.1e
+.Fn acl_valid
+function may reorder the ACL for the purposes of verification; the
+non-portable validation functions will not.
+.Sh RETURN VALUES
+.Rv -std
+.Sh ERRORS
+If any of the following conditions occur, these functions shall return
+-1 and set
+.Va errno
+to the corresponding value:
+.Bl -tag -width Er
+.It Bq Er EACCES
+Search permission is denied for a component of the path prefix, or the
+object exists and the process does not have appropriate access rights.
+.It Bq Er EBADF
+The
+.Va fd
+argument is not a valid file descriptor.
+.It Bq Er EINVAL
+Argument
+.Va acl
+does not point to a valid ACL.
+.Pp
+One or more of the required ACL entries is not present in
+.Va acl .
+.Pp
+The ACL contains entries that are not unique.
+.Pp
+The file system rejects the ACL based on fs-specific semantics issues.
+.It Bq Er ENAMETOOLONG
+A component of a pathname exceeded 255 characters, or an
+entire path name exceeded 1023 characters.
+.It Bq Er ENOENT
+The named object does not exist, or the
+.Va path_p
+argument points to an empty string.
+.It Bq Er ENOMEM
+Insufficient memory available to fulfill request.
+.It Bq Er EOPNOTSUPP
+The file system does not support ACL retrieval.
+.El
+.Sh SEE ALSO
+.Xr acl 3 ,
+.Xr acl_get 3 ,
+.Xr acl_init 3 ,
+.Xr acl_set 3 ,
+.Xr posix1e 3
+.Sh STANDARDS
+POSIX.1e is described in IEEE POSIX.1e draft 17.
+.Sh AUTHORS
+.An Michael Smith
+.An Robert N M Watson
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef _ACLVAR_H
+#define _ACLVAR_H
+
+#include <sys/kauth.h>
+
+#define _ACL_HEADER_SIZE sizeof(struct kauth_filesec)
+#define _ACL_ENTRY_SIZE sizeof(struct kauth_ace)
+
+/*
+ * Internal access control list entry representation.
+ */
+struct _acl_entry {
+ u_int32_t ae_magic;
+#define _ACL_ENTRY_MAGIC 0xac1ac101
+ u_int32_t ae_tag;
+ guid_t ae_applicable;
+ u_int32_t ae_flags;
+ u_int32_t ae_perms;
+};
+
+/*
+ * Internal representation of an ACL.
+ * XXX static allocation is wasteful.
+ */
+struct _acl {
+ u_int32_t a_magic;
+#define _ACL_ACL_MAGIC 0xac1ac102
+ unsigned a_entries;
+ int a_last_get;
+ u_int32_t a_flags;
+ struct _acl_entry a_ace[ACL_MAX_ENTRIES];
+};
+
+/*
+ * ACL/entry flags.
+ */
+struct _acl_flagset {
+ u_int32_t af_flags;
+};
+
+/*
+ * ACL entry permissions.
+ */
+struct _acl_permset {
+ u_int32_t ap_perms;
+};
+
+/*
+ * Argument validation.
+ */
+
+#define _ACL_VALID_ENTRY(_e) ((_e)->ae_magic == _ACL_ENTRY_MAGIC)
+
+#define _ACL_VALID_ACL(_a) ((_a)->a_magic == _ACL_ACL_MAGIC)
+
+#define _ACL_ENTRY_CONTAINED(_a, _e) \
+ ((_e) >= &(_a)->a_ace[0]) && ((_e) < &(_a)->a_ace[ACL_MAX_ENTRIES])
+
+#define _ACL_VALID_FLAG(_f) (((_f) & _ACL_FLAGS_MASK) == (_f))
+
+#define _ACL_VALID_ENTRY_FLAG(_f) (((_f) & _ACL_ENTRY_FLAGS_MASK) == (_f))
+
+#define _ACL_PERMS_MASK (ACL_READ_DATA | \
+ ACL_LIST_DIRECTORY | \
+ ACL_WRITE_DATA | \
+ ACL_ADD_FILE | \
+ ACL_EXECUTE | \
+ ACL_SEARCH | \
+ ACL_DELETE | \
+ ACL_APPEND_DATA | \
+ ACL_ADD_SUBDIRECTORY | \
+ ACL_DELETE_CHILD | \
+ ACL_READ_ATTRIBUTES | \
+ ACL_WRITE_ATTRIBUTES | \
+ ACL_READ_EXTATTRIBUTES | \
+ ACL_WRITE_EXTATTRIBUTES | \
+ ACL_READ_SECURITY | \
+ ACL_WRITE_SECURITY | \
+ ACL_CHANGE_OWNER)
+
+#define _ACL_VALID_PERM(_f) (((_f) & ~_ACL_PERMS_MASK) == 0)
+
+#define _ACL_VALIDATE_ACL(_a) \
+do { \
+ if (!_ACL_VALID_ACL((_a))) { \
+ errno = EINVAL; \
+ return(-1); \
+ } \
+} while (0)
+
+#define _ACL_VALIDATE_ENTRY(_e) \
+do { \
+ if (!_ACL_VALID_ENTRY((_e))) { \
+ errno = EINVAL; \
+ return(-1); \
+ } \
+} while (0)
+
+#define _ACL_VALIDATE_ENTRY_CONTAINED(_a, _e) \
+do { \
+ if (!_ACL_ENTRY_CONTAINED((_a), (_e))) { \
+ errno = EINVAL; \
+ return(-1); \
+ } \
+} while (0)
+
+#define _ACL_VALIDATE_FLAG(_f) \
+do { \
+ if (!_ACL_VALID_FLAG((_f))) { \
+ errno = EINVAL; \
+ return(-1); \
+ } \
+} while (0)
+
+#define _ACL_VALIDATE_ENTRY_FLAG(_f) \
+do { \
+ if (!_ACL_VALID_ENTRY_FLAG((_f))) { \
+ errno = EINVAL; \
+ return(-1); \
+ } \
+} while (0)
+
+#define _ACL_VALIDATE_PERM(_f) \
+do { \
+ if (!_ACL_VALID_PERM((_f))) { \
+ errno = EINVAL; \
+ return(-1); \
+ } \
+} while (0)
+
+#endif /* _ACLVAR_H */
MDSRCS += \
abs.s \
- ecvt.c \
ffs.s \
fp.h \
icacheinval.s \
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
+++ /dev/null
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
- *
- * File: libc/m98k/gen/ecvt.c
- *
- * char *ecvt(double x, int ndigits, int *decimal, int *sign);
- * char *fcvt(double x, int ndigits, int *decimal, int *sign);
- *
- * The function `ecvt' converts the double `x' to a null-terminated
- * string of `ndigits' ASCII digits and returns a pointer to the string.
- * The position of the decimal point relative to the beginning of the
- * string is stored in the int pointed to by `decimal'. A negative
- * value means that the decimal point appears to the left of the returned
- * digits. If the sign of the result is negative, a non-zero value is
- * stored in the int pointed to by `sign'; otherwise, a zero value is stored.
- * The low-order digit of the returned value is rounded.
- *
- * The function `fcvt' is identical to `ecvt', except that the correct digit
- * has been rounded for Fortran F-format output of the number of digits
- * specified by `ndigits'.
- *
- * HISTORY
- * 10-Nov-92 Derek B Clegg (dclegg@next.com)
- * Ported to m98k.
- * 8-Jan-92 Peter King (king@next.com)
- * Created from M68K sources which was created from VAX sources.
- */
-#import <math.h>
-
-static double ecvt_rint(double x);
-static double ecvt_copysign(double x, double y);
-static char *cvt(double arg, int ndigits, int *decptp, int *signp, int eflag);
-
-#define isNAN(x) ((x) != (x))
-
-/* big enough to handle %.20f conversion of 1e308 */
-#define NDIG 350
-
-char *
-ecvt(double arg, int ndigits, int *decptp, int *signp)
-{
- return (cvt(arg, ndigits, decptp, signp, 1));
-}
-
-char *
-fcvt(double arg, int ndigits, int *decptp, int *signp)
-{
- return (cvt(arg, ndigits, decptp, signp, 0));
-}
-
-static char *
-cvt(double arg, int ndigits, int *decptp, int *signp, int eflag)
-{
- int decpt;
- double fi, fj;
- char *p, *p1;
- static char buf[NDIG] = { 0 };
-
- if (ndigits < 0)
- ndigits = 0;
- if (ndigits >= NDIG - 1)
- ndigits = NDIG - 2;
-
- decpt = 0;
- *signp = 0;
- p = &buf[0];
-
- if (arg == 0) {
- *decptp = 0;
- while (p < &buf[ndigits])
- *p++ = '0';
- *p = '\0';
- return (buf);
- } else if (arg < 0) {
- *signp = 1;
- arg = -arg;
- }
-
- arg = modf(arg, &fi);
- p1 = &buf[NDIG];
-
- /* Do integer part */
-
- if (fi != 0) {
- while (fi != 0) {
- fj = modf(fi/10, &fi);
-#if 0
- *--p1 = (int)((fj + 0.03) * 10) + '0';
-#else
- *--p1 = (int)ecvt_rint(fj * 10) + '0';
-#endif
- decpt++;
- }
- while (p1 < &buf[NDIG])
- *p++ = *p1++;
- } else if (arg > 0) {
- while ((fj = arg*10) < 1) {
- arg = fj;
- decpt--;
- }
- }
- *decptp = decpt;
-
- /* Do the fractional part.
- * p pts to where fraction should be concatenated.
- * p1 is how far conversion must go to.
- */
- p1 = &buf[ndigits];
- if (eflag == 0) {
- /* fcvt must provide ndigits after decimal pt */
- p1 += decpt;
- /* if decpt was negative, we might be done for fcvt */
- if (p1 < &buf[0]) {
- buf[0] = '\0';
- return (buf);
- }
- }
-
- while (p <= p1 && p < &buf[NDIG]) {
- arg *= 10;
- arg = modf(arg, &fj);
- *p++ = (int)fj + '0';
- }
-
- /* If we converted all the way to the end of the buf, don't mess with
- * rounding since there's nothing significant out here anyway.
- */
- if (p1 >= &buf[NDIG]) {
- buf[NDIG-1] = '\0';
- return (buf);
- }
-
- /* Round by adding 5 to last digit and propagating carries. */
- p = p1;
- *p1 += 5;
- while (*p1 > '9') {
- *p1 = '0';
- if (p1 > buf) {
- ++*--p1;
- } else {
- *p1 = '1';
- (*decptp)++;
- if (eflag == 0) {
- if (p > buf)
- *p = '0';
- p++;
- }
- }
- }
- *p = '\0';
- return (buf);
-}
-
-static double L = 4503599627370496.0E0; /* 2**52 */
-
-static int ecvt_init = 0;
-
-/*
- * FIXME: This deserves a comment if you turn this off!
- * This used to #pragma CC_OPT_OFF.
- * (Probably this was because the isNAN test was optimized away.)
- * Why don't we just use the value of L given above?
- */
-
-static double
-ecvt_rint(double x)
-{
- double s, t, one;
-
- one = 1.0;
-
- if (ecvt_init == 0) {
- int i;
- L = 1.0;
- for (i = 52; i != 0; i--)
- L *= 2.0;
- ecvt_init = 1;
- }
- if (isNAN(x))
- return (x);
- if (ecvt_copysign(x, one) >= L) /* already an integer */
- return (x);
- s = ecvt_copysign(L, x);
- t = x + s; /* x+s rounded to integer */
- return (t - s);
-}
-
-/* Couldn't we use something like the following structure instead of the
- hacky unsigned short pointer stuff?
-
-struct double_format {
- unsigned sign:1;
- unsigned exponent:11;
- unsigned hi_fraction:20;
- unsigned lo_fraction:32;
-};
-
-*/
-
-#define msign ((unsigned short)0x7fff)
-#define mexp ((unsigned short)0x7ff0)
-
-static double
-ecvt_copysign(double x, double y)
-{
- unsigned short *px, *py;
-
- px = (unsigned short *)&x;
- py = (unsigned short *)&y;
- *px = (*px & msign) | (*py & ~msign);
- return (x);
-}
-
-/*
- * This used to #pragma CC_OPT_ON
- */
-
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
-# Long double is just double precision.
-FBSDSRCS+=machdep_ldisd.c
+# Long double is head-tail pair of doubles
+FBSDSRCS+= gdtoa-strtopdd.c machdep_ldisdd.c _ldbl_util.c
+
+# also build a 64-bit long double version (ppc only)
+LDBLSRCS += machdep_ldisdd.c
MDSRCS += \
bcopy.s \
bzero.s \
+ memset.s \
memcmp.s \
strcat.s \
strcmp.s \
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
.text
.align 5
.globl _bzero
- .globl _memset
// *************
// * B Z E R O *
_bzero: // void bzero(void *b, size_t len);
ba _COMM_PAGE_BZERO
-
-
-// ***************
-// * M E M S E T *
-// ***************
-// Registers we use:
-// r3 = original ptr, not changed since memset returns it
-// r4 = count of bytes to set ("rc")
-// r11 = working operand ptr ("rp")
-// r10 = value to set ("rv")
-
-#define rc r4
-#define rp r11
-#define rv r10
-
- .align 5
-_memset: // void * memset(void *b, int c, size_t len);
- andi. rv,r4,0xFF // copy value to working register, test for 0
- mr rc,r5 // move length to working register
- cmplgi cr1,r5,32 // length < 32 ?
- beqa++ _COMM_PAGE_BZERO
- rlwimi rv,rv,8,16,23 // replicate value to low 2 bytes
- mr rp,r3 // make working copy of operand ptr
- rlwimi rv,rv,16,0,15 // value now in all 4 bytes
- blt cr1,Ltail // length<32, so use common tail routine
- neg r5,rp // start to compute #bytes to align
- andi. r6,r5,0x7 // r6 <- #bytes to align on dw
- beq Lmemset1 // already aligned
-
- ; align on 8-byte boundary
-
- mtcrf 0x01,r6 // move count to cr7
- sub rc,rc,r6 // adjust length
- bf 31,1f
- stb rv,0(rp)
- addi rp,rp,1
-1:
- bf 30,2f
- sth rv,0(rp)
- addi rp,rp,2
-2:
- bf 29,Lmemset1
- stw rv,0(rp)
- addi rp,rp,4
-
- // loop on 16-byte blocks
-Lmemset1:
- stw rv,0(rp) // store first 8 bytes from rv
- stw rv,4(rp)
- srgi r5,rc,4 // r5 <- #blocks (>=1)
- mtcrf 0x01,rc // leftover length to cr7
- mtctr r5 // set up loop count
- lfd f0,0(rp) // pick up in a fp register
- b 2f // enter loop in middle
- .align 4
-1: // loop on 16-byte blocks
- stfd f0,0(rp)
-2:
- stfd f0,8(rp)
- addi rp,rp,16
- bdnz 1b
-
- // store up to 16 trailing bytes (count in cr7)
-
- bf 28,3f
- stfd f0,0(rp)
- addi rp,rp,8
-3:
- bf 29,4f
- stw rv,0(rp)
- addi rp,rp,4
-4:
- bf 30,5f
- sth rv,0(rp)
- addi rp,rp,2
-5:
- bflr 31
- stb rv,0(rp)
- blr
-
- // store up to 31 bytes from rv
- // rv = value to store (in all 4 bytes)
- // rc = #bytes to store (0..31)
-Ltail:
- andi. r5,rc,16 // bit 27 set in length?
- mtcrf 0x01,rc // low 4 bits of length to cr7
- beq 1f // test bits of length
- stw rv,0(rp)
- stw rv,4(rp)
- stw rv,8(rp)
- stw rv,12(rp)
- addi rp,rp,16
-1:
- bf 28,2f
- stw rv,0(rp)
- stw rv,4(rp)
- addi rp,rp,8
-2:
- bf 29,3f
- stw rv,0(rp)
- addi rp,rp,4
-3:
- bf 30,4f
- sth rv,0(rp)
- addi rp,rp,2
-4:
- bflr 31
- stb rv,0(rp)
- blr
-
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+/*
+ * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include <machine/cpu_capabilities.h>
+
+/* We use mode-independent "g" opcodes such as "srgi". These expand
+ * into word operations when targeting __ppc__, and into doubleword
+ * operations when targeting __ppc64__.
+ */
+#include <architecture/ppc/mode_independent_asm.h>
+
+
+ .text
+#define kShort 128 // threshold for calling commpage
+
+
+/* ***************
+ * * M E M S E T *
+ * ***************
+ *
+ * Registers we use:
+ * r3 = original ptr, not changed since memset returns it
+ * r4 = count of bytes to set
+ * r7 = value to set
+ * r8 = working operand ptr
+ */
+
+ .globl _memset
+ .align 5
+_memset: // void * memset(void *b, int c, size_t len);
+ andi. r7,r4,0xFF // copy value to working register, test for 0
+ mr r4,r5 // move length to working register
+ cmplgi cr1,r5,kShort // long enough to bother with _COMM_PAGE_MEMSET_PATTERN?
+ beqa++ _COMM_PAGE_BZERO // if (c==0), map to bzero()
+ rlwimi r7,r7,8,16,23 // replicate nonzero value to low 2 bytes
+ neg r5,r3 // start to compute #bytes to align
+ mr r8,r3 // make working copy of operand ptr
+ rlwimi r7,r7,16,0,15 // value now in all 4 bytes
+ blt cr1,Lmemset3 // too short to use commpage
+
+ // TEMPORARY HACK
+ // Operand is long enough to use _COMM_PAGE_MEMSET_PATTERN. During Tiger
+ // development, B&I uses Panther kernels on their builders but runs Tiger
+ // apps on it. So _COMM_PAGE_MEMSET_PATTERN may not be on this machine.
+ // Rather than patch build fleet kernels, we just test to see if it is there
+ // and use the short-operand case if not. We can remove the hack when Tiger ships.
+
+ lhz r10,_COMM_PAGE_VERSION(0) // REMOVE THIS LINE WHEN TIGER SHIPS
+ andi. r0,r5,0xF // r0 <- #bytes to align on quadword
+
+ // Align ptr and store enough so that we have an aligned 16-byte pattern.
+
+ stw r7,0(r8)
+ stw r7,4(r8)
+ stw r7,8(r8)
+ stw r7,12(r8)
+ cmpwi cr1,r10,1 // REMOVE THIS LINE WHEN TIGER SHIPS
+ beq Lmemset1 // skip if (r0==0), ie if r8 is 16-byte aligned
+ add r8,r8,r0 // 16-byte align ptr
+ sub r4,r4,r0 // adjust length
+ stw r7,0(r8) // now we can store an aligned 16-byte pattern
+ stw r7,4(r8)
+ stw r7,8(r8)
+ stw r7,12(r8)
+
+ // Call machine-specific commpage routine, which expects:
+ // r4 = count (>=32)
+ // r8 = ptr (16-byte aligned) to memory to store
+ // r9 = ptr (16-byte aligned) to 16-byte pattern to store
+ // When it returns:
+ // r3, r7, and r12 are preserved
+ // r4 and r8 are updated to reflect a residual count of from 0..31 bytes
+
+Lmemset1:
+ mflr r12 // save return address
+ mr r9,r8 // point to 16-byte-aligned 16-byte pattern
+ addi r8,r8,16 // point to first unstored byte
+ subi r4,r4,16 // account for the aligned bytes we have stored
+ bnela++ cr1,_COMM_PAGE_MEMSET_PATTERN // CHANGE THIS LINE WHEN TIGER SHIPS
+ mtlr r12
+
+ // Here for short nonzero memset.
+ // r4 = count (<= kShort bytes)
+ // r7 = pattern in all four bytes
+ // r8 = ptr
+Lmemset3:
+ srgi. r0,r4,4 // any 16-byte chunks?
+ mtcrf 0x01,r4 // move length remaining to cr7 so we can test bits
+ beq Lmemset5 // fewer than 16 bytes
+ mtctr r0
+ b Lmemset4 // enter loop
+
+ .align 5
+Lmemset4: // loop over 16-byte chunks
+ stw r7,0(r8)
+ stw r7,4(r8)
+ stw r7,8(r8)
+ stw r7,12(r8)
+ addi r8,r8,16
+ bdnz++ Lmemset4
+
+ // Handle last 0..15 bytes.
+Lmemset5:
+ bf 28,2f
+ stw r7,0(r8)
+ stw r7,4(r8)
+ addi r8,r8,8
+2:
+ bf 29,3f
+ stw r7,0(r8)
+ addi r8,r8,4
+3:
+ bf 30,4f
+ sth r7,0(r8)
+ addi r8,r8,2
+4:
+ bflr 31
+ stb r7,0(r8)
+ blr
+
+
+/* *************************************
+ * * _ M E M S E T _ P A T T E R N 1 6 *
+ * *************************************
+ *
+ * Used to store a 16-byte pattern in memory:
+ *
+ * void _memset_pattern16(void *b, const void *c16, size_t len);
+ *
+ * Where c16 points to the 16-byte pattern. None of the parameters need be aligned.
+ */
+
+ .globl __memset_pattern16
+ .align 5
+__memset_pattern16:
+ cmplgi cr1,r5,kShort // check length
+ lwz r7,0(r4) // load pattern into (these remain lwz in 64-bit mode)
+ lwz r9,4(r4)
+ neg r6,r3 // start to compute ptr alignment
+ lwz r10,8(r4)
+ lwz r11,12(r4)
+ b __memset_pattern_common
+
+
+/* ***********************************
+ * * _ M E M S E T _ P A T T E R N 8 *
+ * ***********************************
+ *
+ * Used to store an 8-byte pattern in memory:
+ *
+ * void _memset_pattern8(void *b, const void *c8, size_t len);
+ *
+ * Where c8 points to the 8-byte pattern. None of the parameters need be aligned.
+ */
+
+ .globl __memset_pattern8
+ .align 5
+__memset_pattern8:
+ lwz r7,0(r4) // load pattern (these remain lwz in 64-bit mode)
+ lwz r9,4(r4)
+ cmplgi cr1,r5,kShort // check length
+ neg r6,r3 // start to compute ptr alignment
+ mr r10,r7 // replicate into 16-byte pattern
+ mr r11,r9
+ b __memset_pattern_common
+
+
+/* ***********************************
+ * * _ M E M S E T _ P A T T E R N 4 *
+ * ***********************************
+ *
+ * Used to store a 4-byte pattern in memory:
+ *
+ * void _memset_pattern4(void *b, const void *c4, size_t len);
+ *
+ * Where c4 points to the 4-byte pattern. None of the parameters need be aligned.
+ */
+
+ .globl __memset_pattern4
+ .align 5
+__memset_pattern4:
+ lwz r7,0(r4) // load pattern
+ cmplgi cr1,r5,kShort // check length
+ neg r6,r3 // start to compute ptr alignment
+ mr r9,r7 // replicate into 16-byte pattern
+ mr r10,r7
+ mr r11,r7
+ b __memset_pattern_common // don't fall through because of scatter-loading
+
+
+/* ***********************************************
+ * * _ M E M S E T _ P A T T E R N _ C O M M O N *
+ * ***********************************************
+ *
+ * This is the common code used by _memset_patter16, 8, and 4. They all get here via
+ * long branch (ie, "b") in case the routines are re-ordered, with:
+ * r3 = ptr to memory to store pattern into (unaligned)
+ * r5 = length in bytes
+ * r6 = neg(r3), used to compute #bytes to align
+ * r7, r9, r10, r11 = 16-byte pattern to store
+ * cr1= ble if (r5 <= kShort)
+ */
+
+ .globl __memset_pattern_common
+ .align 5
+__memset_pattern_common:
+ andi. r0,r6,0xF // get #bytes to 16-byte align ptr
+ ble-- cr1,LShort // if short operand skip out
+
+ // Align ptr and store enough of pattern so we have an aligned
+ // 16-byte chunk of it (this effectively rotates incoming pattern
+ // if the original ptr was not aligned.)
+
+ stw r7,0(r3)
+ stw r9,4(r3)
+ stw r10,8(r3)
+ stw r11,12(r3)
+ beq Laligned // skip if (r0==0), ie if r3 is 16-byte aligned
+ stw r7,16(r3)
+ stw r9,20(r3)
+ stw r10,24(r3)
+ stw r11,28(r3)
+ add r3,r3,r0 // 16-byte align ptr
+ sub r5,r5,r0 // adjust length
+
+ // We're ready to call the machine-specific commpage routine
+ // to do the heavy lifting. When called, _COMM_PAGE_MEMSET_PATTERN expects:
+ // r4 = length (>= 32)
+ // r8 = ptr (16-byte aligned)
+ // r9 = ptr to 16-byte pattern (16-byte aligned)
+ // When it returns:
+ // r3, r7, and r12 are preserved
+ // r4 and r8 are updated to reflect a residual count of from 0..31 bytes
+
+Laligned:
+ mflr r12 // save return across commpage call
+ mr r9,r3 // point to 16-byte aligned 16-byte pattern
+ addi r8,r3,16 // point to first unstored byte (r8 is 16-byte aligned)
+ subi r4,r5,16 // account for the aligned bytes we have stored
+ bla _COMM_PAGE_MEMSET_PATTERN
+ mr. r5,r4 // move length (0..31) back to original reg and test for 0
+ mtlr r12
+ beqlr // done if residual length == 0
+ lwz r7,-16(r8) // load aligned pattern into r7,r9,r10, and r11
+ lwz r9,-12(r8)
+ mr r3,r8 // move destination ptr back
+ lwz r10,-8(r8)
+ lwz r11,-4(r8)
+
+ // Handle short operands and leftovers.
+ // r3 = dest
+ // r5 = length
+ // r7,r9,r10,r11 = pattern
+LShort:
+ srgi. r0,r5,4 // at least 16 bytes?
+ mtcrf 0x01,r5 // move leftover count to cr7
+ beq Lleftovers
+ mtctr r0
+LShortLoop:
+ stw r7,0(r3) // replicate the pattern
+ stw r9,4(r3)
+ stw r10,8(r3)
+ stw r11,12(r3)
+ addi r3,r3,16
+ bdnz LShortLoop // store 16 more bytes
+
+ // Fewer than 16 bytes remaining.
+Lleftovers:
+ bf 28,1f
+ stw r7,0(r3) // store next 8 bytes
+ stw r9,4(r3)
+ addi r3,r3,8
+ mr r7,r10 // shift pattern over
+ mr r9,r11
+1:
+ bf 29,2f
+ stw r7,0(r3)
+ addi r3,r3,4
+ mr r7,r9
+2:
+ bf 30,3f
+ rlwinm r7,r7,16,0,31 // position leftmost 2 bytes for store
+ sth r7,0(r3)
+ addi r3,r3,2
+3:
+ bflr 31
+ srwi r7,r7,24 // position leftmost byte for store
+ stb r7,0(r3)
+ blr
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
_exit.s \
_getlogin.s \
_longjmp.s \
+ __mmap.s \
_pthread_kill.s \
+ __pthread_canceled.s \
+ __pthread_markcancel.s \
+ __semwait_signal.s \
_setjmp.s \
_setlogin.s \
_sysctl.s \
audit.s \
auditctl.s \
auditon.s \
- auditsvc.s \
bind.s \
cerror.s \
chdir.s \
getauid.s \
getdirentries.s \
getdirentriesattr.s \
+ getdtablesize.s \
getegid.s \
geteuid.s \
getfh.s \
mknod.s \
mlock.s \
mlockall.s \
- mmap.s \
mount.s \
- mprotect.s \
- msgctl.s \
msgget.s \
msgrcv.s \
msgsnd.s \
msgsys.s \
- msync.s \
munlock.s \
munlockall.s \
- munmap.s \
new_system_shared_regions.s \
nfsclnt.s \
nfssvc.s \
open.s \
pathconf.s \
pipe.s \
+ poll.s \
posix_madvise.s \
ppc_gettimeofday.s \
pread.s \
sem_trywait.s \
sem_wait.s \
semconfig.s \
- semctl.s \
semget.s \
semop.s \
semsys.s \
setuid.s \
setxattr.s \
shmat.s \
- shmctl.s \
shmdt.s \
shmget.s \
shmsys.s \
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
mtlr r12 // restore return adddress
mr r3,r11 // return original value of bit
blr
-
+
-/* void * OSAtomicDequeue( void ** inList, size_t inOffset); */
+/* int32_t OSAtomicAdd32Barrier( int32_t theAmount, int32_t *theValue ); */
-MI_ENTRY_POINT(_OSAtomicDequeue)
- ba _COMM_PAGE_DEQUEUE
-
+MI_ENTRY_POINT(_OSAtomicAdd32Barrier)
+ mflr r12 // save return address
+ mr r5,r4 // move ptr to where compare-and-swap wants it
+ mr r11,r3 // copy theAmount
+1:
+ lwz r3,0(r5) // get old value
+ add r4,r3,r11 // make new value
+ bla _COMM_PAGE_COMPARE_AND_SWAP32B // preserves r4,r5,r9-r12
+ cmpwi r3,0 // did swap occur?
+ beq-- 1b // compare-and-swap failed, try again
+ mtlr r12 // restore return adddress
+ mr r3,r4 // return new value
+ blr
+
+
+/* int32_t OSAtomicOr32Barrier( int32_t theMask, int32_t *theValue ); */
+
+MI_ENTRY_POINT(_OSAtomicOr32Barrier)
+ mflr r12 // save return address
+ mr r5,r4 // move ptr to where compare-and-swap wants it
+ mr r11,r3 // copy mask
+1:
+ lwz r3,0(r5) // get old value
+ or r4,r3,r11 // make new value
+ bla _COMM_PAGE_COMPARE_AND_SWAP32B // preserves r4,r5,r9-r12
+ cmpwi r3,0 // did swap occur?
+ beq-- 1b // compare-and-swap failed, try again
+ mtlr r12 // restore return adddress
+ mr r3,r4 // return new value
+ blr
+
+
+/* int32_t OSAtomicAnd32Barrier( int32_t theMask, int32_t *theValue ); */
+
+MI_ENTRY_POINT(_OSAtomicAnd32Barrier)
+ mflr r12 // save return address
+ mr r5,r4 // move ptr to where compare-and-swap wants it
+ mr r11,r3 // copy mask
+1:
+ lwz r3,0(r5) // get old value
+ and r4,r3,r11 // make new value
+ bla _COMM_PAGE_COMPARE_AND_SWAP32B // preserves r4,r5,r9-r12
+ cmpwi r3,0 // did swap occur?
+ beq-- 1b // compare-and-swap failed, try again
+ mtlr r12 // restore return adddress
+ mr r3,r4 // return new value
+ blr
-/* void OSAtomicEnqueue( void ** inList, void * inNewLink, size_t inOffset); */
-MI_ENTRY_POINT(_OSAtomicEnqueue)
- ba _COMM_PAGE_ENQUEUE
+/* int32_t OSAtomicXor32Barrier( int32_t theMask, int32_t *theValue ); */
+
+MI_ENTRY_POINT(_OSAtomicXor32Barrier)
+ mflr r12 // save return address
+ mr r5,r4 // move ptr to where compare-and-swap wants it
+ mr r11,r3 // copy mask
+1:
+ lwz r3,0(r5) // get old value
+ xor r4,r3,r11 // make new value
+ bla _COMM_PAGE_COMPARE_AND_SWAP32B // preserves r4,r5,r9-r12
+ cmpwi r3,0 // did swap occur?
+ beq-- 1b // compare-and-swap failed, try again
+ mtlr r12 // restore return adddress
+ mr r3,r4 // return new value
+ blr
+
+
+/* int64_t OSAtomicAdd64Barrier( int64_t theAmount, int64_t *theValue ); */
+
+#if defined(__ppc64__)
+MI_ENTRY_POINT(_OSAtomicAdd64Barrier)
+ mflr r12 // save return address
+ mr r5,r4 // move ptr to where compare-and-swap wants it
+ mr r11,r3 // copy theAmount
+1:
+ ld r3,0(r5) // get old value
+ add r4,r3,r11 // make new value
+ bla _COMM_PAGE_COMPARE_AND_SWAP64B // preserves r4,r5,r9-r12
+ cmpwi r3,0 // did swap occur?
+ beq-- 1b // compare-and-swap failed, try again
+ mtlr r12 // restore return adddress
+ mr r3,r4 // return new value
+ blr
+#endif /* defined(__ppc64__) */
+
+
+/* bool OSAtomicCompareAndSwap32Barrier( int32_t oldValue, int32_t newValue, int32_t *theValue ); */
+
+MI_ENTRY_POINT(_OSAtomicCompareAndSwap32Barrier)
+ ba _COMM_PAGE_COMPARE_AND_SWAP32B
+/* bool OSAtomicCompareAndSwap64Barrier( int364_t oldValue, int64_t newValue, int64_t *theValue ); */
+
+#if defined(__ppc64__)
+MI_ENTRY_POINT(_OSAtomicCompareAndSwap64Barrier)
+ ba _COMM_PAGE_COMPARE_AND_SWAP64B
+#endif /* defined(__ppc64__) */
+
+
+/* bool OSAtomicTestAndSetBarrier( uint32_t n, void *theAddress ); */
+
+MI_ENTRY_POINT(_OSAtomicTestAndSetBarrier)
+ mflr r12 // save return
+ srwi r5,r3,3 // get byte offset of n
+ rlwinm r6,r3,0,0x7 // get bit position within byte
+ add r4,r4,r5 // r4 points to byte containing the bit
+ lis r10,0x8000 // light bit 0
+ rlwimi r6,r4,3,0x18 // r6 is bit position within word
+ clrrgi r5,r4,2 // point to word containing the bit
+ srw r10,r10,r6 // get mask for bit
+ addi r9,r6,1 // save bit position + 1
+1:
+ lwz r3,0(r5) // get old word
+ rlwnm r11,r3,r9,0x1 // right justify old value of bit
+ or r4,r3,r10 // set it in new word
+ bla _COMM_PAGE_COMPARE_AND_SWAP32B // preserves r4,r5,r9-r12
+ cmpwi r3,0 // did swap occur?
+ beq-- 1b // compare-and-swap failed, try again
+ mtlr r12 // restore return adddress
+ mr r3,r11 // return original value of bit
+ blr
+
+
+/* bool OSAtomicTestAndClearBarrier( uint32_t n, void *theAddress ); */
+
+MI_ENTRY_POINT(_OSAtomicTestAndClearBarrier)
+ mflr r12 // save return
+ srwi r5,r3,3 // get byte offset of n
+ rlwinm r6,r3,0,0x7 // get bit position within byte
+ add r4,r4,r5 // r4 points to byte containing the bit
+ lis r10,0x8000 // light bit 0
+ rlwimi r6,r4,3,0x18 // r6 is bit position within word
+ clrrgi r5,r4,2 // point to word containing the bit
+ srw r10,r10,r6 // get mask for bit
+ addi r9,r6,1 // save bit position + 1
+1:
+ lwz r3,0(r5) // get old word
+ rlwnm r11,r3,r9,0x1 // right justify old value of bit
+ andc r4,r3,r10 // clear it in new word
+ bla _COMM_PAGE_COMPARE_AND_SWAP32B // preserves r4,r5,r9-r12
+ cmpwi r3,0 // did swap occur?
+ beq-- 1b // compare-and-swap failed, try again
+ mtlr r12 // restore return adddress
+ mr r3,r11 // return original value of bit
+ blr
+
/* bool OSSpinLockTry( OSSpinLock *lock ); */
MI_ENTRY_POINT(_OSSpinLockTry)
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* Macros.
*/
+/*
+ * This is the same as SYSCALL, but it can call an alternate error
+ * return function. It's generic to support potential future callers.
+ */
+#define SYSCALL_ERR(name, nargs, error_ret) \
+ .globl error_ret @\
+ MI_ENTRY_POINT(_##name) @\
+ kernel_trap_args_##nargs @\
+ li r0,SYS_##name @\
+ sc @\
+ b 1f @\
+ blr @\
+1: MI_BRANCH_EXTERNAL(error_ret)
+
#define SYSCALL(name, nargs) \
.globl cerror @\
MI_ENTRY_POINT(_##name) @\
#undef END
#import <mach/ppc/syscall_sw.h>
+#if !defined(SYS___pthread_canceled)
+#define SYS___pthread_markcancel 332
+#define SYS___pthread_canceled 333
+#define SYS___semwait_signal 334
+#endif
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include "SYS.h"
+
+PSEUDO(__mmap, mmap, 6)
+ blr
--- /dev/null
+/*
+ * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include "SYS.h"
+
+SYSCALL(__pthread_canceled, 1)
+
+
--- /dev/null
+/*
+ * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include "SYS.h"
+
+SYSCALL(__pthread_markcancel, 1)
+
+
--- /dev/null
+/*
+ * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include "SYS.h"
+
+SYSCALL(__semwait_signal, 6)
+
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
+#ifdef __LP64__
SYSCALL(accept, 3)
+#else /* !__LP64__ */
+PSEUDO(accept$UNIX2003, accept, 3)
+ blr
+
+SYSCALL_ERR(accept, 3, cerror_cvt)
+#endif /* __LP64__ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
+#ifdef __LP64__
SYSCALL(bind, 3)
+#else /* !__LP64__ */
+PSEUDO(bind$UNIX2003, bind, 3)
+ blr
+SYSCALL_ERR(bind, 3, cerror_cvt)
+#endif /* __LP64__ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
.globl _errno
+#if 0
+MI_ENTRY_POINT(cerror_cvt)
+ MI_PUSH_STACK_FRAME
+ MI_GET_ADDRESS(r12,_errno)
+ cmplwi r3,102 /* EOPNOTSUPP? */
+ bne 1f
+ li r3,45 /* Yes; make ENOTSUP for compatibility */
+1:
+ stw r3,0(r12) /* save syscall return code in global */
+ MI_CALL_EXTERNAL(_cthread_set_errno_self)
+ li r3,-1 /* then bug return value */
+ li r4,-1 /* in case we're returning a long-long in 32-bit mode, etc */
+ MI_POP_STACK_FRAME_AND_RETURN
+#endif
+
+MI_ENTRY_POINT(cerror_cvt)
+ cmplwi r3,102 /* EOPNOTSUPP? */
+ bne 1f
+ li r3,45 /* Yes; make ENOTSUP for compatibility */
+1:
MI_ENTRY_POINT(cerror)
MI_PUSH_STACK_FRAME
MI_GET_ADDRESS(r12,_errno)
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
+#ifdef __LP64__
SYSCALL(connect, 3)
+#else /* !__LP64__ */
+PSEUDO(connect$UNIX2003, connect, 3)
+ blr
+
+SYSCALL_ERR(connect, 3, cerror_cvt)
+#endif /* __LP64__ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
-SYSCALL(fgetxattr, 5)
+SYSCALL(fgetxattr, 6)
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
-SYSCALL(fsetxattr, 5)
+SYSCALL(fsetxattr, 6)
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#include "SYS.h"
+#ifdef __LP64__
SYSCALL(getattrlist, 0)
+#else /* !__LP64__ */
+PSEUDO(getattrlist$UNIX2003, getattrlist, 0)
+ blr
+
+SYSCALL_ERR(getattrlist, 0, cerror_cvt)
+#endif /* __LP64__ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include "SYS.h"
+
+SYSCALL(getdtablesize, 0)
+
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
+#ifdef __LP64__
SYSCALL(getpeername, 3)
+#else /* !__LP64__ */
+PSEUDO(getpeername$UNIX2003, getpeername, 3)
+ blr
+
+SYSCALL_ERR(getpeername, 3, cerror_cvt)
+#endif /* __LP64__ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
+#ifdef __LP64__
SYSCALL(getsockname, 3)
+#else /* !__LP64__ */
+PSEUDO(getsockname$UNIX2003, getsockname, 3)
+ blr
+
+SYSCALL_ERR(getsockname, 3, cerror_cvt)
+#endif /* __LP64__ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
-SYSCALL(getxattr, 5)
+SYSCALL(getxattr, 6)
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
/*
- * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
+#ifdef __LP64__
SYSCALL(lchown, 3)
+#else /* !__LP64__ */
+PSEUDO(lchown$UNIX2003, lchown, 3)
+ blr
+SYSCALL_ERR(lchown, 3, cerror_cvt)
+#endif /* __LP64__ */
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include <architecture/ppc/asm_help.h>
+
+#define BRANCH(X, Y) \
+TEXT @ \
+LABEL(X) @ \
+BRANCH_EXTERN(Y)
+
+BRANCH(_asl_log$LDBL64, _asl_log)
+BRANCH(_asl_vlog$LDBL64, _asl_vlog)
+BRANCH(_asprintf$LDBL64, _asprintf)
+BRANCH(_err$LDBL64, _err)
+BRANCH(_errc$LDBL64, _errc)
+BRANCH(_errx$LDBL64, _errx)
+BRANCH(_fprintf$LDBL64, _fprintf)
+BRANCH(_fscanf$LDBL64, _fscanf)
+BRANCH(_fwprintf$LDBL64, _fwprintf)
+BRANCH(_fwscanf$LDBL64, _fwscanf)
+BRANCH(_printf$LDBL64, _printf)
+BRANCH(_scanf$LDBL64, _scanf)
+BRANCH(_snprintf$LDBL64, _snprintf)
+BRANCH(_sprintf$LDBL64, _sprintf)
+BRANCH(_sscanf$LDBL64, _sscanf)
+BRANCH(_strtold$LDBL64, _strtold)
+BRANCH(_swprintf$LDBL64, _swprintf)
+BRANCH(_swscanf$LDBL64, _swscanf)
+BRANCH(_syslog$LDBL64, _syslog)
+BRANCH(_vasprintf$LDBL64, _vasprintf)
+BRANCH(_verr$LDBL64, _verr)
+BRANCH(_verrc$LDBL64, _verrc)
+BRANCH(_verrx$LDBL64, _verrx)
+BRANCH(_vfprintf$LDBL64, _vfprintf)
+BRANCH(_vfscanf$LDBL64, _vfscanf)
+BRANCH(_vfwprintf$LDBL64, _vfwprintf)
+BRANCH(_vfwscanf$LDBL64, _vfwscanf)
+BRANCH(_vprintf$LDBL64, _vprintf)
+BRANCH(_vscanf$LDBL64, _vscanf)
+BRANCH(_vsnprintf$LDBL64, _vsnprintf)
+BRANCH(_vsprintf$LDBL64, _vsprintf)
+BRANCH(_vsscanf$LDBL64, _vsscanf)
+BRANCH(_vswprintf$LDBL64, _vswprintf)
+BRANCH(_vswscanf$LDBL64, _vswscanf)
+BRANCH(_vsyslog$LDBL64, _vsyslog)
+BRANCH(_vwarn$LDBL64, _vwarn)
+BRANCH(_vwarnc$LDBL64, _vwarnc)
+BRANCH(_vwarnx$LDBL64, _vwarnx)
+BRANCH(_vwprintf$LDBL64, _vwprintf)
+BRANCH(_vwscanf$LDBL64, _vwscanf)
+BRANCH(_warn$LDBL64, _warn)
+BRANCH(_warnc$LDBL64, _warnc)
+BRANCH(_warnx$LDBL64, _warnx)
+BRANCH(_wcstold$LDBL64, _wcstold)
+BRANCH(_wprintf$LDBL64, _wprintf)
+BRANCH(_wscanf$LDBL64, _wscanf)
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
+#ifdef __LP64__
SYSCALL(listen, 2)
+#else /* !__LP64__ */
+PSEUDO(listen$UNIX2003, listen, 2)
+ blr
+
+SYSCALL_ERR(listen, 2, cerror_cvt)
+#endif /* __LP64__ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
+++ /dev/null
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-#include "SYS.h"
-
-SYSCALL(mmap, 6)
-
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
+++ /dev/null
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-/* Copyright 1998 Apple Computer, Inc. */
-
-#include "SYS.h"
-
-SYSCALL(mprotect, 3)
+++ /dev/null
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-#include "SYS.h"
-
-SYSCALL(msgctl, 3)
-
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
+++ /dev/null
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-/* Copyright 1998 Apple Computer, Inc. */
-
-#include "SYS.h"
-
-SYSCALL(msync, 3)
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
+++ /dev/null
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-#include "SYS.h"
-
-SYSCALL(munmap, 2)
-
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include <architecture/ppc/asm_help.h>
+
+#define BRANCH(X, Y) \
+TEXT @ \
+LABEL(X) @ \
+BRANCH_EXTERN(Y)
+
+BRANCH(_asprintf$LDBL64, _asprintf)
+BRANCH(_err$LDBL64, _err)
+BRANCH(_errc$LDBL64, _errc)
+BRANCH(_errx$LDBL64, _errx)
+BRANCH(_fprintf$LDBL64, _fprintf)
+BRANCH(_fscanf$LDBL64, _fscanf)
+BRANCH(_fwprintf$LDBL64, _fwprintf)
+BRANCH(_fwscanf$LDBL64, _fwscanf)
+BRANCH(_printf$LDBL64, _printf)
+BRANCH(_scanf$LDBL64, _scanf)
+BRANCH(_snprintf$LDBL64, _snprintf)
+BRANCH(_sprintf$LDBL64, _sprintf)
+BRANCH(_sscanf$LDBL64, _sscanf)
+BRANCH(_strtold$LDBL64, _strtold)
+BRANCH(_swprintf$LDBL64, _swprintf)
+BRANCH(_swscanf$LDBL64, _swscanf)
+BRANCH(_syslog$LDBL64, _syslog)
+BRANCH(_vasprintf$LDBL64, _vasprintf)
+BRANCH(_verr$LDBL64, _verr)
+BRANCH(_verrc$LDBL64, _verrc)
+BRANCH(_verrx$LDBL64, _verrx)
+BRANCH(_vfprintf$LDBL64, _vfprintf)
+BRANCH(_vfscanf$LDBL64, _vfscanf)
+BRANCH(_vfwprintf$LDBL64, _vfwprintf)
+BRANCH(_vfwscanf$LDBL64, _vfwscanf)
+BRANCH(_vprintf$LDBL64, _vprintf)
+BRANCH(_vscanf$LDBL64, _vscanf)
+BRANCH(_vsnprintf$LDBL64, _vsnprintf)
+BRANCH(_vsprintf$LDBL64, _vsprintf)
+BRANCH(_vsscanf$LDBL64, _vsscanf)
+BRANCH(_vswprintf$LDBL64, _vswprintf)
+BRANCH(_vswscanf$LDBL64, _vswscanf)
+BRANCH(_vsyslog$LDBL64, _vsyslog)
+BRANCH(_vwarn$LDBL64, _vwarn)
+BRANCH(_vwarnc$LDBL64, _vwarnc)
+BRANCH(_vwarnx$LDBL64, _vwarnx)
+BRANCH(_vwprintf$LDBL64, _vwprintf)
+BRANCH(_vwscanf$LDBL64, _vwscanf)
+BRANCH(_warn$LDBL64, _warn)
+BRANCH(_warnc$LDBL64, _warnc)
+BRANCH(_warnx$LDBL64, _warnx)
+BRANCH(_wcstold$LDBL64, _wcstold)
+BRANCH(_wprintf$LDBL64, _wprintf)
+BRANCH(_wscanf$LDBL64, _wscanf)
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include "SYS.h"
+
+SYSCALL(poll, 3)
+
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
MI_ENTRY_POINT(___commpage_gettimeofday)
ba _COMM_PAGE_GETTIMEOFDAY
-
+
+/* This syscall is special cased: the timeval is returned in r3/r4.
+ * Note also that the "seconds" field of the timeval is a long, so
+ * it's size is mode dependent.
+ */
MI_ENTRY_POINT(___ppc_gettimeofday)
mr r12,r3 // save ptr to timeval
SYSCALL_NONAME(gettimeofday,0)
mr. r12,r12 // was timeval ptr null?
beq 3f
- stw r3,0(r12)
- stw r4,4(r12)
+ stg r3,0(r12) // "stw" in 32-bit mode, "std" in 64-bit mode
+ stw r4,GPR_BYTES(r12)
li r3,0
3:
blr
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
+#ifdef __LP64__
SYSCALL(recvfrom, 6)
+#else /* !__LP64__ */
+PSEUDO(recvfrom$UNIX2003, recvfrom, 6)
+ blr
+
+SYSCALL_ERR(recvfrom, 6, cerror_cvt)
+#endif /* __LP64__ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
+#ifdef __LP64__
SYSCALL(recvmsg, 3)
+#else /* !__LP64__ */
+PSEUDO(recvmsg$UNIX2003, recvmsg, 3)
+ blr
+
+SYSCALL_ERR(recvmsg, 3, cerror_cvt)
+#endif /* __LP64__ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
+++ /dev/null
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-#include "SYS.h"
-
-SYSCALL(semctl, 3)
-
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
+#ifdef __LP64__
SYSCALL(sendmsg, 3)
+#else /* !__LP64__ */
+PSEUDO(sendmsg$UNIX2003, sendmsg, 3)
+ blr
+
+SYSCALL_ERR(sendmsg, 3, cerror_cvt)
+#endif /* __LP64__ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
+#ifdef __LP64__
SYSCALL(sendto, 6)
+#else /* !__LP64__ */
+PSEUDO(sendto$UNIX2003, sendto, 6)
+ blr
+
+SYSCALL_ERR(sendto, 6, cerror_cvt)
+#endif /* __LP64__ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#include "SYS.h"
+#ifdef __LP64__
SYSCALL(setattrlist, 0)
+#else /* !__LP64__ */
+PSEUDO(setattrlist$UNIX2003, setattrlist, 0)
+ blr
+
+SYSCALL_ERR(setattrlist, 0, cerror_cvt)
+#endif /* __LP64__ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
-SYSCALL(setxattr, 5)
+SYSCALL(setxattr, 6)
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
+++ /dev/null
-/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-#include "SYS.h"
-
-SYSCALL(shmctl, 3)
-
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*/
#include "SYS.h"
+#ifdef __LP64__
SYSCALL(socketpair, 5)
+#else /* !__LP64__ */
+PSEUDO(socketpair$UNIX2003, socketpair, 5)
+ blr
+
+SYSCALL_ERR(socketpair, 5, cerror_cvt)
+#endif /* __LP64__ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
MDSRCS += \
abs.s \
- ecvt.c \
ffs.s \
fp.h \
icacheinval.s \
# searching ppc directory as a fallback to avoid unnecessary code duplication
-.PATH: ${.CURDIR}/ppc/pthreads
+.PATH: ${.CURDIR}/ppc64/pthreads ${.CURDIR}/ppc/pthreads
MDSRCS += \
init_cpu_capabilities.c \
get_cpu_capabilities.s \
- pthread_set_self.s \
- pthread_self.s \
- pthread_getspecific.s
+ pthread_set_self_64.s \
+ pthread_self_64.s \
+ pthread_getspecific_64.s
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include "pthread_machdep.h"
+
+#define __APPLE_API_PRIVATE
+#include <machine/cpu_capabilities.h>
+#undef __APPLE_API_PRIVATE
+
+ .text
+ .align 4
+ .globl _pthread_getspecific
+_pthread_getspecific:
+ sldi r4, r3, 3 // multiply index by 8 to get byte offset
+ addi r5, r13, _PTHREAD_TSD_OFFSET // add offset of TSD array in pthread struct
+ ldx r3, r4, r5
+ blr
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#define __APPLE_API_PRIVATE
+#include <machine/cpu_capabilities.h>
+#undef __APPLE_API_PRIVATE
+
+ .text
+ .align 2
+ .globl _pthread_self
+_pthread_self:
+ mr r3, r13
+ blr
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+ .text
+ .align 2
+ .globl ___pthread_set_self
+___pthread_set_self:
+ mr r13, r3
+ blr
-.PATH: ${.CURDIR}/ppc/stdlib
-# Long double is just double precision.
-FBSDSRCS+=machdep_ldisd.c
+# Long double is head-tail pair of doubles
+FBSDSRCS+= gdtoa-strtopdd.c machdep_ldisdd.c _ldbl_util.c
MDSRCS += \
bcopy.s \
bzero.s \
+ memset.s \
memcmp.s \
strcat.s \
strcmp.s \
# searching ppc directory as a fallback to avoid unnecessary code duplication
-.PATH: ${.CURDIR}/ppc/sys
+.PATH: ${.CURDIR}/ppc/sys ${.CURDIR}/ppc64/sys
MDSRCS+= ATPgetreq.s \
ATPgetrsp.s \
ATsocket.s \
OSAtomic.s \
_exit.s \
+ __fcntl.s \
_getlogin.s \
+ __ioctl.s \
_longjmp.s \
+ __mmap.s \
_pthread_kill.s \
+ __pthread_canceled.s \
+ __pthread_markcancel.s \
+ __semwait_signal.s \
_setjmp.s \
_setlogin.s \
_sysctl.s \
audit.s \
auditctl.s \
auditon.s \
- auditsvc.s \
bind.s \
cerror.s \
chdir.s \
fchflags.s \
fchmod.s \
fchown.s \
- fcntl.s \
fgetxattr.s \
fhopen.s \
flistxattr.s \
getauid.s \
getdirentries.s \
getdirentriesattr.s \
+ getdtablesize.s \
getegid.s \
geteuid.s \
getfh.s \
getsockopt.s \
getuid.s \
getxattr.s \
- ioctl.s \
issetugid.s \
kevent.s \
kill.s \
kqueue_from_portset_np.s \
kqueue_portset_np.s \
ktrace.s \
+ lchown.s \
link.s \
lio_listio.s \
listen.s \
mknod.s \
mlock.s \
mlockall.s \
- mmap.s \
mount.s \
- mprotect.s \
msgctl.s \
msgget.s \
msgrcv.s \
msgsnd.s \
msgsys.s \
- msync.s \
munlock.s \
munlockall.s \
- munmap.s \
new_system_shared_regions.s \
nfsclnt.s \
nfssvc.s \
open.s \
pathconf.s \
pipe.s \
+ poll.s \
posix_madvise.s \
ppc_gettimeofday.s \
pread.s \
write.s \
writev.s
+MISRCS+= fcntl64.c ioctl64.c
+
.for _src in fhopen.s getfh.s nfsclnt.s
CFLAGS-${_src} += -DNFSCLIENT
.endfor
CFLAGS-nfssvc.s += -DNFSSERVER
+
+# for ppc64-specific assembly code, use the SYS.h in ppc/sys
+.for _src in __fcntl.s __ioctl.s
+CFLAGS-${_src} += -I${.CURDIR}/ppc/sys
+.endfor
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include "SYS.h"
+
+PSEUDO(__fcntl, fcntl, 3)
+ blr
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include "SYS.h"
+
+PSEUDO(__ioctl, ioctl, 3)
+ blr
PTHREADS_INSTHDRS := ${PTHREADS_INSTHDRS:S/^/${.CURDIR}\/pthreads\//}
INSTHDRS += ${PTHREADS_INSTHDRS}
+UNIX03SRCS += pthread.c pthread_cond.c
+
.if ${LIB} == "c"
-MAN3+= pthread.3 pthread_attr.3 pthread_cancel.3 \
+MAN3+= pthread.3 pthread_atfork.3 pthread_attr.3 pthread_cancel.3 \
pthread_cleanup_pop.3 pthread_cleanup_push.3 \
pthread_cond_broadcast.3 pthread_cond_destroy.3 \
pthread_cond_init.3 pthread_cond_signal.3 \
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
printf(" * Internal implementation details\n");
printf(" */\n");
printf("\n");
- printf("#define __PTHREAD_SIZE__ %ld\n", (long) sizeof(struct _pthread)-sizeof(long));
- printf("#define __PTHREAD_ATTR_SIZE__ %ld\n", (long) sizeof(pthread_attr_t)-sizeof(long));
- printf("#define __PTHREAD_MUTEXATTR_SIZE__ %ld\n", (long) sizeof(pthread_mutexattr_t)-sizeof(long));
- printf("#define __PTHREAD_MUTEX_SIZE__ %ld\n", (long) sizeof(pthread_mutex_t)-sizeof(long));
- printf("#define __PTHREAD_CONDATTR_SIZE__ %ld\n", (long) sizeof(pthread_condattr_t)-sizeof(long));
- printf("#define __PTHREAD_COND_SIZE__ %ld\n", (long) sizeof(pthread_cond_t)-sizeof(long));
- printf("#define __PTHREAD_ONCE_SIZE__ %ld\n", (long) sizeof(pthread_once_t)-sizeof(long));
+ printf("#define __PTHREAD_SIZE__ %zd\n", sizeof(struct _pthread)-sizeof(long));
+ printf("#define __PTHREAD_ATTR_SIZE__ %zd\n", sizeof(pthread_attr_t)-sizeof(long));
+ printf("#define __PTHREAD_MUTEXATTR_SIZE__ %zd\n", sizeof(pthread_mutexattr_t)-sizeof(long));
+ printf("#define __PTHREAD_MUTEX_SIZE__ %zd\n", sizeof(pthread_mutex_t)-sizeof(long));
+ printf("#define __PTHREAD_CONDATTR_SIZE__ %zd\n", sizeof(pthread_condattr_t)-sizeof(long));
+ printf("#define __PTHREAD_COND_SIZE__ %zd\n", sizeof(pthread_cond_t)-sizeof(long));
+ printf("#define __PTHREAD_ONCE_SIZE__ %zd\n", sizeof(pthread_once_t)-sizeof(long));
+ printf("#define __PTHREAD_sig_OFFSET__ %zd\n", offsetof(struct _pthread, sig));
+ printf("#define __PTHREAD_cleanup_stack_OFFSET__ %zd\n", offsetof(struct _pthread, __cleanup_stack));
+ printf("#define __PTHREAD_guardsize_OFFSET__ %zd\n", offsetof(struct _pthread, guardsize));
+ printf("#define __PTHREAD_param_OFFSET__ %zd\n", offsetof(struct _pthread, param));
+ printf("#define __PTHREAD_mutexes_OFFSET__ %zd\n", offsetof(struct _pthread, mutexes));
+ printf("#define __PTHREAD_joiner_OFFSET__ %zd\n", offsetof(struct _pthread, joiner));
+ printf("#define __PTHREAD_exit_value_OFFSET__ %zd\n", offsetof(struct _pthread, exit_value));
+ printf("#define __PTHREAD_death_OFFSET__ %zd\n", offsetof(struct _pthread, death));
+ printf("#define __PTHREAD_kernel_thread_OFFSET__ %zd\n", offsetof(struct _pthread, kernel_thread));
+ printf("#define __PTHREAD_fun_OFFSET__ %zd\n", offsetof(struct _pthread, fun));
+ printf("#define __PTHREAD_arg_OFFSET__ %zd\n", offsetof(struct _pthread, arg));
+ printf("#define __PTHREAD_cancel_state_OFFSET__ %zd\n", offsetof(struct _pthread, cancel_state));
+ printf("#define __PTHREAD_err_no_OFFSET__ %zd\n", offsetof(struct _pthread, err_no));
+ printf("#define __PTHREAD_tsd_OFFSET__ %zd\n", offsetof(struct _pthread, tsd));
+ printf("#define __PTHREAD_stackaddr_OFFSET__ %zd\n", offsetof(struct _pthread, stackaddr));
+ printf("#define __PTHREAD_stacksize_OFFSET__ %zd\n", offsetof(struct _pthread, stacksize));
+ printf("#define __PTHREAD_reply_port_OFFSET__ %zd\n", offsetof(struct _pthread, reply_port));
+ printf("#define __PTHREAD_cthread_self_OFFSET__ %zd\n", offsetof(struct _pthread, cthread_self));
+ printf("#define __PTHREAD_freeStackOnExit_OFFSET__ %zd\n", offsetof(struct _pthread, freeStackOnExit));
+ printf("#define __PTHREAD_plist_OFFSET__ %zd\n", offsetof(struct _pthread, plist));
printf("/*\n");
printf(" * [Internal] data structure signatures\n");
printf(" */\n");
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
.Fn pthread_self void
.Xc
Returns the thread ID of the calling thread.
+.It Xo
+.Ft int
+.Fn pthread_atfork "void (*prepare)(void)" "void (*parent)(void)" "void (*child)(void)"
+.Xc
+Registers handlers to be called before and after
+.Fn fork
.El
.Sh ATTRIBUTE OBJECT ROUTINES
.Bl -tag -width Er
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#define __APPLE_API_PRIVATE
#include <machine/cpu_capabilities.h>
+
+#ifndef BUILDING_VARIANT /* [ */
+
__private_extern__ struct __pthread_list __pthread_head = LIST_HEAD_INITIALIZER(&__pthread_head);
/* Per-thread kernel support */
/* Used when we need to call into the kernel with no reply port */
extern pthread_lock_t reply_port_lock;
+/* Mach message used to notify that a thread needs to be reaped */
+
+typedef struct _pthread_reap_msg_t {
+ mach_msg_header_t header;
+ pthread_t thread;
+ mach_msg_trailer_t trailer;
+} pthread_reap_msg_t;
+
/* We'll implement this when the main thread is a pthread */
/* Use the local _pthread struct to avoid malloc before our MiG reply port is set */
static struct _pthread _thread = {0};
int __is_threaded = 0;
/* _pthread_count is protected by _pthread_list_lock */
static int _pthread_count = 1;
+int __unix_conforming = 0;
+
__private_extern__ pthread_lock_t _pthread_list_lock = LOCK_INITIALIZER;
static int min_priority;
static int pthread_concurrency;
+static void _pthread_exit(pthread_t self, void *value_ptr);
+
/*
* [Internal] stack support
*/
_pthread_allocate_stack(pthread_attr_t *attrs, void **stack)
{
kern_return_t kr;
+ vm_address_t stackaddr;
size_t guardsize;
#if 1
assert(attrs->stacksize >= PTHREAD_STACK_MIN);
if (attrs->stackaddr != NULL) {
/* No guard pages setup in this case */
- assert(((vm_address_t)(attrs->stackaddr) & (vm_page_size - 1)) == 0);
+ assert(((uintptr_t)attrs->stackaddr % vm_page_size) == 0);
*stack = attrs->stackaddr;
return 0;
}
- guardsize = attrs->guardsize;
- *((vm_address_t *)stack) = PTHREAD_STACK_HINT;
- kr = vm_map(mach_task_self(), (vm_address_t *)stack,
+ guardsize = attrs->guardsize;
+ stackaddr = PTHREAD_STACK_HINT;
+ kr = vm_map(mach_task_self(), &stackaddr,
attrs->stacksize + guardsize,
vm_page_size-1,
VM_MAKE_TAG(VM_MEMORY_STACK)| VM_FLAGS_ANYWHERE , MEMORY_OBJECT_NULL,
VM_INHERIT_DEFAULT);
if (kr != KERN_SUCCESS)
kr = vm_allocate(mach_task_self(),
- (vm_address_t *)stack, attrs->stacksize + guardsize,
+ &stackaddr, attrs->stacksize + guardsize,
VM_MAKE_TAG(VM_MEMORY_STACK)| VM_FLAGS_ANYWHERE);
if (kr != KERN_SUCCESS) {
return EAGAIN;
/* The guard page is at the lowest address */
/* The stack base is the highest address */
if (guardsize)
- kr = vm_protect(mach_task_self(), (vm_address_t)*stack, guardsize, FALSE, VM_PROT_NONE);
- *stack += attrs->stacksize + guardsize;
+ kr = vm_protect(mach_task_self(), stackaddr, guardsize, FALSE, VM_PROT_NONE);
+ *stack = (void *)(stackaddr + attrs->stacksize + guardsize);
#else
vm_address_t cur_stack = (vm_address_t)0;
int
pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr)
{
- if ((attr->sig == _PTHREAD_ATTR_SIG) && (((vm_offset_t)stackaddr & (vm_page_size - 1)) == 0)) {
+ if ((attr->sig == _PTHREAD_ATTR_SIG) && (((uintptr_t)stackaddr % vm_page_size) == 0)) {
attr->stackaddr = stackaddr;
attr->freeStackOnExit = FALSE;
return (ESUCCESS);
pthread_attr_getstack(const pthread_attr_t *attr, void **stackaddr, size_t * stacksize)
{
if (attr->sig == _PTHREAD_ATTR_SIG) {
- u_int32_t addr = (u_int32_t)attr->stackaddr;
-
- addr -= attr->stacksize;
- *stackaddr = (void *)addr;
+ *stackaddr = (void *)((uintptr_t)attr->stackaddr - attr->stacksize);
*stacksize = attr->stacksize;
return (ESUCCESS);
} else {
pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr, size_t stacksize)
{
if ((attr->sig == _PTHREAD_ATTR_SIG) &&
- (((vm_offset_t)stackaddr & (vm_page_size - 1)) == 0) &&
- ((stacksize % vm_page_size) == 0) && (stacksize >= PTHREAD_STACK_MIN)) {
- u_int32_t addr = (u_int32_t)stackaddr;
-
- addr += stacksize;
- attr->stackaddr = (void *)addr;
+ (((uintptr_t)stackaddr % vm_page_size) == 0) &&
+ ((stacksize % vm_page_size) == 0) && (stacksize >= PTHREAD_STACK_MIN)) {
+ attr->stackaddr = (void *)((uintptr_t)stackaddr + stacksize);
attr->stacksize = stacksize;
attr->freeStackOnExit = FALSE;
return (ESUCCESS);
_pthread_body(pthread_t self)
{
_pthread_set_self(self);
- pthread_exit((self->fun)(self->arg));
+ _pthread_exit(self, (self->fun)(self->arg));
}
int
t->plist.le_next = (struct _pthread *)0;
t->plist.le_prev = (struct _pthread **)0;
t->cancel_state = PTHREAD_CANCEL_ENABLE | PTHREAD_CANCEL_DEFERRED;
- t->cleanup_stack = (struct _pthread_handler_rec *)NULL;
+ t->__cleanup_stack = (struct __darwin_pthread_handler_rec *)NULL;
t->death = SEMAPHORE_NULL;
if (kernel_thread != MACH_PORT_NULL)
/* thread underneath is terminated right away. */
static
void _pthread_become_available(pthread_t thread, mach_port_t kernel_thread) {
- mach_msg_empty_rcv_t msg;
+ pthread_reap_msg_t msg;
kern_return_t ret;
msg.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_MAKE_SEND,
msg.header.msgh_size = sizeof msg - sizeof msg.trailer;
msg.header.msgh_remote_port = thread_recycle_port;
msg.header.msgh_local_port = kernel_thread;
- msg.header.msgh_id = (int)thread;
+ msg.header.msgh_id = 0x44454144; /* 'DEAD' */
+ msg.thread = thread;
ret = mach_msg_send(&msg.header);
assert(ret == MACH_MSG_SUCCESS);
}
/* Reap the resources for available threads */
-static
+__private_extern__
int _pthread_reap_thread(pthread_t th, mach_port_t kernel_thread, void **value_ptr) {
mach_port_type_t ptype;
kern_return_t ret;
static
void _pthread_reap_threads(void)
{
- mach_msg_empty_rcv_t msg;
+ pthread_reap_msg_t msg;
kern_return_t ret;
ret = mach_msg(&msg.header, MACH_RCV_MSG|MACH_RCV_TIMEOUT, 0,
- sizeof(mach_msg_empty_rcv_t), thread_recycle_port,
+ sizeof msg, thread_recycle_port,
MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
while (ret == MACH_MSG_SUCCESS) {
mach_port_t kernel_thread = msg.header.msgh_remote_port;
- pthread_t thread = (pthread_t)msg.header.msgh_id;
+ pthread_t thread = msg.thread;
if (_pthread_reap_thread(thread, kernel_thread, (void **)0) == EAGAIN)
{
return;
}
ret = mach_msg(&msg.header, MACH_RCV_MSG|MACH_RCV_TIMEOUT, 0,
- sizeof(mach_msg_empty_rcv_t), thread_recycle_port,
+ sizeof msg, thread_recycle_port,
MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
}
}
/*
* Terminate a thread.
*/
-void
-pthread_exit(void *value_ptr)
+static void
+_pthread_exit(pthread_t self, void *value_ptr)
{
- struct _pthread_handler_rec *handler;
- pthread_t self = pthread_self();
+ struct __darwin_pthread_handler_rec *handler;
kern_return_t kern_res;
int thread_count;
/* Make this thread not to receive any signals */
syscall(331,1);
- while ((handler = self->cleanup_stack) != 0)
+ while ((handler = self->__cleanup_stack) != 0)
{
- (handler->routine)(handler->arg);
- self->cleanup_stack = handler->next;
+ (handler->__routine)(handler->__arg);
+ self->__cleanup_stack = handler->__next;
}
_pthread_tsd_cleanup(self);
abort();
}
-/*
- * Wait for a thread to terminate and obtain its exit value.
- */
-int
-pthread_join(pthread_t thread,
- void **value_ptr)
+void
+pthread_exit(void *value_ptr)
{
- kern_return_t kern_res;
- int res = ESUCCESS;
-
- if (thread->sig == _PTHREAD_SIG)
- {
- semaphore_t death = new_sem_from_pool(); /* in case we need it */
-
- LOCK(thread->lock);
- if ((thread->detached & PTHREAD_CREATE_JOINABLE) &&
- thread->death == SEMAPHORE_NULL)
- {
- pthread_t self = pthread_self();
-
- assert(thread->joiner == NULL);
- if (thread != self && (self == NULL || self->joiner != thread))
- {
- int already_exited = (thread->detached & _PTHREAD_EXITED);
-
- thread->death = death;
- thread->joiner = self;
- UNLOCK(thread->lock);
-
- if (!already_exited)
- {
- /* Wait for it to signal... */
- do {
- PTHREAD_MACH_CALL(semaphore_wait(death), kern_res);
- } while (kern_res != KERN_SUCCESS);
- }
-
- LOCK(_pthread_list_lock);
- LIST_REMOVE(thread, plist);
- UNLOCK(_pthread_list_lock);
- /* ... and wait for it to really be dead */
- while ((res = _pthread_reap_thread(thread,
- thread->kernel_thread,
- value_ptr)) == EAGAIN)
- {
- sched_yield();
- }
- } else {
- UNLOCK(thread->lock);
- res = EDEADLK;
- }
- } else {
- UNLOCK(thread->lock);
- res = EINVAL;
- }
- restore_sem_to_pool(death);
- return res;
- }
- return ESRCH;
+ _pthread_exit(pthread_self(), value_ptr);
}
/*
return (ESUCCESS); /* Spec defines no possible errors! */
}
-/*
- * Cancel a thread
- */
-int
-pthread_cancel(pthread_t thread)
-{
- if (thread->sig == _PTHREAD_SIG)
- {
- thread->cancel_state |= _PTHREAD_CANCEL_PENDING;
- return (ESUCCESS);
- } else
- {
- return (ESRCH);
- }
-}
-
/*
* Insert a cancellation point in a thread.
*/
-static void
-_pthread_testcancel(pthread_t thread)
+__private_extern__ void
+_pthread_testcancel(pthread_t thread, int isconforming)
{
LOCK(thread->lock);
if ((thread->cancel_state & (PTHREAD_CANCEL_ENABLE|_PTHREAD_CANCEL_PENDING)) ==
(PTHREAD_CANCEL_ENABLE|_PTHREAD_CANCEL_PENDING))
{
UNLOCK(thread->lock);
- pthread_exit(0);
+ if (isconforming)
+ pthread_exit(PTHREAD_CANCELED);
+ else
+ pthread_exit(0);
}
UNLOCK(thread->lock);
}
-void
-pthread_testcancel(void)
-{
- pthread_t self = pthread_self();
- _pthread_testcancel(self);
-}
-/*
- * Query/update the cancelability 'state' of a thread
- */
-int
-pthread_setcancelstate(int state, int *oldstate)
-{
- pthread_t self = pthread_self();
- int err = ESUCCESS;
- LOCK(self->lock);
- if (oldstate)
- *oldstate = self->cancel_state & ~_PTHREAD_CANCEL_STATE_MASK;
- if ((state == PTHREAD_CANCEL_ENABLE) || (state == PTHREAD_CANCEL_DISABLE))
- {
- self->cancel_state = (self->cancel_state & _PTHREAD_CANCEL_STATE_MASK) | state;
- } else
- {
- err = EINVAL;
- }
- UNLOCK(self->lock);
- _pthread_testcancel(self); /* See if we need to 'die' now... */
- return (err);
-}
-
-/*
- * Query/update the cancelability 'type' of a thread
- */
-int
-pthread_setcanceltype(int type, int *oldtype)
-{
- pthread_t self = pthread_self();
- int err = ESUCCESS;
- LOCK(self->lock);
- if (oldtype)
- *oldtype = self->cancel_state & ~_PTHREAD_CANCEL_TYPE_MASK;
- if ((type == PTHREAD_CANCEL_DEFERRED) || (type == PTHREAD_CANCEL_ASYNCHRONOUS))
- {
- self->cancel_state = (self->cancel_state & _PTHREAD_CANCEL_TYPE_MASK) | type;
- } else
- {
- err = EINVAL;
- }
- UNLOCK(self->lock);
- _pthread_testcancel(self); /* See if we need to 'die' now... */
- return (err);
-}
int
pthread_getconcurrency(void)
_init_cpu_capabilities();
-#if defined(__ppc__)
-
- /* Use fsqrt instruction in sqrt() if available. */
- if (_cpu_capabilities & kHasFsqrt) {
- extern size_t hw_sqrt_len;
- extern double sqrt( double );
- extern double hw_sqrt( double );
- extern void sys_icache_invalidate(void *, size_t);
-
- memcpy ( (void *)sqrt, (void *)hw_sqrt, hw_sqrt_len );
- sys_icache_invalidate((void *)sqrt, hw_sqrt_len);
- }
-#endif
-
#if defined(_OBJC_PAGE_BASE_ADDRESS)
{
vm_address_t objcRTPage = (vm_address_t)_OBJC_PAGE_BASE_ADDRESS;
_pthread_count = 1;
}
+#else /* !BUILDING_VARIANT ] [ */
+extern int __unix_conforming;
+extern pthread_lock_t _pthread_list_lock;
+extern void _pthread_testcancel(pthread_t thread, int isconforming);
+extern int _pthread_reap_thread(pthread_t th, mach_port_t kernel_thread, void **value_ptr);
+
+#endif /* !BUILDING_VARIANT ] */
+
+#if __DARWIN_UNIX03
+
+static void __posix_join_cleanup(void *arg)
+{
+ pthread_t thread = (pthread_t)arg;
+ int already_exited, res;
+ void * dummy;
+ semaphore_t death;
+
+ LOCK(thread->lock);
+ death = thread->death;
+ already_exited = (thread->detached & _PTHREAD_EXITED);
+
+ if (!already_exited){
+ thread->joiner = (struct _pthread *)NULL;
+ UNLOCK(thread->lock);
+ restore_sem_to_pool(death);
+ } else {
+ UNLOCK(thread->lock);
+ while ((res = _pthread_reap_thread(thread,
+ thread->kernel_thread,
+ &dummy)) == EAGAIN)
+ {
+ sched_yield();
+ }
+ restore_sem_to_pool(death);
+
+ }
+}
+
+#endif /* __DARWIN_UNIX03 */
+
+
+/*
+ * Wait for a thread to terminate and obtain its exit value.
+ */
+int
+pthread_join(pthread_t thread,
+ void **value_ptr)
+{
+ kern_return_t kern_res;
+ int res = ESUCCESS;
+
+#if __DARWIN_UNIX03
+ if (__unix_conforming == 0)
+ __unix_conforming = 1;
+#endif /* __DARWIN_UNIX03 */
+
+ if (thread->sig == _PTHREAD_SIG)
+ {
+ semaphore_t death = new_sem_from_pool(); /* in case we need it */
+
+ LOCK(thread->lock);
+ if ((thread->detached & PTHREAD_CREATE_JOINABLE) &&
+ thread->death == SEMAPHORE_NULL)
+ {
+ pthread_t self = pthread_self();
+
+ assert(thread->joiner == NULL);
+ if (thread != self && (self == NULL || self->joiner != thread))
+ {
+ int already_exited = (thread->detached & _PTHREAD_EXITED);
+
+ thread->death = death;
+ thread->joiner = self;
+ UNLOCK(thread->lock);
+
+ if (!already_exited)
+ {
+#if __DARWIN_UNIX03
+ /* Wait for it to signal... */
+ pthread_cleanup_push(__posix_join_cleanup, (void *)thread);
+ do {
+ res = __semwait_signal(death, 0, 0, 0, 0, 0);
+ } while ((res < 0) && (errno == EINTR));
+ pthread_cleanup_pop(0);
+
+#else /* __DARWIN_UNIX03 */
+ /* Wait for it to signal... */
+ do {
+ PTHREAD_MACH_CALL(semaphore_wait(death), kern_res);
+ } while (kern_res != KERN_SUCCESS);
+#endif /* __DARWIN_UNIX03 */
+ }
+#if __DARWIN_UNIX03
+ else {
+ if ((thread->cancel_state & (PTHREAD_CANCEL_ENABLE|_PTHREAD_CANCEL_PENDING)) == (PTHREAD_CANCEL_ENABLE|_PTHREAD_CANCEL_PENDING))
+ res = PTHREAD_CANCELED;
+ }
+#endif /* __DARWIN_UNIX03 */
+
+ LOCK(_pthread_list_lock);
+ LIST_REMOVE(thread, plist);
+ UNLOCK(_pthread_list_lock);
+ /* ... and wait for it to really be dead */
+ while ((res = _pthread_reap_thread(thread,
+ thread->kernel_thread,
+ value_ptr)) == EAGAIN)
+ {
+ sched_yield();
+ }
+ } else {
+ UNLOCK(thread->lock);
+ res = EDEADLK;
+ }
+ } else {
+ UNLOCK(thread->lock);
+ res = EINVAL;
+ }
+ restore_sem_to_pool(death);
+ return res;
+ }
+ return ESRCH;
+}
+
+/*
+ * Cancel a thread
+ */
+int
+pthread_cancel(pthread_t thread)
+{
+#if __DARWIN_UNIX03
+ if (__unix_conforming == 0)
+ __unix_conforming = 1;
+#endif /* __DARWIN_UNIX03 */
+
+ if (thread->sig == _PTHREAD_SIG)
+ {
+#if __DARWIN_UNIX03
+ int state;
+ LOCK(thread->lock);
+ state = thread->cancel_state |= _PTHREAD_CANCEL_PENDING;
+ UNLOCK(thread->lock);
+ if (state & PTHREAD_CANCEL_ENABLE)
+ __pthread_markcancel(thread->kernel_thread);
+#else /* __DARWIN_UNIX03 */
+ thread->cancel_state |= _PTHREAD_CANCEL_PENDING;
+#endif /* __DARWIN_UNIX03 */
+ return (ESUCCESS);
+ } else
+ {
+ return (ESRCH);
+ }
+}
+
+void
+pthread_testcancel(void)
+{
+ pthread_t self = pthread_self();
+
+#if __DARWIN_UNIX03
+ if (__unix_conforming == 0)
+ __unix_conforming = 1;
+ _pthread_testcancel(self, 1);
+#else /* __DARWIN_UNIX03 */
+ _pthread_testcancel(self, 0);
+#endif /* __DARWIN_UNIX03 */
+
+}
+/*
+ * Query/update the cancelability 'state' of a thread
+ */
+int
+pthread_setcancelstate(int state, int *oldstate)
+{
+ pthread_t self = pthread_self();
+
+#if __DARWIN_UNIX03
+ if (__unix_conforming == 0)
+ __unix_conforming = 1;
+#endif /* __DARWIN_UNIX03 */
+
+ switch (state) {
+ case PTHREAD_CANCEL_ENABLE:
+#if __DARWIN_UNIX03
+ __pthread_canceled(1);
+#endif /* __DARWIN_UNIX03 */
+ break;
+ case PTHREAD_CANCEL_DISABLE:
+#if __DARWIN_UNIX03
+ __pthread_canceled(2);
+#endif /* __DARWIN_UNIX03 */
+ break;
+ default:
+ return EINVAL;
+ }
+
+ self = pthread_self();
+ LOCK(self->lock);
+ if (oldstate)
+ *oldstate = self->cancel_state & _PTHREAD_CANCEL_STATE_MASK;
+ self->cancel_state &= ~_PTHREAD_CANCEL_STATE_MASK;
+ self->cancel_state |= state;
+ UNLOCK(self->lock);
+#if !__DARWIN_UNIX03
+ _pthread_testcancel(self, 0); /* See if we need to 'die' now... */
+#endif /* __DARWIN_UNIX03 */
+ return (0);
+}
+
+/*
+ * Query/update the cancelability 'type' of a thread
+ */
+int
+pthread_setcanceltype(int type, int *oldtype)
+{
+ pthread_t self = pthread_self();
+
+#if __DARWIN_UNIX03
+ if (__unix_conforming == 0)
+ __unix_conforming = 1;
+#endif /* __DARWIN_UNIX03 */
+
+ if ((type != PTHREAD_CANCEL_DEFERRED) &&
+ (type != PTHREAD_CANCEL_ASYNCHRONOUS))
+ return EINVAL;
+ self = pthread_self();
+ LOCK(self->lock);
+ if (oldtype)
+ *oldtype = self->cancel_state & _PTHREAD_CANCEL_TYPE_MASK;
+ self->cancel_state &= ~_PTHREAD_CANCEL_TYPE_MASK;
+ self->cancel_state |= type;
+ UNLOCK(self->lock);
+#if !__DARWIN_UNIX03
+ _pthread_testcancel(self, 0); /* See if we need to 'die' now... */
+#endif /* __DARWIN_UNIX03 */
+ return (0);
+}
+
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#ifndef _POSIX_PTHREAD_H
#define _POSIX_PTHREAD_H
+#include <_types.h>
#ifndef __POSIX_LIB__
#include <pthread_impl.h>
#endif
-#include <errno.h>
#include <sched.h>
#include <time.h>
-#include <unistd.h>
-#include <limits.h>
-#include <signal.h>
-#include <sys/types.h> /* temporary - need to fix correctly */
-#ifndef _POSIX_C_SOURCE
-#include <mach/mach_types.h>
-#endif /* ! _POSIX_C_SOURCE */
+#ifndef _PTHREAD_ATTR_T
+#define _PTHREAD_ATTR_T
+typedef __darwin_pthread_attr_t pthread_attr_t;
+#endif
+
+#ifndef _PTHREAD_COND_T
+#define _PTHREAD_COND_T
+typedef __darwin_pthread_cond_t pthread_cond_t;
+#endif
+
+#ifndef _PTHREAD_CONDATTR_T
+#define _PTHREAD_CONDATTR_T
+typedef __darwin_pthread_condattr_t pthread_condattr_t;
+#endif
+
+#ifndef _PTHREAD_KEY_T
+#define _PTHREAD_KEY_T
+typedef __darwin_pthread_key_t pthread_key_t;
+#endif
+
+#ifndef _PTHREAD_MUTEX_T
+#define _PTHREAD_MUTEX_T
+typedef __darwin_pthread_mutex_t pthread_mutex_t;
+#endif
+
+#ifndef _PTHREAD_MUTEXATTR_T
+#define _PTHREAD_MUTEXATTR_T
+typedef __darwin_pthread_mutexattr_t pthread_mutexattr_t;
+#endif
+
+#ifndef _PTHREAD_ONCE_T
+#define _PTHREAD_ONCE_T
+typedef __darwin_pthread_once_t pthread_once_t;
+#endif
+
+#ifndef _PTHREAD_RWLOCK_T
+#define _PTHREAD_RWLOCK_T
+typedef __darwin_pthread_rwlock_t pthread_rwlock_t;
+#endif
+
+#ifndef _PTHREAD_RWLOCKATTR_T
+#define _PTHREAD_RWLOCKATTR_T
+typedef __darwin_pthread_rwlockattr_t pthread_rwlockattr_t;
+#endif
+
+#ifndef _PTHREAD_T
+#define _PTHREAD_T
+typedef __darwin_pthread_t pthread_t;
+#endif
+
+#if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)
+
+#ifndef _MACH_PORT_T
+#define _MACH_PORT_T
+typedef __darwin_mach_port_t mach_port_t;
+#endif
+
+#ifndef _SIGSET_T
+#define _SIGSET_T
+typedef __darwin_sigset_t sigset_t;
+#endif
+
+#endif /* ! _POSIX_C_SOURCE && ! _XOPEN_SOURCE */
/*
* These symbols indicate which [optional] features are available
#define pthread_cleanup_push(func, val) \
{ \
- struct _pthread_handler_rec __handler; \
+ struct __darwin_pthread_handler_rec __handler; \
pthread_t __self = pthread_self(); \
- __handler.routine = func; \
- __handler.arg = val; \
- __handler.next = __self->cleanup_stack; \
- __self->cleanup_stack = &__handler;
+ __handler.__routine = func; \
+ __handler.__arg = val; \
+ __handler.__next = __self->__cleanup_stack; \
+ __self->__cleanup_stack = &__handler;
#define pthread_cleanup_pop(execute) \
/* Note: 'handler' must be in this same lexical context! */ \
- __self->cleanup_stack = __handler.next; \
- if (execute) (__handler.routine)(__handler.arg); \
+ __self->__cleanup_stack = __handler.__next; \
+ if (execute) (__handler.__routine)(__handler.__arg); \
}
-
+
/*
* Thread attributes
*/
#define PTHREAD_CANCEL_DEFERRED 0x02 /* Cancel waits until cancellation point */
#define PTHREAD_CANCEL_ASYNCHRONOUS 0x00 /* Cancel occurs immediately */
+/* Value returned from pthread_join() when a thread is canceled */
+#define PTHREAD_CANCELED ((void *) 1)
+
/* We only support PTHREAD_SCOPE_SYSTEM */
#define PTHREAD_SCOPE_SYSTEM 1
#define PTHREAD_SCOPE_PROCESS 2
#define PTHREAD_PROCESS_SHARED 1
#define PTHREAD_PROCESS_PRIVATE 2
-/* Who defines this? */
-
-#if !defined(ENOTSUP)
-#define ENOTSUP 89
-#endif
/*
* Mutex protocol attributes
*/
#define PTHREAD_ONCE_INIT {_PTHREAD_ONCE_SIG_init, {0}}
-/*
- * Thread Specific Data - keys
- */
-
-#include <sys/time.h>
-
/*
* Prototypes for all PTHREAD interfaces
*/
+int pthread_atfork(void (*prepare)(void), void (*parent)(void),
+ void (*child)(void));
int pthread_attr_destroy(pthread_attr_t *attr);
int pthread_attr_getdetachstate(const pthread_attr_t *attr,
int *detachstate);
+int pthread_attr_getguardsize(const pthread_attr_t *attr,
+ size_t *guardsize);
int pthread_attr_getinheritsched(const pthread_attr_t *attr,
int *inheritsched);
int pthread_attr_getschedparam(const pthread_attr_t *attr,
struct sched_param *param);
int pthread_attr_getschedpolicy(const pthread_attr_t *attr,
int *policy);
+int pthread_attr_getscope(pthread_attr_t *, int *);
+int pthread_attr_getstack(const pthread_attr_t *attr,
+ void **stackaddr, size_t *stacksize);
int pthread_attr_getstackaddr(const pthread_attr_t *attr,
void **stackaddr);
int pthread_attr_getstacksize(const pthread_attr_t *attr,
size_t *stacksize);
-int pthread_attr_getstack(const pthread_attr_t *attr,
- void **stackaddr, size_t *stacksize);
-int pthread_attr_getguardsize(const pthread_attr_t *attr,
- size_t *guardsize);
int pthread_attr_init(pthread_attr_t *attr);
int pthread_attr_setdetachstate(pthread_attr_t *attr,
int detachstate);
+int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize);
int pthread_attr_setinheritsched(pthread_attr_t *attr,
int inheritsched);
int pthread_attr_setschedparam(pthread_attr_t *attr,
const struct sched_param *param);
int pthread_attr_setschedpolicy(pthread_attr_t *attr,
int policy);
+int pthread_attr_setscope(pthread_attr_t *, int);
+int pthread_attr_setstack(pthread_attr_t *attr,
+ void *stackaddr, size_t stacksize);
int pthread_attr_setstackaddr(pthread_attr_t *attr,
void *stackaddr);
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
-int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize);
-int pthread_attr_setstack(pthread_attr_t *attr,
- void *stackaddr, size_t stacksize);
-int pthread_cancel(pthread_t thread);
-int pthread_setcancelstate(int state, int *oldstate);
-int pthread_setcanceltype(int type, int *oldtype);
-void pthread_testcancel(void);
+int pthread_cancel(pthread_t thread) __DARWIN_ALIAS(pthread_cancel);
+
int pthread_cond_broadcast(pthread_cond_t *cond);
int pthread_cond_destroy(pthread_cond_t *cond);
int pthread_cond_init(pthread_cond_t *cond,
const pthread_condattr_t *attr);
int pthread_cond_signal(pthread_cond_t *cond);
-int pthread_cond_wait(pthread_cond_t *cond,
- pthread_mutex_t *mutex);
int pthread_cond_timedwait(pthread_cond_t *cond,
pthread_mutex_t *mutex,
- const struct timespec *abstime);
-int pthread_condattr_init(pthread_condattr_t *attr);
+ const struct timespec *abstime) __DARWIN_ALIAS(pthread_cond_timedwait);
+int pthread_cond_wait(pthread_cond_t *cond,
+ pthread_mutex_t *mutex) __DARWIN_ALIAS(pthread_cond_wait);
int pthread_condattr_destroy(pthread_condattr_t *attr);
int pthread_condattr_getpshared(const pthread_condattr_t *attr,
int *pshared);
+int pthread_condattr_init(pthread_condattr_t *attr);
int pthread_condattr_setpshared(pthread_condattr_t *attr,
int pshared);
int pthread_create(pthread_t *thread,
int pthread_equal(pthread_t t1,
pthread_t t2);
void pthread_exit(void *value_ptr) __dead2;
-int pthread_kill(pthread_t, int);
-int pthread_sigmask(int, const sigset_t *, sigset_t *);
+int pthread_getconcurrency(void);
int pthread_getschedparam(pthread_t thread,
int *policy,
struct sched_param *param);
+void *pthread_getspecific(pthread_key_t key);
int pthread_join(pthread_t thread,
- void **value_ptr);
+ void **value_ptr) __DARWIN_ALIAS(pthread_join);
+int pthread_key_create(pthread_key_t *key,
+ void (*destructor)(void *));
+int pthread_key_delete(pthread_key_t key);
int pthread_mutex_destroy(pthread_mutex_t *mutex);
int pthread_mutex_getprioceiling(const pthread_mutex_t *mutex,
int *prioceiling);
int prioceiling);
int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr,
int protocol);
-int pthread_mutexattr_settype(pthread_mutexattr_t *attr,
- int type);
int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
int pshared);
+int pthread_mutexattr_settype(pthread_mutexattr_t *attr,
+ int type);
int pthread_once(pthread_once_t *once_control,
void (*init_routine)(void));
-pthread_t pthread_self(void);
-int pthread_setschedparam(pthread_t thread,
- int policy,
- const struct sched_param *param);
-int pthread_key_create(pthread_key_t *key,
- void (*destructor)(void *));
-int pthread_key_delete(pthread_key_t key);
-int pthread_setspecific(pthread_key_t key,
- const void *value);
-void *pthread_getspecific(pthread_key_t key);
-int pthread_attr_getscope(pthread_attr_t *, int *);
-int pthread_attr_setscope(pthread_attr_t *, int);
-int pthread_getconcurrency(void);
-int pthread_setconcurrency(int);
int pthread_rwlock_destroy(pthread_rwlock_t * rwlock);
int pthread_rwlock_init(pthread_rwlock_t * rwlock,
const pthread_rwlockattr_t *attr);
int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
-int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock);
int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
-int pthread_rwlockattr_init(pthread_rwlockattr_t *attr);
+int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr);
int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr,
int *pshared);
+int pthread_rwlockattr_init(pthread_rwlockattr_t *attr);
int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr,
int pshared);
+pthread_t pthread_self(void);
-#ifndef _POSIX_C_SOURCE
+int pthread_setcancelstate(int state, int *oldstate) __DARWIN_ALIAS(pthread_setcancelstate);
+int pthread_setcanceltype(int type, int *oldtype) __DARWIN_ALIAS(pthread_setcanceltype);
+int pthread_setconcurrency(int);
+int pthread_setschedparam(pthread_t thread,
+ int policy,
+ const struct sched_param *param);
+int pthread_setspecific(pthread_key_t key,
+ const void *value);
+void pthread_testcancel(void) __DARWIN_ALIAS(pthread_testcancel);
+
+#if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)
/* returns non-zero if pthread_create or cthread_fork have been called */
int pthread_is_threaded_np(void);
const pthread_attr_t *attr,
void *(*start_routine)(void *),
void *arg);
-void pthread_yield_np(void);
-#endif /* ! _POSIX_C_SOURCE */
+int pthread_kill(pthread_t, int);
+int pthread_sigmask(int, const sigset_t *, sigset_t *);
+void pthread_yield_np(void);
+#endif /* ! _POSIX_C_SOURCE && ! _XOPEN_SOURCE */
__END_DECLS
#endif /* _POSIX_PTHREAD_H */
--- /dev/null
+.\" Copyright (c) 2004 Apple Computer, Inc.
+.\"
+.Dd August 12, 2004
+.Dt PTHREAD_ATFORK 3
+.Os
+.Sh NAME
+.Nm pthread_atfork
+.Nd register handlers to be called before and after
+.Fn fork
+.Sh SYNOPSIS
+.Fd #include <pthread.h>
+.Ft int
+.Fn pthread_atfork "void (*prepare)(void)" "void (*parent)(void)" "void (*child)(void)"
+.Sh DESCRIPTION
+The
+.Fn pthread_atfork
+function is used to register functions to be called before and after
+.Fn fork
+The
+.Fa prepare
+handler is called before
+.Fn fork
+, while the
+.Fa parent
+and
+.Fa child
+handlers are called after
+.Fn fork
+in the parent and child process, respectively.
+.Fa prepare
+handlers are called in reverse order of their registration, while
+.Fa parent
+and
+.Fa child
+handlers are called in the order in which they were registered. Any of the handlers may
+be NULL.
+.Pp
+Remember: only async-cancel-safe functions are allowed on the child side of
+.Fn fork
+.Sh RETURN VALUES
+If successful, the
+.Fn pthread_atfork
+function will return zero; otherwise an error number will be returned to
+indicate the error.
+.Sh ERRORS
+.Fn pthread_atfork
+will fail if:
+.Bl -tag -width Er
+.It Bq Er ENOMEM
+The system lacked the necessary resources to add another handler to the list.
+.El
+.Sh SEE ALSO
+.Xr fork 2
+.Sh STANDARDS
+.Fn pthread_atfork
+conforms to
+.St -p1003.1-96 .
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#include <stdio.h>
extern void _pthread_mutex_remove(pthread_mutex_t *, pthread_t);
+extern int __unix_conforming;
+
+#ifndef BUILDING_VARIANT /* [ */
/*
* Destroy a condition variable.
}
}
+static void cond_cleanup(void *arg)
+{
+ pthread_cond_t *cond = (pthread_cond_t *)arg;
+ pthread_mutex_t *mutex;
+ LOCK(cond->lock);
+ mutex = cond->busy;
+ cond->waiters--;
+ if (cond->waiters == 0) {
+ _pthread_cond_remove(cond, mutex);
+ cond->busy = (pthread_mutex_t *)NULL;
+ }
+ UNLOCK(cond->lock);
+ /*
+ ** Can't do anything if this fails -- we're on the way out
+ */
+ (void)pthread_mutex_lock(mutex);
+}
+
/*
* Suspend waiting for a condition variable.
* Note: we have to keep a list of condition variables which are using
* this same mutex variable so we can detect invalid 'destroy' sequences.
*/
-static int
+__private_extern__ int
_pthread_cond_wait(pthread_cond_t *cond,
pthread_mutex_t *mutex,
const struct timespec *abstime,
- int isRelative)
+ int isRelative,
+ int isconforming)
{
int res;
kern_return_t kern_res;
+ int wait_res;
pthread_mutex_t *busy;
mach_timespec_t then;
+ struct timespec cthen = {0,0};
int sig = cond->sig;
/* to provide backwards compat for apps using united condtn vars */
_pthread_cond_init(cond, NULL);
}
- if (abstime)
- {
- if (isRelative == 0)
+ if (abstime) {
+ if (!isconforming)
{
- struct timespec now;
- struct timeval tv;
- gettimeofday(&tv, NULL);
- TIMEVAL_TO_TIMESPEC(&tv, &now);
-
- /* Compute relative time to sleep */
- then.tv_nsec = abstime->tv_nsec - now.tv_nsec;
- then.tv_sec = abstime->tv_sec - now.tv_sec;
- if (then.tv_nsec < 0)
- {
- then.tv_nsec += NSEC_PER_SEC;
- then.tv_sec--;
+ if (isRelative == 0) {
+ struct timespec now;
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ TIMEVAL_TO_TIMESPEC(&tv, &now);
+
+ /* Compute relative time to sleep */
+ then.tv_nsec = abstime->tv_nsec - now.tv_nsec;
+ then.tv_sec = abstime->tv_sec - now.tv_sec;
+ if (then.tv_nsec < 0)
+ {
+ then.tv_nsec += NSEC_PER_SEC;
+ then.tv_sec--;
+ }
+ if (((int)then.tv_sec < 0) ||
+ ((then.tv_sec == 0) && (then.tv_nsec == 0)))
+ {
+ UNLOCK(cond->lock);
+ return ETIMEDOUT;
+ }
+ } else {
+ then.tv_sec = abstime->tv_sec;
+ then.tv_nsec = abstime->tv_nsec;
}
- if (((int)then.tv_sec < 0) ||
- ((then.tv_sec == 0) && (then.tv_nsec == 0)))
- {
+ if (then.tv_nsec >= NSEC_PER_SEC) {
UNLOCK(cond->lock);
- return ETIMEDOUT;
+ return EINVAL;
}
- }
- else
- {
- then.tv_sec = abstime->tv_sec;
- then.tv_nsec = abstime->tv_nsec;
- }
- if (then.tv_nsec >= NSEC_PER_SEC)
- {
- UNLOCK(cond->lock);
- return EINVAL;
- }
+ } else {
+ cthen.tv_sec = abstime->tv_sec;
+ cthen.tv_nsec = abstime->tv_nsec;
+ if ((cthen.tv_sec < 0) || (cthen.tv_nsec < 0)) {
+ UNLOCK(cond->lock);
+ return EINVAL;
+ }
+ if (cthen.tv_nsec >= NSEC_PER_SEC) {
+ UNLOCK(cond->lock);
+ return EINVAL;
+ }
+ }
}
if (++cond->waiters == 1)
mutex->owner = _PTHREAD_MUTEX_OWNER_SWITCHING;
UNLOCK(mutex->lock);
- if (abstime) {
- kern_res = semaphore_timedwait_signal(cond->sem, mutex->sem, then);
+ if (!isconforming) {
+ if (abstime) {
+ kern_res = semaphore_timedwait_signal(cond->sem, mutex->sem, then);
+ } else {
+ PTHREAD_MACH_CALL(semaphore_wait_signal(cond->sem, mutex->sem), kern_res);
+ }
} else {
- PTHREAD_MACH_CALL(semaphore_wait_signal(cond->sem, mutex->sem), kern_res);
+ pthread_cleanup_push(cond_cleanup, (void *)cond);
+ wait_res = __semwait_signal(cond->sem, mutex->sem, abstime != NULL, isRelative,
+ cthen.tv_sec, cthen.tv_nsec);
+ pthread_cleanup_pop(0);
}
- }
- else
- {
+ } else {
UNLOCK(mutex->lock);
- if (abstime) {
- kern_res = semaphore_timedwait(cond->sem, then);
- } else {
- PTHREAD_MACH_CALL(semaphore_wait(cond->sem), kern_res);
+ if (!isconforming) {
+ if (abstime) {
+ kern_res = semaphore_timedwait(cond->sem, then);
+ } else {
+ PTHREAD_MACH_CALL(semaphore_wait(cond->sem), kern_res);
+ }
+ } else {
+ pthread_cleanup_push(cond_cleanup, (void *)cond);
+ wait_res = __semwait_signal(cond->sem, NULL, abstime != NULL, isRelative,
+ cthen.tv_sec, cthen.tv_nsec);
+ pthread_cleanup_pop(0);
}
+
}
LOCK(cond->lock);
if ((res = pthread_mutex_lock(mutex)) != ESUCCESS)
return (res);
- /* KERN_ABORTED can be treated as a spurious wakeup */
- if ((kern_res == KERN_SUCCESS) || (kern_res == KERN_ABORTED))
- return (ESUCCESS);
- else if (kern_res == KERN_OPERATION_TIMED_OUT)
- return (ETIMEDOUT);
- return (EINVAL);
-}
-
-int
-pthread_cond_wait(pthread_cond_t *cond,
- pthread_mutex_t *mutex)
-{
- return (_pthread_cond_wait(cond, mutex, (struct timespec *)NULL, 0));
+ if (!isconforming) {
+ /* KERN_ABORTED can be treated as a spurious wakeup */
+ if ((kern_res == KERN_SUCCESS) || (kern_res == KERN_ABORTED))
+ return (ESUCCESS);
+ else if (kern_res == KERN_OPERATION_TIMED_OUT)
+ return (ETIMEDOUT);
+ return (EINVAL);
+ } else {
+ if (wait_res < 0) {
+ if (errno == ETIMEDOUT) {
+ return ETIMEDOUT;
+ } else if (errno == EINTR) {
+ /*
+ ** EINTR can be treated as a spurious wakeup unless we were canceled.
+ */
+ return 0;
+ }
+ return EINVAL;
+ }
+ return 0;
+ }
}
-int
-pthread_cond_timedwait(pthread_cond_t *cond,
- pthread_mutex_t *mutex,
- const struct timespec *abstime)
-{
- return (_pthread_cond_wait(cond, mutex, abstime, 0));
-}
int
pthread_cond_timedwait_relative_np(pthread_cond_t *cond,
pthread_mutex_t *mutex,
const struct timespec *abstime)
{
- return (_pthread_cond_wait(cond, mutex, abstime, 1));
+ return (_pthread_cond_wait(cond, mutex, abstime, 1, 0));
}
int
}
+#else /* !BUILDING_VARIANT */
+extern int _pthread_cond_wait(pthread_cond_t *cond,
+ pthread_mutex_t *mutex,
+ const struct timespec *abstime,
+ int isRelative,
+ int isconforming);
+
+#endif /* !BUILDING_VARIANT ] */
+
+int
+pthread_cond_wait(pthread_cond_t *cond,
+ pthread_mutex_t *mutex)
+{
+ int conforming;
+#if __DARWIN_UNIX03
+
+ if (__unix_conforming == 0)
+ __unix_conforming = 1;
+
+ conforming = 1;
+#else /* __DARWIN_UNIX03 */
+ conforming = 0;
+#endif /* __DARWIN_UNIX03 */
+ return (_pthread_cond_wait(cond, mutex, (struct timespec *)NULL, 0, conforming));
+}
+
+int
+pthread_cond_timedwait(pthread_cond_t *cond,
+ pthread_mutex_t *mutex,
+ const struct timespec *abstime)
+{
+ int conforming;
+#if __DARWIN_UNIX03
+ if (__unix_conforming == 0)
+ __unix_conforming = 1;
+
+ conforming = 1;
+#else /* __DARWIN_UNIX03 */
+ conforming = 0;
+#endif /* __DARWIN_UNIX03 */
+
+ return (_pthread_cond_wait(cond, mutex, abstime, 0, conforming));
+}
+
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#ifndef _POSIX_PTHREAD_INTERNALS_H
#define _POSIX_PTHREAD_INTERNALS_H
+// suppress pthread_attr_t typedef in sys/signal.h
+#define _PTHREAD_ATTR_T
+struct _pthread_attr_t; /* forward reference */
+typedef struct _pthread_attr_t pthread_attr_t;
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
+#include <limits.h>
+#include <errno.h>
#include <mach/mach.h>
#include <mach/mach_error.h>
/*
* Threads
*/
+#define _PTHREAD_T
typedef struct _pthread
{
long sig; /* Unique signature for this structure */
- struct _pthread_handler_rec *cleanup_stack;
+ struct __darwin_pthread_handler_rec *__cleanup_stack;
pthread_lock_t lock; /* Used for internal mutex on structure */
u_int32_t detached:8,
inherit:8,
policy:8,
pad:8;
size_t guardsize; /* size in bytes to guard stack overflow */
- int pad0;
+#if !defined(__LP64__)
+ int pad0; /* for backwards compatibility */
+#endif
struct sched_param param;
struct _pthread_mutex *mutexes;
struct _pthread *joiner;
- int pad1;
+#if !defined(__LP64__)
+ int pad1; /* for backwards compatibility */
+#endif
void *exit_value;
semaphore_t death; /* pthread_join() uses this to wait for death's call */
mach_port_t kernel_thread; /* kernel thread this thread is bound to */
void *stackaddr; /* Base of the stack (is aligned on vm_page_size boundary */
size_t stacksize; /* Size of the stack (is a multiple of vm_page_size and >= PTHREAD_STACK_MIN) */
mach_port_t reply_port; /* Cached MiG reply port */
- void *cthread_self; /* cthread_self() if somebody calls cthread_set_self() */
+#if defined(__LP64__)
+ int pad2; /* for natural alignment */
+#endif
+ void *cthread_self; /* cthread_self() if somebody calls cthread_set_self() */
boolean_t freeStackOnExit; /* Should we free the stack when we're done? */
+#if defined(__LP64__)
+ int pad3; /* for natural alignment */
+#endif
LIST_ENTRY(_pthread) plist;
} *pthread_t;
-// suppress pthread_t typedef in signal.h
-#define _PTHREAD_T_DECLARED
-
/*
* This will cause a compile-time failure if someone moved the tsd field
* and we need to change _PTHREAD_TSD_OFFSET in pthread_machdep.h
/*
* Thread attributes
*/
-typedef struct
+struct _pthread_attr_t
{
long sig; /* Unique signature for this structure */
pthread_lock_t lock; /* Used for internal mutex on structure */
void *stackaddr; /* Base of the stack (is aligned on vm_page_size boundary */
size_t stacksize; /* Size of the stack (is a multiple of vm_page_size and >= PTHREAD_STACK_MIN) */
boolean_t freeStackOnExit;/* Should we free the stack when we exit? */
-} pthread_attr_t;
-
-// suppress pthread_attr_t typedef in sys/signal.h
-#define _PTHREAD_ATTR_T_DECLARED
+};
/*
* Mutex attributes
*/
+#define _PTHREAD_MUTEXATTR_T
typedef struct
{
long sig; /* Unique signature for this structure */
/*
* Mutex variables
*/
+#define _PTHREAD_MUTEX_T
typedef struct _pthread_mutex
{
long sig; /* Unique signature for this structure */
/*
* Condition variable attributes
*/
+#define _PTHREAD_CONDATTR_T
typedef struct
{
long sig; /* Unique signature for this structure */
/*
* Condition variables
*/
+#define _PTHREAD_COND_T
typedef struct _pthread_cond
{
long sig; /* Unique signature for this structure */
/*
* Initialization control (once) variables
*/
+#define _PTHREAD_ONCE_T
typedef struct
{
long sig; /* Unique signature for this structure */
pthread_lock_t lock; /* Used for internal mutex on structure */
} pthread_once_t;
+#define _PTHREAD_RWLOCKATTR_T
typedef struct {
long sig; /* Unique signature for this structure */
int pshared;
int rfu[2]; /* reserved for future use */
} pthread_rwlockattr_t;
+#define _PTHREAD_RWLOCK_T
typedef struct {
long sig;
pthread_mutex_t lock; /* monitor lock */
#include "pthread.h"
+#if defined(__i386__) || defined(__ppc64__)
+/*
+ * Inside libSystem, we can use r13 or %gs directly to get access to the
+ * thread-specific data area. The current thread is in the first slot.
+ */
+inline static pthread_t __attribute__((__pure__))
+_pthread_self_direct(void)
+{
+ pthread_t ret;
+#if defined(__i386__)
+ asm("movl %%gs:%P1, %0" : "=r" (ret) : "i" (offsetof(struct _pthread, tsd[0])));
+#elif defined(__ppc64__)
+ register const pthread_t __pthread_self asm ("r13");
+ ret = __pthread_self;
+#endif
+ return ret;
+}
+#define pthread_self() _pthread_self_direct()
+#endif
+
#define _PTHREAD_DEFAULT_INHERITSCHED PTHREAD_INHERIT_SCHED
#define _PTHREAD_DEFAULT_PROTOCOL PTHREAD_PRIO_NONE
#define _PTHREAD_DEFAULT_PRIOCEILING 0
#endif
#define _PTHREAD_MUTEX_OWNER_SWITCHING (pthread_t)(~0)
-#define _PTHREAD_CANCEL_STATE_MASK 0xFE
-#define _PTHREAD_CANCEL_TYPE_MASK 0xFD
+#define _PTHREAD_CANCEL_STATE_MASK 0x01
+#define _PTHREAD_CANCEL_TYPE_MASK 0x02
#define _PTHREAD_CANCEL_PENDING 0x10 /* pthread_cancel() has been called for this thread */
extern boolean_t swtch_pri(int);
__private_extern__ semaphore_t new_sem_from_pool(void);
__private_extern__ void restore_sem_to_pool(semaphore_t);
+__private_extern__ void _pthread_atfork_queue_init(void);
#endif /* _POSIX_PTHREAD_INTERNALS_H */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#define _POSIX_PTHREAD_MACHDEP_H
#ifdef __LP64__
-#define _PTHREAD_TSD_OFFSET 0x68
+#define _PTHREAD_TSD_OFFSET 0x60
#else
#define _PTHREAD_TSD_OFFSET 0x48
#endif /* __LP64__ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+MACHINE:=`arch`
+MAKEOBJDIR:=../../obj.`arch`
+
+TESTS = pthread_atfork_test
+LDFLAGS = -nostdlib -lcrt1.o
+LDLIBS = $(MAKEOBJDIR)/libc.a /usr/local/lib/system/libnotify.a \
+ /usr/local/lib/system/libm.a /usr/local/lib/system/libmCommon.a \
+ -lgcc /usr/local/lib/system/libkeymgr.a \
+ /usr/local/lib/system/libdyld.a /usr/local/lib/system/libmacho.a \
+ $(MAKEOBJDIR)/libc.a
+CFLAGS = -I..
+
+.SUFFIXES:
+.SUFFIXES: .c
+
+.PHONY: tests
+
+tests: $(TESTS)
+ @for i in $(TESTS); do \
+ $$i && echo $$i passed; \
+ done
+
+clean:
+ rm -f $(TESTS)
+
+Makefile pthread_atfork_test.c : ;
--- /dev/null
+#include <assert.h>
+#include <pthread.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+/*
+ * Parent and child handlers are called in the order they were registered
+ * prepare handlers are called in reverse order. The non-commutative
+ * operations will ensure that we are calling them in the proper order.
+ */
+
+static int parentval = 0;
+static int childval = 0;
+
+static void prepare1(void)
+{
+ parentval *= 2;
+}
+
+static void prepare2(void)
+{
+ parentval = 3;
+}
+
+static void parent1(void)
+{
+ parentval += 4;
+}
+
+static void parent2(void)
+{
+ parentval *= 3;
+}
+
+static void child1(void)
+{
+ childval = 5;
+}
+
+static void child2(void)
+{
+ childval *= 3;
+}
+
+int
+main(void)
+{
+ pid_t pid, child;
+ int status;
+
+ assert(!pthread_atfork(prepare1, parent1, child1));
+ assert(!pthread_atfork(prepare2, parent2, child2));
+ pid = fork();
+ assert(pid >= 0);
+ if (pid == 0) {
+ _exit(childval);
+ } else {
+ child = waitpid(pid, &status, 0);
+ assert(child == pid);
+ assert(WIFEXITED(status));
+ assert(WEXITSTATUS(status) == 15);
+ assert(parentval == 30);
+ }
+ return 0;
+}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
kern_return_t r;
unsigned int count;
#if defined(__ppc__) || defined(__ppc64__)
- struct ppc_thread_state state = {0};
- struct ppc_thread_state *ts = &state;
-
+#if defined(__ppc__)
+ ppc_thread_state_t state = {0};
+ ppc_thread_state_t *ts = &state;
+ thread_state_flavor_t flavor = PPC_THREAD_STATE;
+ count = PPC_THREAD_STATE_COUNT;
+#elif defined(__ppc64__)
+ ppc_thread_state64_t state = {0};
+ ppc_thread_state64_t *ts = &state;
+ thread_state_flavor_t flavor = PPC_THREAD_STATE64;
+ count = PPC_THREAD_STATE64_COUNT;
+#endif
/*
* Set up PowerPC registers.
*/
- count = PPC_THREAD_STATE_COUNT;
if (suspended) {
PTHREAD_MACH_CALL(thread_get_state(thread->kernel_thread,
- PPC_THREAD_STATE,
+ flavor,
(thread_state_t) &state,
&count),
r);
}
- ts->srr0 = (int) routine;
+ ts->srr0 = (uintptr_t)routine;
ts->r1 = (uintptr_t)vsp - C_ARGSAVE_LEN - C_RED_ZONE;
- ts->r3 = (int)thread;
+ ts->r3 = (uintptr_t)thread;
/* Incase of needresume, suspend is always set */
if (suspended) {
PTHREAD_MACH_CALL(thread_set_state(thread->kernel_thread,
- PPC_THREAD_STATE,
+ flavor,
(thread_state_t) &state,
- PPC_THREAD_STATE_COUNT),
+ count),
r);
if (needresume)
PTHREAD_MACH_CALL(thread_resume(thread->kernel_thread),
r);
} else {
PTHREAD_MACH_CALL(thread_create_running(mach_task_self(),
- PPC_THREAD_STATE,
+ flavor,
(thread_state_t) ts,
- PPC_THREAD_STATE_COUNT,
+ count,
&thread->kernel_thread),
r);
}
r);
}
ts->eip = (int) routine;
- *--sp = (int) thread; /* argument to function */
- *--sp = 0; /* fake return address */
- ts->esp = (int) sp; /* set stack pointer */
+
+ /*
+ ** We need to simulate a 16-byte aligned stack frame as if we had
+ ** executed a call instruction. Since we're "pushing" one argument,
+ ** we need to adjust the pointer by 12 bytes (3 * sizeof (int *))
+ */
+
+ sp -= 3; /* make sure stack is aligned */
+ *--sp = (int) thread; /* argument to function */
+ *--sp = 0; /* fake return address */
+ ts->esp = (int) sp; /* set stack pointer */
/* Incase of needresume, suspend is always set */
if (suspended) {
PTHREAD_MACH_CALL(thread_set_state(thread->kernel_thread,
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/regex/engine.c,v 1.13 2003/02/16 17:29:10 nectar Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/regex/engine.c,v 1.14 2004/07/12 07:35:59 tjr Exp $");
/*
* The matching engine and friends. This file is #included by regexec.c
#define at lat
#define match lmat
#endif
+#ifdef MNAMES
+#define matcher mmatcher
+#define fast mfast
+#define slow mslow
+#define dissect mdissect
+#define backref mbackref
+#define step mstep
+#define print mprint
+#define at mat
+#define match mmat
+#endif
/* another structure passed up and down to avoid zillions of parameters */
struct match {
states fresh; /* states for a fresh start */
states tmp; /* temporary */
states empty; /* empty set of states */
+ mbstate_t mbs; /* multibyte conversion state */
};
/* ========= begin header generated by ./mkh ========= */
static char *backref(struct match *m, char *start, char *stop, sopno startst, sopno stopst, sopno lev);
static char *fast(struct match *m, char *start, char *stop, sopno startst, sopno stopst);
static char *slow(struct match *m, char *start, char *stop, sopno startst, sopno stopst);
-static states step(struct re_guts *g, sopno start, sopno stop, states bef, int ch, states aft);
-#define BOL (OUT+1)
-#define EOL (BOL+1)
-#define BOLEOL (BOL+2)
-#define NOTHING (BOL+3)
-#define BOW (BOL+4)
-#define EOW (BOL+5)
-#define CODEMAX (BOL+5) /* highest code used */
-#define NONCHAR(c) ((c) > CHAR_MAX)
-#define NNONCHAR (CODEMAX-CHAR_MAX)
+static states step(struct re_guts *g, sopno start, sopno stop, states bef, wint_t ch, states aft);
+#define BOL (OUT-1)
+#define EOL (BOL-1)
+#define BOLEOL (BOL-2)
+#define NOTHING (BOL-3)
+#define BOW (BOL-4)
+#define EOW (BOL-5)
+#define BADCHAR (BOL-6)
+#define NONCHAR(c) ((c) <= OUT)
#ifdef REDEBUG
static void print(struct match *m, char *caption, states st, int ch, FILE *d);
#endif
SETUP(m->tmp);
SETUP(m->empty);
CLEAR(m->empty);
+ ZAPSTATE(&m->mbs);
/* Adjust start according to moffset, to speed things up */
if (g->moffset > -1)
if (endp != NULL)
break;
assert(m->coldp < m->endp);
- m->coldp++;
+ m->coldp += XMBRTOWC(NULL, m->coldp,
+ m->endp - m->coldp, &m->mbs, 0);
}
if (nmatch == 1 && !g->backrefs)
break; /* no further info needed */
/* despite initial appearances, there is no match here */
NOTE("false alarm");
- start = m->coldp + 1; /* recycle starting later */
+ /* recycle starting later */
+ start = m->coldp + XMBRTOWC(NULL, m->coldp,
+ m->endp - m->coldp, &m->mbs, 0);
assert(start <= stop);
}
assert(nope);
break;
case OCHAR:
- sp++;
+ sp += XMBRTOWC(NULL, sp, stop - start, &m->mbs, 0);
break;
case OBOL:
case OEOL:
break;
case OANY:
case OANYOF:
- sp++;
+ sp += XMBRTOWC(NULL, sp, stop - start, &m->mbs, 0);
break;
case OBACK_:
case O_BACK:
sop s;
regoff_t offsave;
cset *cs;
+ wint_t wc;
AT("back", start, stop, startst, stopst);
sp = start;
for (ss = startst; !hard && ss < stopst; ss++)
switch (OP(s = m->g->strip[ss])) {
case OCHAR:
- if (sp == stop || *sp++ != (char)OPND(s))
+ if (sp == stop)
+ return(NULL);
+ sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR);
+ if (wc != OPND(s))
return(NULL);
break;
case OANY:
if (sp == stop)
return(NULL);
- sp++;
+ sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR);
+ if (wc == BADCHAR)
+ return (NULL);
break;
case OANYOF:
+ if (sp == stop)
+ return (NULL);
cs = &m->g->sets[OPND(s)];
- if (sp == stop || !CHIN(cs, *sp++))
+ sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR);
+ if (wc == BADCHAR || !CHIN(cs, wc))
return(NULL);
break;
case OBOL:
states fresh = m->fresh;
states tmp = m->tmp;
char *p = start;
- int c = (start == m->beginp) ? OUT : *(start-1);
- int lastc; /* previous c */
- int flagch;
+ wint_t c;
+ wint_t lastc; /* previous c */
+ wint_t flagch;
int i;
char *coldp; /* last p after which no match was underway */
+ size_t clen;
CLEAR(st);
SET1(st, startst);
ASSIGN(fresh, st);
SP("start", st, *p);
coldp = NULL;
+ if (start == m->beginp)
+ c = OUT;
+ else {
+ /*
+ * XXX Wrong if the previous character was multi-byte.
+ * Newline never is (in encodings supported by FreeBSD),
+ * so this only breaks the ISWORD tests below.
+ */
+ c = (uch)*(start - 1);
+ }
for (;;) {
/* next character */
lastc = c;
- c = (p == m->endp) ? OUT : *p;
+ if (p == m->endp)
+ c = OUT;
+ else
+ clen = XMBRTOWC(&c, p, m->endp - p, &m->mbs, BADCHAR);
if (EQ(st, fresh))
coldp = p;
st = step(m->g, startst, stopst, tmp, c, st);
SP("aft", st, c);
assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
- p++;
+ p += clen;
}
assert(coldp != NULL);
m->coldp = coldp;
if (ISSET(st, stopst))
- return(p+1);
+ return(p+XMBRTOWC(NULL, p, m->endp - p, &m->mbs, 0));
else
return(NULL);
}
states empty = m->empty;
states tmp = m->tmp;
char *p = start;
- int c = (start == m->beginp) ? OUT : *(start-1);
- int lastc; /* previous c */
- int flagch;
+ wint_t c;
+ wint_t lastc; /* previous c */
+ wint_t flagch;
int i;
char *matchp; /* last p at which a match ended */
+ size_t clen;
AT("slow", start, stop, startst, stopst);
CLEAR(st);
SP("sstart", st, *p);
st = step(m->g, startst, stopst, st, NOTHING, st);
matchp = NULL;
+ if (start == m->beginp)
+ c = OUT;
+ else {
+ /*
+ * XXX Wrong if the previous character was multi-byte.
+ * Newline never is (in encodings supported by FreeBSD),
+ * so this only breaks the ISWORD tests below.
+ */
+ c = (uch)*(start - 1);
+ }
for (;;) {
/* next character */
lastc = c;
- c = (p == m->endp) ? OUT : *p;
+ if (p == m->endp) {
+ c = OUT;
+ clen = 0;
+ } else
+ clen = XMBRTOWC(&c, p, m->endp - p, &m->mbs, BADCHAR);
/* is there an EOL and/or BOL between lastc and c? */
flagch = '\0';
st = step(m->g, startst, stopst, tmp, c, st);
SP("saft", st, c);
assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
- p++;
+ p += clen;
}
return(matchp);
- step - map set of states reachable before char to set reachable after
== static states step(struct re_guts *g, sopno start, sopno stop, \
== states bef, int ch, states aft);
- == #define BOL (OUT+1)
- == #define EOL (BOL+1)
- == #define BOLEOL (BOL+2)
- == #define NOTHING (BOL+3)
- == #define BOW (BOL+4)
- == #define EOW (BOL+5)
- == #define CODEMAX (BOL+5) // highest code used
- == #define NONCHAR(c) ((c) > CHAR_MAX)
- == #define NNONCHAR (CODEMAX-CHAR_MAX)
+ == #define BOL (OUT-1)
+ == #define EOL (BOL-1)
+ == #define BOLEOL (BOL-2)
+ == #define NOTHING (BOL-3)
+ == #define BOW (BOL-4)
+ == #define EOW (BOL-5)
+ == #define BADCHAR (BOL-6)
+ == #define NONCHAR(c) ((c) <= OUT)
*/
static states
step(g, start, stop, bef, ch, aft)
sopno start; /* start state within strip */
sopno stop; /* state after stop state within strip */
states bef; /* states reachable before */
-int ch; /* character or NONCHAR code */
+wint_t ch; /* character or NONCHAR code */
states aft; /* states already known reachable after */
{
cset *cs;
break;
case OCHAR:
/* only characters can match */
- assert(!NONCHAR(ch) || ch != (char)OPND(s));
- if (ch == (char)OPND(s))
+ assert(!NONCHAR(ch) || ch != OPND(s));
+ if (ch == OPND(s))
FWD(aft, bef, 1);
break;
case OBOL:
--- /dev/null
+--- engine.c.orig 2004-11-25 11:38:32.000000000 -0800
++++ engine.c 2005-02-24 14:25:22.000000000 -0800
+@@ -270,7 +270,7 @@
+ break;
+ assert(m->coldp < m->endp);
+ m->coldp += XMBRTOWC(NULL, m->coldp,
+- m->endp - m->coldp, &m->mbs, 0);
++ m->endp - m->coldp, &m->mbs, 0, g->loc);
+ }
+ if (nmatch == 1 && !g->backrefs)
+ break; /* no further info needed */
+@@ -331,7 +331,7 @@
+ NOTE("false alarm");
+ /* recycle starting later */
+ start = m->coldp + XMBRTOWC(NULL, m->coldp,
+- m->endp - m->coldp, &m->mbs, 0);
++ m->endp - m->coldp, &m->mbs, 0, g->loc);
+ assert(start <= stop);
+ }
+
+@@ -409,7 +409,7 @@
+ assert(nope);
+ break;
+ case OCHAR:
+- sp += XMBRTOWC(NULL, sp, stop - start, &m->mbs, 0);
++ sp += XMBRTOWC(NULL, sp, stop - start, &m->mbs, 0, m->g->loc);
+ break;
+ case OBOL:
+ case OEOL:
+@@ -418,7 +418,7 @@
+ break;
+ case OANY:
+ case OANYOF:
+- sp += XMBRTOWC(NULL, sp, stop - start, &m->mbs, 0);
++ sp += XMBRTOWC(NULL, sp, stop - start, &m->mbs, 0, m->g->loc);
+ break;
+ case OBACK_:
+ case O_BACK:
+@@ -585,14 +585,14 @@
+ case OCHAR:
+ if (sp == stop)
+ return(NULL);
+- sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR);
++ sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR, m->g->loc);
+ if (wc != OPND(s))
+ return(NULL);
+ break;
+ case OANY:
+ if (sp == stop)
+ return(NULL);
+- sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR);
++ sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR, m->g->loc);
+ if (wc == BADCHAR)
+ return (NULL);
+ break;
+@@ -600,8 +600,8 @@
+ if (sp == stop)
+ return (NULL);
+ cs = &m->g->sets[OPND(s)];
+- sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR);
+- if (wc == BADCHAR || !CHIN(cs, wc))
++ sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR, m->g->loc);
++ if (wc == BADCHAR || !CHIN(cs, wc, m->g->loc))
+ return(NULL);
+ break;
+ case OBOL:
+@@ -625,8 +625,8 @@
+ (sp < m->endp && *(sp-1) == '\n' &&
+ (m->g->cflags®_NEWLINE)) ||
+ (sp > m->beginp &&
+- !ISWORD(*(sp-1))) ) &&
+- (sp < m->endp && ISWORD(*sp)) )
++ !ISWORD(*(sp-1), m->g->loc)) ) &&
++ (sp < m->endp && ISWORD(*sp, m->g->loc)) )
+ { /* yes */ }
+ else
+ return(NULL);
+@@ -635,8 +635,8 @@
+ if (( (sp == m->endp && !(m->eflags®_NOTEOL)) ||
+ (sp < m->endp && *sp == '\n' &&
+ (m->g->cflags®_NEWLINE)) ||
+- (sp < m->endp && !ISWORD(*sp)) ) &&
+- (sp > m->beginp && ISWORD(*(sp-1))) )
++ (sp < m->endp && !ISWORD(*sp, m->g->loc)) ) &&
++ (sp > m->beginp && ISWORD(*(sp-1), m->g->loc)) )
+ { /* yes */ }
+ else
+ return(NULL);
+@@ -807,7 +807,7 @@
+ if (p == m->endp)
+ c = OUT;
+ else
+- clen = XMBRTOWC(&c, p, m->endp - p, &m->mbs, BADCHAR);
++ clen = XMBRTOWC(&c, p, m->endp - p, &m->mbs, BADCHAR, m->g->loc);
+ if (EQ(st, fresh))
+ coldp = p;
+
+@@ -831,12 +831,12 @@
+ }
+
+ /* how about a word boundary? */
+- if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
+- (c != OUT && ISWORD(c)) ) {
++ if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc, m->g->loc))) &&
++ (c != OUT && ISWORD(c, m->g->loc)) ) {
+ flagch = BOW;
+ }
+- if ( (lastc != OUT && ISWORD(lastc)) &&
+- (flagch == EOL || (c != OUT && !ISWORD(c))) ) {
++ if ( (lastc != OUT && ISWORD(lastc, m->g->loc)) &&
++ (flagch == EOL || (c != OUT && !ISWORD(c, m->g->loc))) ) {
+ flagch = EOW;
+ }
+ if (flagch == BOW || flagch == EOW) {
+@@ -861,7 +861,7 @@
+ assert(coldp != NULL);
+ m->coldp = coldp;
+ if (ISSET(st, stopst))
+- return(p+XMBRTOWC(NULL, p, m->endp - p, &m->mbs, 0));
++ return(p+XMBRTOWC(NULL, p, m->endp - p, &m->mbs, 0, m->g->loc));
+ else
+ return(NULL);
+ }
+@@ -913,7 +913,7 @@
+ c = OUT;
+ clen = 0;
+ } else
+- clen = XMBRTOWC(&c, p, m->endp - p, &m->mbs, BADCHAR);
++ clen = XMBRTOWC(&c, p, m->endp - p, &m->mbs, BADCHAR, m->g->loc);
+
+ /* is there an EOL and/or BOL between lastc and c? */
+ flagch = '\0';
+@@ -935,12 +935,12 @@
+ }
+
+ /* how about a word boundary? */
+- if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
+- (c != OUT && ISWORD(c)) ) {
++ if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc, m->g->loc))) &&
++ (c != OUT && ISWORD(c, m->g->loc)) ) {
+ flagch = BOW;
+ }
+- if ( (lastc != OUT && ISWORD(lastc)) &&
+- (flagch == EOL || (c != OUT && !ISWORD(c))) ) {
++ if ( (lastc != OUT && ISWORD(lastc, m->g->loc)) &&
++ (flagch == EOL || (c != OUT && !ISWORD(c, m->g->loc))) ) {
+ flagch = EOW;
+ }
+ if (flagch == BOW || flagch == EOW) {
+@@ -1031,7 +1031,7 @@
+ break;
+ case OANYOF:
+ cs = &g->sets[OPND(s)];
+- if (!NONCHAR(ch) && CHIN(cs, ch))
++ if (!NONCHAR(ch) && CHIN(cs, ch, g->loc))
+ FWD(aft, bef, 1);
+ break;
+ case OBACK_: /* ignored here */
.\" SUCH DAMAGE.
.\"
.\" @(#)re_format.7 8.3 (Berkeley) 3/20/94
-.\" $FreeBSD: src/lib/libc/regex/re_format.7,v 1.10 2002/01/22 12:38:43 ru Exp $
+.\" $FreeBSD: src/lib/libc/regex/re_format.7,v 1.11 2004/07/02 23:52:12 ru Exp $
.\"
.Dd March 20, 1994
.Dt RE_FORMAT 7
The sequence is a single element of the bracket expression's list.
A bracket expression containing a multi-character collating element
can thus match more than one character,
-e.g. if the collating sequence includes a
+e.g.\& if the collating sequence includes a
.Ql ch
collating element,
then the RE
static char sccsid[] = "@(#)regcomp.c 8.5 (Berkeley) 3/20/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/regex/regcomp.c,v 1.30 2003/02/16 17:29:10 nectar Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/regex/regcomp.c,v 1.34 2004/10/03 15:42:59 stefanf Exp $");
#include <sys/types.h>
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <regex.h>
+#include <runetype.h>
+#include <wchar.h>
+#include <wctype.h>
#include "collate.h"
#include "utils.h"
#include "regex2.h"
-#include "cclass.h"
#include "cname.h"
/*
#endif
/* === regcomp.c === */
-static void p_ere(struct parse *p, int stop);
+static void p_ere(struct parse *p, wint_t stop);
static void p_ere_exp(struct parse *p);
static void p_str(struct parse *p);
-static void p_bre(struct parse *p, int end1, int end2);
+static void p_bre(struct parse *p, wint_t end1, wint_t end2);
static int p_simp_re(struct parse *p, int starordinary);
static int p_count(struct parse *p);
static void p_bracket(struct parse *p);
static void p_b_term(struct parse *p, cset *cs);
static void p_b_cclass(struct parse *p, cset *cs);
static void p_b_eclass(struct parse *p, cset *cs);
-static char p_b_symbol(struct parse *p);
-static char p_b_coll_elem(struct parse *p, int endc);
-static char othercase(int ch);
-static void bothcases(struct parse *p, int ch);
-static void ordinary(struct parse *p, int ch);
+static wint_t p_b_symbol(struct parse *p);
+static wint_t p_b_coll_elem(struct parse *p, wint_t endc);
+static wint_t othercase(wint_t ch);
+static void bothcases(struct parse *p, wint_t ch);
+static void ordinary(struct parse *p, wint_t ch);
static void nonnewline(struct parse *p);
static void repeat(struct parse *p, sopno start, int from, int to);
static int seterr(struct parse *p, int e);
static cset *allocset(struct parse *p);
static void freeset(struct parse *p, cset *cs);
-static int freezeset(struct parse *p, cset *cs);
-static int firstch(struct parse *p, cset *cs);
-static int nch(struct parse *p, cset *cs);
-static void mcadd(struct parse *p, cset *cs, char *cp) __unused;
-#if used
-static void mcsub(cset *cs, char *cp);
-static int mcin(cset *cs, char *cp);
-static char *mcfind(cset *cs, char *cp);
-#endif
-static void mcinvert(struct parse *p, cset *cs);
-static void mccase(struct parse *p, cset *cs);
-static int isinsets(struct re_guts *g, int c);
-static int samesets(struct re_guts *g, int c1, int c2);
-static void categorize(struct parse *p, struct re_guts *g);
+static void CHadd(struct parse *p, cset *cs, wint_t ch);
+static void CHaddrange(struct parse *p, cset *cs, wint_t min, wint_t max);
+static void CHaddtype(struct parse *p, cset *cs, wctype_t wct);
+static wint_t singleton(cset *cs);
static sopno dupl(struct parse *p, sopno start, sopno finish);
static void doemit(struct parse *p, sop op, size_t opnd);
static void doinsert(struct parse *p, sop op, size_t opnd, sopno pos);
static void enlarge(struct parse *p, sopno size);
static void stripsnug(struct parse *p, struct re_guts *g);
static void findmust(struct parse *p, struct re_guts *g);
-static int altoffset(sop *scan, int offset, int mccs);
+static int altoffset(sop *scan, int offset);
static void computejumps(struct parse *p, struct re_guts *g);
static void computematchjumps(struct parse *p, struct re_guts *g);
static sopno pluscount(struct parse *p, struct re_guts *g);
+static wint_t wgetnext(struct parse *p);
#ifdef __cplusplus
}
#define NEXT2() (p->next += 2)
#define NEXTn(n) (p->next += (n))
#define GETNEXT() (*p->next++)
+#define WGETNEXT() wgetnext(p)
#define SETERROR(e) seterr(p, (e))
#define REQUIRE(co, e) ((co) || SETERROR(e))
#define MUSTSEE(c, e) (REQUIRE(MORE() && PEEK() == (c), e))
len = strlen((char *)pattern);
/* do the mallocs early so failure handling is easy */
- g = (struct re_guts *)malloc(sizeof(struct re_guts) +
- (NC-1)*sizeof(cat_t));
+ g = (struct re_guts *)malloc(sizeof(struct re_guts));
if (g == NULL)
return(REG_ESPACE);
p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */
p->pbegin[i] = 0;
p->pend[i] = 0;
}
- g->csetsize = NC;
g->sets = NULL;
- g->setbits = NULL;
g->ncsets = 0;
g->cflags = cflags;
g->iflags = 0;
g->matchjump = NULL;
g->mlen = 0;
g->nsub = 0;
- g->ncategories = 1; /* category 0 is "everything else" */
- g->categories = &g->catspace[-(CHAR_MIN)];
- (void) memset((char *)g->catspace, 0, NC*sizeof(cat_t));
g->backrefs = 0;
/* do it */
g->laststate = THERE();
/* tidy up loose ends and fill things in */
- categorize(p, g);
stripsnug(p, g);
findmust(p, g);
/* only use Boyer-Moore algorithm if the pattern is bigger
struct parse *p;
{
char c;
+ wint_t wc;
sopno pos;
int count;
int count2;
break;
case '\\':
(void)REQUIRE(MORE(), REG_EESCAPE);
- c = GETNEXT();
- ordinary(p, c);
+ wc = WGETNEXT();
+ ordinary(p, wc);
break;
case '{': /* okay as ordinary except if digit follows */
(void)REQUIRE(!MORE() || !isdigit((uch)PEEK()), REG_BADRPT);
/* FALLTHROUGH */
default:
- ordinary(p, c);
+ p->next--;
+ wc = WGETNEXT();
+ ordinary(p, wc);
break;
}
{
(void)REQUIRE(MORE(), REG_EMPTY);
while (MORE())
- ordinary(p, GETNEXT());
+ ordinary(p, WGETNEXT());
}
/*
* Giving end1 as OUT essentially eliminates the end1/end2 check.
*
* This implementation is a bit of a kludge, in that a trailing $ is first
- * taken as an ordinary character and then revised to be an anchor. The
- * only undesirable side effect is that '$' gets included as a character
- * category in such cases. This is fairly harmless; not worth fixing.
+ * taken as an ordinary character and then revised to be an anchor.
* The amount of lookahead needed to avoid this kludge is excessive.
*/
static void
int count2;
sopno pos;
int i;
+ wint_t wc;
sopno subno;
# define BACKSL (1<<CHAR_BIT)
(void)REQUIRE(starordinary, REG_BADRPT);
/* FALLTHROUGH */
default:
- ordinary(p, (char)c);
+ p->next--;
+ wc = WGETNEXT();
+ ordinary(p, wc);
break;
}
/*
- p_bracket - parse a bracketed character list
== static void p_bracket(struct parse *p);
- *
- * Note a significant property of this code: if the allocset() did SETERROR,
- * no set operations are done.
*/
static void
p_bracket(p)
struct parse *p;
{
- cset *cs = allocset(p);
- int invert = 0;
+ cset *cs;
+ wint_t ch;
/* Dept of Truly Sickening Special-Case Kludges */
if (p->next + 5 < p->end && strncmp(p->next, "[:<:]]", 6) == 0) {
return;
}
+ if ((cs = allocset(p)) == NULL)
+ return;
+
+ if (p->g->cflags®_ICASE)
+ cs->icase = 1;
if (EAT('^'))
- invert++; /* make note to invert set at end */
+ cs->invert = 1;
if (EAT(']'))
- CHadd(cs, ']');
+ CHadd(p, cs, ']');
else if (EAT('-'))
- CHadd(cs, '-');
+ CHadd(p, cs, '-');
while (MORE() && PEEK() != ']' && !SEETWO('-', ']'))
p_b_term(p, cs);
if (EAT('-'))
- CHadd(cs, '-');
+ CHadd(p, cs, '-');
(void)MUSTEAT(']', REG_EBRACK);
if (p->error != 0) /* don't mess things up further */
return;
- if (p->g->cflags®_ICASE) {
- int i;
- int ci;
-
- for (i = p->g->csetsize - 1; i >= 0; i--)
- if (CHIN(cs, i) && isalpha(i)) {
- ci = othercase(i);
- if (ci != i)
- CHadd(cs, ci);
- }
- if (cs->multis != NULL)
- mccase(p, cs);
- }
- if (invert) {
- int i;
-
- for (i = p->g->csetsize - 1; i >= 0; i--)
- if (CHIN(cs, i))
- CHsub(cs, i);
- else
- CHadd(cs, i);
- if (p->g->cflags®_NEWLINE)
- CHsub(cs, '\n');
- if (cs->multis != NULL)
- mcinvert(p, cs);
- }
-
- assert(cs->multis == NULL); /* xxx */
+ if (cs->invert && p->g->cflags®_NEWLINE)
+ cs->bmp['\n' >> 3] |= 1 << ('\n' & 7);
- if (nch(p, cs) == 1) { /* optimize singleton sets */
- ordinary(p, firstch(p, cs));
+ if ((ch = singleton(cs)) != OUT) { /* optimize singleton sets */
+ ordinary(p, ch);
freeset(p, cs);
} else
- EMIT(OANYOF, freezeset(p, cs));
+ EMIT(OANYOF, (int)(cs - p->g->sets));
}
/*
cset *cs;
{
char c;
- char start, finish;
- int i;
+ wint_t start, finish;
+ wint_t i;
/* classify what we've got */
switch ((MORE()) ? PEEK() : '\0') {
(void)REQUIRE(EATTWO('=', ']'), REG_ECOLLATE);
break;
default: /* symbol, ordinary character, or range */
-/* xxx revision needed for multichar stuff */
start = p_b_symbol(p);
if (SEE('-') && MORE2() && PEEK2() != ']') {
/* range */
} else
finish = start;
if (start == finish)
- CHadd(cs, start);
+ CHadd(p, cs, start);
else {
if (__collate_load_error) {
(void)REQUIRE((uch)start <= (uch)finish, REG_ERANGE);
- for (i = (uch)start; i <= (uch)finish; i++)
- CHadd(cs, i);
+ CHaddrange(p, cs, start, finish);
} else {
(void)REQUIRE(__collate_range_cmp(start, finish) <= 0, REG_ERANGE);
- for (i = CHAR_MIN; i <= CHAR_MAX; i++) {
+ for (i = 0; i <= UCHAR_MAX; i++) {
if ( __collate_range_cmp(start, i) <= 0
&& __collate_range_cmp(i, finish) <= 0
)
- CHadd(cs, i);
+ CHadd(p, cs, i);
}
}
}
struct parse *p;
cset *cs;
{
- int c;
char *sp = p->next;
- struct cclass *cp;
size_t len;
+ wctype_t wct;
+ char clname[16];
while (MORE() && isalpha((uch)PEEK()))
NEXT();
len = p->next - sp;
- for (cp = cclasses; cp->name != NULL; cp++)
- if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0')
- break;
- if (cp->name == NULL) {
- /* oops, didn't find it */
+ if (len >= sizeof(clname) - 1) {
SETERROR(REG_ECTYPE);
return;
}
-
- switch (cp->fidx) {
- case CALNUM:
- for (c = CHAR_MIN; c <= CHAR_MAX; c++)
- if (isalnum((uch)c))
- CHadd(cs, c);
- break;
- case CALPHA:
- for (c = CHAR_MIN; c <= CHAR_MAX; c++)
- if (isalpha((uch)c))
- CHadd(cs, c);
- break;
- case CBLANK:
- for (c = CHAR_MIN; c <= CHAR_MAX; c++)
- if (isblank((uch)c))
- CHadd(cs, c);
- break;
- case CCNTRL:
- for (c = CHAR_MIN; c <= CHAR_MAX; c++)
- if (iscntrl((uch)c))
- CHadd(cs, c);
- break;
- case CDIGIT:
- for (c = CHAR_MIN; c <= CHAR_MAX; c++)
- if (isdigit((uch)c))
- CHadd(cs, c);
- break;
- case CGRAPH:
- for (c = CHAR_MIN; c <= CHAR_MAX; c++)
- if (isgraph((uch)c))
- CHadd(cs, c);
- break;
- case CLOWER:
- for (c = CHAR_MIN; c <= CHAR_MAX; c++)
- if (islower((uch)c))
- CHadd(cs, c);
- break;
- case CPRINT:
- for (c = CHAR_MIN; c <= CHAR_MAX; c++)
- if (isprint((uch)c))
- CHadd(cs, c);
- break;
- case CPUNCT:
- for (c = CHAR_MIN; c <= CHAR_MAX; c++)
- if (ispunct((uch)c))
- CHadd(cs, c);
- break;
- case CSPACE:
- for (c = CHAR_MIN; c <= CHAR_MAX; c++)
- if (isspace((uch)c))
- CHadd(cs, c);
- break;
- case CUPPER:
- for (c = CHAR_MIN; c <= CHAR_MAX; c++)
- if (isupper((uch)c))
- CHadd(cs, c);
- break;
- case CXDIGIT:
- for (c = CHAR_MIN; c <= CHAR_MAX; c++)
- if (isxdigit((uch)c))
- CHadd(cs, c);
- break;
+ memcpy(clname, sp, len);
+ clname[len] = '\0';
+ if ((wct = wctype(clname)) == 0) {
+ SETERROR(REG_ECTYPE);
+ return;
}
-#if 0
- for (u = cp->multis; *u != '\0'; u += strlen(u) + 1)
- MCadd(p, cs, u);
-#endif
+ CHaddtype(p, cs, wct);
}
/*
struct parse *p;
cset *cs;
{
- char c;
+ wint_t c;
c = p_b_coll_elem(p, '=');
- CHadd(cs, c);
+ CHadd(p, cs, c);
}
/*
- p_b_symbol - parse a character or [..]ed multicharacter collating symbol
== static char p_b_symbol(struct parse *p);
*/
-static char /* value of symbol */
+static wint_t /* value of symbol */
p_b_symbol(p)
struct parse *p;
{
- char value;
+ wint_t value;
(void)REQUIRE(MORE(), REG_EBRACK);
if (!EATTWO('[', '.'))
- return(GETNEXT());
+ return(WGETNEXT());
/* collating symbol */
value = p_b_coll_elem(p, '.');
- p_b_coll_elem - parse a collating-element name and look it up
== static char p_b_coll_elem(struct parse *p, int endc);
*/
-static char /* value of collating element */
+static wint_t /* value of collating element */
p_b_coll_elem(p, endc)
struct parse *p;
-int endc; /* name ended by endc,']' */
+wint_t endc; /* name ended by endc,']' */
{
char *sp = p->next;
struct cname *cp;
int len;
+ mbstate_t mbs;
+ wchar_t wc;
+ size_t clen;
while (MORE() && !SEETWO(endc, ']'))
NEXT();
for (cp = cnames; cp->name != NULL; cp++)
if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0')
return(cp->code); /* known name */
- if (len == 1)
- return(*sp); /* single character */
- SETERROR(REG_ECOLLATE); /* neither */
+ memset(&mbs, 0, sizeof(mbs));
+ if ((clen = mbrtowc(&wc, sp, len, &mbs)) == len)
+ return (wc); /* single character */
+ else if (clen == (size_t)-1 || clen == (size_t)-2)
+ SETERROR(REG_ILLSEQ);
+ else
+ SETERROR(REG_ECOLLATE); /* neither */
return(0);
}
- othercase - return the case counterpart of an alphabetic
== static char othercase(int ch);
*/
-static char /* if no counterpart, return ch */
+static wint_t /* if no counterpart, return ch */
othercase(ch)
-int ch;
+wint_t ch;
{
- ch = (uch)ch;
- assert(isalpha(ch));
- if (isupper(ch))
- return(tolower(ch));
- else if (islower(ch))
- return(toupper(ch));
+ assert(iswalpha(ch));
+ if (iswupper(ch))
+ return(towlower(ch));
+ else if (iswlower(ch))
+ return(towupper(ch));
else /* peculiar, but could happen */
return(ch);
}
static void
bothcases(p, ch)
struct parse *p;
-int ch;
+wint_t ch;
{
char *oldnext = p->next;
char *oldend = p->end;
- char bracket[3];
+ char bracket[3 + MB_LEN_MAX];
+ size_t n;
+ mbstate_t mbs;
- ch = (uch)ch;
assert(othercase(ch) != ch); /* p_bracket() would recurse */
p->next = bracket;
- p->end = bracket+2;
- bracket[0] = ch;
- bracket[1] = ']';
- bracket[2] = '\0';
+ memset(&mbs, 0, sizeof(mbs));
+ n = wcrtomb(bracket, ch, &mbs);
+ assert(n != (size_t)-1);
+ bracket[n] = ']';
+ bracket[n + 1] = '\0';
+ p->end = bracket+n+1;
p_bracket(p);
- assert(p->next == bracket+2);
+ assert(p->next == p->end);
p->next = oldnext;
p->end = oldend;
}
static void
ordinary(p, ch)
struct parse *p;
-int ch;
+wint_t ch;
{
- cat_t *cap = p->g->categories;
+ cset *cs;
- if ((p->g->cflags®_ICASE) && isalpha((uch)ch) && othercase(ch) != ch)
+ if ((p->g->cflags®_ICASE) && iswalpha(ch) && othercase(ch) != ch)
bothcases(p, ch);
+ else if ((ch & OPDMASK) == ch)
+ EMIT(OCHAR, ch);
else {
- EMIT(OCHAR, (uch)ch);
- if (cap[ch] == 0)
- cap[ch] = p->g->ncategories++;
+ /*
+ * Kludge: character is too big to fit into an OCHAR operand.
+ * Emit a singleton set.
+ */
+ if ((cs = allocset(p)) == NULL)
+ return;
+ CHadd(p, cs, ch);
+ EMIT(OANYOF, (int)(cs - p->g->sets));
}
}
}
}
+/*
+ - wgetnext - helper function for WGETNEXT() macro. Gets the next wide
+ - character from the parse struct, signals a REG_ILLSEQ error if the
+ - character can't be converted. Returns the number of bytes consumed.
+ */
+static wint_t
+wgetnext(p)
+struct parse *p;
+{
+ mbstate_t mbs;
+ wchar_t wc;
+ size_t n;
+
+ memset(&mbs, 0, sizeof(mbs));
+ n = mbrtowc(&wc, p->next, p->end - p->next, &mbs);
+ if (n == (size_t)-1 || n == (size_t)-2) {
+ SETERROR(REG_ILLSEQ);
+ return (0);
+ }
+ if (n == 0)
+ n = 1;
+ p->next += n;
+ return (wc);
+}
+
/*
- seterr - set an error condition
== static int seterr(struct parse *p, int e);
allocset(p)
struct parse *p;
{
- int no = p->g->ncsets++;
- size_t nc;
- size_t nbytes;
- cset *cs;
- size_t css = (size_t)p->g->csetsize;
- int i;
+ cset *cs, *ncs;
- if (no >= p->ncsalloc) { /* need another column of space */
- p->ncsalloc += CHAR_BIT;
- nc = p->ncsalloc;
- assert(nc % CHAR_BIT == 0);
- nbytes = nc / CHAR_BIT * css;
- if (p->g->sets == NULL)
- p->g->sets = (cset *)malloc(nc * sizeof(cset));
- else
- p->g->sets = (cset *)reallocf((char *)p->g->sets,
- nc * sizeof(cset));
- if (p->g->setbits == NULL)
- p->g->setbits = (uch *)malloc(nbytes);
- else {
- p->g->setbits = (uch *)reallocf((char *)p->g->setbits,
- nbytes);
- /* xxx this isn't right if setbits is now NULL */
- for (i = 0; i < no; i++)
- p->g->sets[i].ptr = p->g->setbits + css*(i/CHAR_BIT);
- }
- if (p->g->sets != NULL && p->g->setbits != NULL)
- (void) memset((char *)p->g->setbits + (nbytes - css),
- 0, css);
- else {
- no = 0;
- SETERROR(REG_ESPACE);
- /* caller's responsibility not to do set ops */
- }
+ ncs = realloc(p->g->sets, (p->g->ncsets + 1) * sizeof(*ncs));
+ if (ncs == NULL) {
+ SETERROR(REG_ESPACE);
+ return (NULL);
}
-
- assert(p->g->sets != NULL); /* xxx */
- cs = &p->g->sets[no];
- cs->ptr = p->g->setbits + css*((no)/CHAR_BIT);
- cs->mask = 1 << ((no) % CHAR_BIT);
- cs->hash = 0;
- cs->smultis = 0;
- cs->multis = NULL;
+ p->g->sets = ncs;
+ cs = &p->g->sets[p->g->ncsets++];
+ memset(cs, 0, sizeof(*cs));
return(cs);
}
struct parse *p;
cset *cs;
{
- int i;
cset *top = &p->g->sets[p->g->ncsets];
- size_t css = (size_t)p->g->csetsize;
- for (i = 0; i < css; i++)
- CHsub(cs, i);
+ free(cs->wides);
+ free(cs->ranges);
+ free(cs->types);
+ memset(cs, 0, sizeof(*cs));
if (cs == top-1) /* recover only the easy case */
p->g->ncsets--;
}
/*
- - freezeset - final processing on a set of characters
- == static int freezeset(struct parse *p, cset *cs);
- *
- * The main task here is merging identical sets. This is usually a waste
- * of time (although the hash code minimizes the overhead), but can win
- * big if REG_ICASE is being used. REG_ICASE, by the way, is why the hash
- * is done using addition rather than xor -- all ASCII [aA] sets xor to
- * the same value!
- */
-static int /* set number */
-freezeset(p, cs)
-struct parse *p;
-cset *cs;
-{
- short h = cs->hash;
- int i;
- cset *top = &p->g->sets[p->g->ncsets];
- cset *cs2;
- size_t css = (size_t)p->g->csetsize;
-
- /* look for an earlier one which is the same */
- for (cs2 = &p->g->sets[0]; cs2 < top; cs2++)
- if (cs2->hash == h && cs2 != cs) {
- /* maybe */
- for (i = 0; i < css; i++)
- if (!!CHIN(cs2, i) != !!CHIN(cs, i))
- break; /* no */
- if (i == css)
- break; /* yes */
- }
-
- if (cs2 < top) { /* found one */
- freeset(p, cs);
- cs = cs2;
- }
-
- return((int)(cs - p->g->sets));
-}
-
-/*
- - firstch - return first character in a set (which must have at least one)
- == static int firstch(struct parse *p, cset *cs);
+ - singleton - Determine whether a set contains only one character,
+ - returning it if so, otherwise returning OUT.
*/
-static int /* character; there is no "none" value */
-firstch(p, cs)
-struct parse *p;
+static wint_t
+singleton(cs)
cset *cs;
{
- int i;
- size_t css = (size_t)p->g->csetsize;
-
- for (i = 0; i < css; i++)
- if (CHIN(cs, i))
- return((char)i);
- assert(never);
- return(0); /* arbitrary */
-}
+ wint_t i, s, n;
-/*
- - nch - number of characters in a set
- == static int nch(struct parse *p, cset *cs);
- */
-static int
-nch(p, cs)
-struct parse *p;
-cset *cs;
-{
- int i;
- size_t css = (size_t)p->g->csetsize;
- int n = 0;
-
- for (i = 0; i < css; i++)
- if (CHIN(cs, i))
+ for (i = n = 0; i < NC; i++)
+ if (CHIN(cs, i)) {
n++;
- return(n);
+ s = i;
+ }
+ if (n == 1)
+ return (s);
+ if (cs->nwides == 1 && cs->nranges == 0 && cs->ntypes == 0 &&
+ cs->icase == 0)
+ return (cs->wides[0]);
+ /* Don't bother handling the other cases. */
+ return (OUT);
}
/*
- - mcadd - add a collating element to a cset
- == static void mcadd(struct parse *p, cset *cs, \
- == char *cp);
+ - CHadd - add character to character set.
*/
static void
-mcadd(p, cs, cp)
+CHadd(p, cs, ch)
struct parse *p;
cset *cs;
-char *cp;
+wint_t ch;
{
- size_t oldend = cs->smultis;
-
- cs->smultis += strlen(cp) + 1;
- if (cs->multis == NULL)
- cs->multis = malloc(cs->smultis);
- else
- cs->multis = reallocf(cs->multis, cs->smultis);
- if (cs->multis == NULL) {
- SETERROR(REG_ESPACE);
- return;
+ wint_t nch, *newwides;
+ assert(ch >= 0);
+ if (ch < NC)
+ cs->bmp[ch >> 3] |= 1 << (ch & 7);
+ else {
+ newwides = realloc(cs->wides, (cs->nwides + 1) *
+ sizeof(*cs->wides));
+ if (newwides == NULL) {
+ SETERROR(REG_ESPACE);
+ return;
+ }
+ cs->wides = newwides;
+ cs->wides[cs->nwides++] = ch;
+ }
+ if (cs->icase) {
+ if ((nch = towlower(ch)) < NC)
+ cs->bmp[nch >> 3] |= 1 << (nch & 7);
+ if ((nch = towupper(ch)) < NC)
+ cs->bmp[nch >> 3] |= 1 << (nch & 7);
}
-
- (void) strcpy(cs->multis + oldend - 1, cp);
- cs->multis[cs->smultis - 1] = '\0';
}
-#if used
/*
- - mcsub - subtract a collating element from a cset
- == static void mcsub(cset *cs, char *cp);
+ - CHaddrange - add all characters in the range [min,max] to a character set.
*/
static void
-mcsub(cs, cp)
+CHaddrange(p, cs, min, max)
+struct parse *p;
cset *cs;
-char *cp;
+wint_t min, max;
{
- char *fp = mcfind(cs, cp);
- size_t len = strlen(fp);
-
- assert(fp != NULL);
- (void) memmove(fp, fp + len + 1,
- cs->smultis - (fp + len + 1 - cs->multis));
- cs->smultis -= len;
+ crange *newranges;
- if (cs->smultis == 0) {
- free(cs->multis);
- cs->multis = NULL;
+ for (; min < NC && min <= max; min++)
+ CHadd(p, cs, min);
+ if (min >= max)
+ return;
+ newranges = realloc(cs->ranges, (cs->nranges + 1) *
+ sizeof(*cs->ranges));
+ if (newranges == NULL) {
+ SETERROR(REG_ESPACE);
return;
}
-
- cs->multis = reallocf(cs->multis, cs->smultis);
- assert(cs->multis != NULL);
-}
-
-/*
- - mcin - is a collating element in a cset?
- == static int mcin(cset *cs, char *cp);
- */
-static int
-mcin(cs, cp)
-cset *cs;
-char *cp;
-{
- return(mcfind(cs, cp) != NULL);
-}
-
-/*
- - mcfind - find a collating element in a cset
- == static char *mcfind(cset *cs, char *cp);
- */
-static char *
-mcfind(cs, cp)
-cset *cs;
-char *cp;
-{
- char *p;
-
- if (cs->multis == NULL)
- return(NULL);
- for (p = cs->multis; *p != '\0'; p += strlen(p) + 1)
- if (strcmp(cp, p) == 0)
- return(p);
- return(NULL);
+ cs->ranges = newranges;
+ cs->ranges[cs->nranges].min = min;
+ cs->ranges[cs->nranges].min = max;
+ cs->nranges++;
}
-#endif
/*
- - mcinvert - invert the list of collating elements in a cset
- == static void mcinvert(struct parse *p, cset *cs);
- *
- * This would have to know the set of possibilities. Implementation
- * is deferred.
+ - CHaddtype - add all characters of a certain type to a character set.
*/
static void
-mcinvert(p, cs)
+CHaddtype(p, cs, wct)
struct parse *p;
cset *cs;
+wctype_t wct;
{
- assert(cs->multis == NULL); /* xxx */
-}
-
-/*
- - mccase - add case counterparts of the list of collating elements in a cset
- == static void mccase(struct parse *p, cset *cs);
- *
- * This would have to know the set of possibilities. Implementation
- * is deferred.
- */
-static void
-mccase(p, cs)
-struct parse *p;
-cset *cs;
-{
- assert(cs->multis == NULL); /* xxx */
-}
-
-/*
- - isinsets - is this character in any sets?
- == static int isinsets(struct re_guts *g, int c);
- */
-static int /* predicate */
-isinsets(g, c)
-struct re_guts *g;
-int c;
-{
- uch *col;
- int i;
- int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT;
- unsigned uc = (uch)c;
-
- for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize)
- if (col[uc] != 0)
- return(1);
- return(0);
-}
-
-/*
- - samesets - are these two characters in exactly the same sets?
- == static int samesets(struct re_guts *g, int c1, int c2);
- */
-static int /* predicate */
-samesets(g, c1, c2)
-struct re_guts *g;
-int c1;
-int c2;
-{
- uch *col;
- int i;
- int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT;
- unsigned uc1 = (uch)c1;
- unsigned uc2 = (uch)c2;
-
- for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize)
- if (col[uc1] != col[uc2])
- return(0);
- return(1);
-}
-
-/*
- - categorize - sort out character categories
- == static void categorize(struct parse *p, struct re_guts *g);
- */
-static void
-categorize(p, g)
-struct parse *p;
-struct re_guts *g;
-{
- cat_t *cats = g->categories;
- int c;
- int c2;
- cat_t cat;
-
- /* avoid making error situations worse */
- if (p->error != 0)
+ wint_t i;
+ wctype_t *newtypes;
+
+ for (i = 0; i < NC; i++)
+ if (iswctype(i, wct))
+ CHadd(p, cs, i);
+ newtypes = realloc(cs->types, (cs->ntypes + 1) *
+ sizeof(*cs->types));
+ if (newtypes == NULL) {
+ SETERROR(REG_ESPACE);
return;
-
- for (c = CHAR_MIN; c <= CHAR_MAX; c++)
- if (cats[c] == 0 && isinsets(g, c)) {
- cat = g->ncategories++;
- cats[c] = cat;
- for (c2 = c+1; c2 <= CHAR_MAX; c2++)
- if (cats[c2] == 0 && samesets(g, c, c2))
- cats[c2] = cat;
- }
+ }
+ cs->types = newtypes;
+ cs->types[cs->ntypes++] = wct;
}
/*
sopno newlen;
sop s;
char *cp;
- sopno i;
int offset;
- int cs, mccs;
+ char buf[MB_LEN_MAX];
+ size_t clen;
+ mbstate_t mbs;
/* avoid making error situations worse */
if (p->error != 0)
return;
- /* Find out if we can handle OANYOF or not */
- mccs = 0;
- for (cs = 0; cs < g->ncsets; cs++)
- if (g->sets[cs].multis != NULL)
- mccs = 1;
+ /*
+ * It's not generally safe to do a ``char'' substring search on
+ * multibyte character strings, but it's safe for at least
+ * UTF-8 (see RFC 3629).
+ */
+ if (MB_CUR_MAX > 1 &&
+ strcmp(_CurrentRuneLocale->__encoding, "UTF-8") != 0)
+ return;
/* find the longest OCHAR sequence in strip */
newlen = 0;
s = *scan++;
switch (OP(s)) {
case OCHAR: /* sequence member */
- if (newlen == 0) /* new sequence */
+ if (newlen == 0) { /* new sequence */
+ memset(&mbs, 0, sizeof(mbs));
newstart = scan - 1;
- newlen++;
+ }
+ clen = wcrtomb(buf, OPND(s), &mbs);
+ if (clen == (size_t)-1)
+ goto toohard;
+ newlen += clen;
break;
case OPLUS_: /* things that don't break one */
case OLPAREN:
break;
case OQUEST_: /* things that must be skipped */
case OCH_:
- offset = altoffset(scan, offset, mccs);
+ offset = altoffset(scan, offset);
scan--;
do {
scan += OPND(s);
if (offset > -1)
offset++;
newlen = 0;
- /* And, now, if we found out we can't deal with
- * it, make offset = -1.
- */
- if (mccs)
- offset = -1;
break;
+ toohard:
default:
/* Anything here makes it impossible or too hard
* to calculate the offset -- so we give up;
}
cp = g->must;
scan = start;
- for (i = g->mlen; i > 0; i--) {
+ memset(&mbs, 0, sizeof(mbs));
+ while (cp < g->must + g->mlen) {
while (OP(s = *scan++) != OCHAR)
continue;
- assert(cp < g->must + g->mlen);
- *cp++ = (char)OPND(s);
+ clen = wcrtomb(cp, OPND(s), &mbs);
+ assert(clen != (size_t)-1);
+ cp += clen;
}
assert(cp == g->must + g->mlen);
*cp++ = '\0'; /* just on general principles */
/*
- altoffset - choose biggest offset among multiple choices
- == static int altoffset(sop *scan, int offset, int mccs);
+ == static int altoffset(sop *scan, int offset);
*
* Compute, recursively if necessary, the largest offset among multiple
* re paths.
*/
static int
-altoffset(scan, offset, mccs)
+altoffset(scan, offset)
sop *scan;
int offset;
-int mccs;
{
int largest;
int try;
break;
case OQUEST_:
case OCH_:
- try = altoffset(scan, try, mccs);
+ try = altoffset(scan, try);
if (try == -1)
return -1;
scan--;
scan++;
break;
case OANYOF:
- if (mccs)
- return -1;
case OCHAR:
case OANY:
try++;
--- /dev/null
+--- regcomp.c.orig 2004-11-25 11:38:32.000000000 -0800
++++ regcomp.c 2005-02-24 13:46:56.000000000 -0800
+@@ -43,6 +43,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/regex/regcomp.c,v 1.34 2004/10/03 15:42:59 stefanf Exp $");
+
++#include "xlocale_private.h"
++
+ #include <sys/types.h>
+ #include <stdio.h>
+ #include <string.h>
+@@ -73,6 +75,9 @@
+ sopno ssize; /* malloced strip size (allocated) */
+ sopno slen; /* malloced strip length (used) */
+ int ncsalloc; /* number of csets allocated */
++#if __DARWIN_UNIX03
++ int zerorepeats;
++#endif /* __DARWIN_UNIX03 */
+ struct re_guts *g;
+ # define NPAREN 10 /* we need to remember () 1-9 for back refs */
+ sopno pbegin[NPAREN]; /* -> ( ([0] unused) */
+@@ -97,7 +102,7 @@
+ static void p_b_eclass(struct parse *p, cset *cs);
+ static wint_t p_b_symbol(struct parse *p);
+ static wint_t p_b_coll_elem(struct parse *p, wint_t endc);
+-static wint_t othercase(wint_t ch);
++static wint_t othercase(wint_t ch, locale_t loc);
+ static void bothcases(struct parse *p, wint_t ch);
+ static void ordinary(struct parse *p, wint_t ch);
+ static void nonnewline(struct parse *p);
+@@ -108,7 +113,7 @@
+ static void CHadd(struct parse *p, cset *cs, wint_t ch);
+ static void CHaddrange(struct parse *p, cset *cs, wint_t min, wint_t max);
+ static void CHaddtype(struct parse *p, cset *cs, wctype_t wct);
+-static wint_t singleton(cset *cs);
++static wint_t singleton(cset *cs, locale_t loc);
+ static sopno dupl(struct parse *p, sopno start, sopno finish);
+ static void doemit(struct parse *p, sop op, size_t opnd);
+ static void doinsert(struct parse *p, sop op, size_t opnd, sopno pos);
+@@ -227,10 +232,14 @@
+ p->end = p->next + len;
+ p->error = 0;
+ p->ncsalloc = 0;
++#if __DARWIN_UNIX03
++ p->zerorepeats = 0;
++#endif /* __DARWIN_UNIX03 */
+ for (i = 0; i < NPAREN; i++) {
+ p->pbegin[i] = 0;
+ p->pend[i] = 0;
+ }
++ g->loc = __current_locale();
+ g->sets = NULL;
+ g->ncsets = 0;
+ g->cflags = cflags;
+@@ -308,8 +317,12 @@
+ conc = HERE();
+ while (MORE() && (c = PEEK()) != '|' && c != stop)
+ p_ere_exp(p);
++#if __DARWIN_UNIX03
++ if (!p->zerorepeats) REQUIRE(HERE() != conc, REG_EMPTY); /* require nonempty */
++ else p->zerorepeats--;
++#else
+ (void)REQUIRE(HERE() != conc, REG_EMPTY); /* require nonempty */
+-
++#endif
+ if (!EAT('|'))
+ break; /* NOTE BREAK OUT */
+
+@@ -417,7 +430,7 @@
+ ordinary(p, wc);
+ break;
+ case '{': /* okay as ordinary except if digit follows */
+- (void)REQUIRE(!MORE() || !isdigit((uch)PEEK()), REG_BADRPT);
++ (void)REQUIRE(!MORE() || !isdigit_l((uch)PEEK(), p->g->loc), REG_BADRPT);
+ /* FALLTHROUGH */
+ default:
+ p->next--;
+@@ -431,7 +444,7 @@
+ c = PEEK();
+ /* we call { a repetition if followed by a digit */
+ if (!( c == '*' || c == '+' || c == '?' ||
+- (c == '{' && MORE2() && isdigit((uch)PEEK2())) ))
++ (c == '{' && MORE2() && isdigit_l((uch)PEEK2(), p->g->loc)) ))
+ return; /* no repetition, we're done */
+ NEXT();
+
+@@ -460,7 +473,7 @@
+ case '{':
+ count = p_count(p);
+ if (EAT(',')) {
+- if (isdigit((uch)PEEK())) {
++ if (isdigit_l((uch)PEEK(), p->g->loc)) {
+ count2 = p_count(p);
+ (void)REQUIRE(count <= count2, REG_BADBR);
+ } else /* single number with comma */
+@@ -481,7 +494,7 @@
+ return;
+ c = PEEK();
+ if (!( c == '*' || c == '+' || c == '?' ||
+- (c == '{' && MORE2() && isdigit((uch)PEEK2())) ) )
++ (c == '{' && MORE2() && isdigit_l((uch)PEEK2(), p->g->loc)) ) )
+ return;
+ SETERROR(REG_BADRPT);
+ }
+@@ -494,7 +507,12 @@
+ p_str(p)
+ struct parse *p;
+ {
++#if __DARWIN_UNIX03
++ if (!p->zerorepeats) REQUIRE(MORE(), REG_EMPTY);
++ else p->zerorepeats--;
++#else /* !__DARWIN_UNIX03 */
+ (void)REQUIRE(MORE(), REG_EMPTY);
++#endif /* __DARWIN_UNIX03 */
+ while (MORE())
+ ordinary(p, WGETNEXT());
+ }
+@@ -534,8 +552,12 @@
+ p->g->iflags |= USEEOL;
+ p->g->neol++;
+ }
+-
++#if __DARWIN_UNIX03
++ if (!p->zerorepeats) REQUIRE(HERE() != start, REG_EMPTY); /* require nonempty */
++ else p->zerorepeats--;
++#else /* !__DARWIN_UNIX03 */
+ (void)REQUIRE(HERE() != start, REG_EMPTY); /* require nonempty */
++#endif /* __DARWIN_UNIX03 */
+ }
+
+ /*
+@@ -639,7 +661,7 @@
+ } else if (EATTWO('\\', '{')) {
+ count = p_count(p);
+ if (EAT(',')) {
+- if (MORE() && isdigit((uch)PEEK())) {
++ if (MORE() && isdigit_l((uch)PEEK(), p->g->loc)) {
+ count2 = p_count(p);
+ (void)REQUIRE(count <= count2, REG_BADBR);
+ } else /* single number with comma */
+@@ -670,7 +692,7 @@
+ int count = 0;
+ int ndigits = 0;
+
+- while (MORE() && isdigit((uch)PEEK()) && count <= DUPMAX) {
++ while (MORE() && isdigit_l((uch)PEEK(), p->g->loc) && count <= DUPMAX) {
+ count = count*10 + (GETNEXT() - '0');
+ ndigits++;
+ }
+@@ -709,10 +731,21 @@
+ cs->icase = 1;
+ if (EAT('^'))
+ cs->invert = 1;
++#if __DARWIN_UNIX03
++ if (PEEK2() != '-') { /* Don't eat '-' or ']' if they're part of ranges */
++ if (EAT(']'))
++ CHadd(p, cs, ']');
++ else if (EAT('-'))
++ CHadd(p, cs, '-');
++ }
++ if (MORE() && !SEETWO('-',']')) /* Parse RE []-'] */
++ p_b_term(p, cs);
++#else /* !__DARWIN_UNIX03 */
+ if (EAT(']'))
+ CHadd(p, cs, ']');
+ else if (EAT('-'))
+ CHadd(p, cs, '-');
++#endif /* __DARWIN_UNIX03 */
+ while (MORE() && PEEK() != ']' && !SEETWO('-', ']'))
+ p_b_term(p, cs);
+ if (EAT('-'))
+@@ -725,7 +758,7 @@
+ if (cs->invert && p->g->cflags®_NEWLINE)
+ cs->bmp['\n' >> 3] |= 1 << ('\n' & 7);
+
+- if ((ch = singleton(cs)) != OUT) { /* optimize singleton sets */
++ if ((ch = singleton(cs, p->g->loc)) != OUT) { /* optimize singleton sets */
+ ordinary(p, ch);
+ freeset(p, cs);
+ } else
+@@ -751,8 +784,16 @@
+ c = (MORE2()) ? PEEK2() : '\0';
+ break;
+ case '-':
++#if __DARWIN_UNIX03
++ if (PEEK2() != '-') { /* Allow [---] */
++ SETERROR(REG_ERANGE);
++ return; /* NOTE RETURN */
++ } else
++ c = '-';
++#else /* !__DARWIN_UNIX03 */
+ SETERROR(REG_ERANGE);
+ return; /* NOTE RETURN */
++#endif /* __DARWIN_UNIX03 */
+ break;
+ default:
+ c = '\0';
+@@ -773,7 +814,11 @@
+ NEXT2();
+ (void)REQUIRE(MORE(), REG_EBRACK);
+ c = PEEK();
++#if __DARWIN_UNIX03
++ REQUIRE(c != '-', REG_ECOLLATE); /* allow [=]=] */
++#else /* !__DARWIN_UNIX03 */
+ (void)REQUIRE(c != '-' && c != ']', REG_ECOLLATE);
++#endif /* __DARWIN_UNIX03 */
+ p_b_eclass(p, cs);
+ (void)REQUIRE(MORE(), REG_EBRACK);
+ (void)REQUIRE(EATTWO('=', ']'), REG_ECOLLATE);
+@@ -792,14 +837,14 @@
+ if (start == finish)
+ CHadd(p, cs, start);
+ else {
+- if (__collate_load_error) {
++ if (p->g->loc->__collate_load_error) {
+ (void)REQUIRE((uch)start <= (uch)finish, REG_ERANGE);
+ CHaddrange(p, cs, start, finish);
+ } else {
+- (void)REQUIRE(__collate_range_cmp(start, finish) <= 0, REG_ERANGE);
++ (void)REQUIRE(__collate_range_cmp(start, finish, p->g->loc) <= 0, REG_ERANGE);
+ for (i = 0; i <= UCHAR_MAX; i++) {
+- if ( __collate_range_cmp(start, i) <= 0
+- && __collate_range_cmp(i, finish) <= 0
++ if ( __collate_range_cmp(start, i, p->g->loc) <= 0
++ && __collate_range_cmp(i, finish, p->g->loc) <= 0
+ )
+ CHadd(p, cs, i);
+ }
+@@ -823,7 +868,7 @@
+ wctype_t wct;
+ char clname[16];
+
+- while (MORE() && isalpha((uch)PEEK()))
++ while (MORE() && isalpha_l((uch)PEEK(), p->g->loc))
+ NEXT();
+ len = p->next - sp;
+ if (len >= sizeof(clname) - 1) {
+@@ -832,7 +877,7 @@
+ }
+ memcpy(clname, sp, len);
+ clname[len] = '\0';
+- if ((wct = wctype(clname)) == 0) {
++ if ((wct = wctype_l(clname, p->g->loc)) == 0) {
+ SETERROR(REG_ECTYPE);
+ return;
+ }
+@@ -903,7 +948,7 @@
+ if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0')
+ return(cp->code); /* known name */
+ memset(&mbs, 0, sizeof(mbs));
+- if ((clen = mbrtowc(&wc, sp, len, &mbs)) == len)
++ if ((clen = mbrtowc_l(&wc, sp, len, &mbs, p->g->loc)) == len)
+ return (wc); /* single character */
+ else if (clen == (size_t)-1 || clen == (size_t)-2)
+ SETERROR(REG_ILLSEQ);
+@@ -914,17 +959,18 @@
+
+ /*
+ - othercase - return the case counterpart of an alphabetic
+- == static char othercase(int ch);
++ == static char othercase(int ch, locale_t loc);
+ */
+ static wint_t /* if no counterpart, return ch */
+-othercase(ch)
++othercase(ch, loc)
+ wint_t ch;
++locale_t loc;
+ {
+- assert(iswalpha(ch));
+- if (iswupper(ch))
+- return(towlower(ch));
+- else if (iswlower(ch))
+- return(towupper(ch));
++ assert(iswalpha_l(ch, loc));
++ if (iswupper_l(ch, loc))
++ return(towlower_l(ch, loc));
++ else if (iswlower_l(ch, loc))
++ return(towupper_l(ch, loc));
+ else /* peculiar, but could happen */
+ return(ch);
+ }
+@@ -946,10 +992,10 @@
+ size_t n;
+ mbstate_t mbs;
+
+- assert(othercase(ch) != ch); /* p_bracket() would recurse */
++ assert(othercase(ch, p->g->loc) != ch); /* p_bracket() would recurse */
+ p->next = bracket;
+ memset(&mbs, 0, sizeof(mbs));
+- n = wcrtomb(bracket, ch, &mbs);
++ n = wcrtomb_l(bracket, ch, &mbs, p->g->loc);
+ assert(n != (size_t)-1);
+ bracket[n] = ']';
+ bracket[n + 1] = '\0';
+@@ -971,7 +1017,7 @@
+ {
+ cset *cs;
+
+- if ((p->g->cflags®_ICASE) && iswalpha(ch) && othercase(ch) != ch)
++ if ((p->g->cflags®_ICASE) && iswalpha_l(ch, p->g->loc) && othercase(ch, p->g->loc) != ch)
+ bothcases(p, ch);
+ else if ((ch & OPDMASK) == ch)
+ EMIT(OCHAR, ch);
+@@ -1039,6 +1085,9 @@
+ switch (REP(MAP(from), MAP(to))) {
+ case REP(0, 0): /* must be user doing this */
+ DROP(finish-start); /* drop the operand */
++#if __DARWIN_UNIX03
++ p->zerorepeats++;
++#endif /* __DARWIN_UNIX03 */
+ break;
+ case REP(0, 1): /* as x{1,1}? */
+ case REP(0, N): /* as x{1,n}? */
+@@ -1099,7 +1148,7 @@
+ size_t n;
+
+ memset(&mbs, 0, sizeof(mbs));
+- n = mbrtowc(&wc, p->next, p->end - p->next, &mbs);
++ n = mbrtowc_l(&wc, p->next, p->end - p->next, &mbs, p->g->loc);
+ if (n == (size_t)-1 || n == (size_t)-2) {
+ SETERROR(REG_ILLSEQ);
+ return (0);
+@@ -1172,13 +1221,14 @@
+ - returning it if so, otherwise returning OUT.
+ */
+ static wint_t
+-singleton(cs)
++singleton(cs, loc)
+ cset *cs;
++locale_t loc;
+ {
+ wint_t i, s, n;
+
+ for (i = n = 0; i < NC; i++)
+- if (CHIN(cs, i)) {
++ if (CHIN(cs, i, loc)) {
+ n++;
+ s = i;
+ }
+@@ -1215,9 +1265,9 @@
+ cs->wides[cs->nwides++] = ch;
+ }
+ if (cs->icase) {
+- if ((nch = towlower(ch)) < NC)
++ if ((nch = towlower_l(ch, p->g->loc)) < NC)
+ cs->bmp[nch >> 3] |= 1 << (nch & 7);
+- if ((nch = towupper(ch)) < NC)
++ if ((nch = towupper_l(ch, p->g->loc)) < NC)
+ cs->bmp[nch >> 3] |= 1 << (nch & 7);
+ }
+ }
+@@ -1262,7 +1312,7 @@
+ wctype_t *newtypes;
+
+ for (i = 0; i < NC; i++)
+- if (iswctype(i, wct))
++ if (iswctype_l(i, wct, p->g->loc))
+ CHadd(p, cs, i);
+ newtypes = realloc(cs->types, (cs->ntypes + 1) *
+ sizeof(*cs->types));
+@@ -1451,6 +1501,7 @@
+ char buf[MB_LEN_MAX];
+ size_t clen;
+ mbstate_t mbs;
++ struct __xlocale_st_runelocale *rl = p->g->loc->__lc_ctype;
+
+ /* avoid making error situations worse */
+ if (p->error != 0)
+@@ -1461,8 +1512,8 @@
+ * multibyte character strings, but it's safe for at least
+ * UTF-8 (see RFC 3629).
+ */
+- if (MB_CUR_MAX > 1 &&
+- strcmp(_CurrentRuneLocale->__encoding, "UTF-8") != 0)
++ if (rl->__mb_cur_max > 1 &&
++ strcmp(rl->_CurrentRuneLocale.__encoding, "UTF-8") != 0)
+ return;
+
+ /* find the longest OCHAR sequence in strip */
+@@ -1478,7 +1529,7 @@
+ memset(&mbs, 0, sizeof(mbs));
+ newstart = scan - 1;
+ }
+- clen = wcrtomb(buf, OPND(s), &mbs);
++ clen = wcrtomb_l(buf, OPND(s), &mbs, p->g->loc);
+ if (clen == (size_t)-1)
+ goto toohard;
+ newlen += clen;
+@@ -1597,7 +1648,7 @@
+ while (cp < g->must + g->mlen) {
+ while (OP(s = *scan++) != OCHAR)
+ continue;
+- clen = wcrtomb(cp, OPND(s), &mbs);
++ clen = wcrtomb_l(cp, OPND(s), &mbs, p->g->loc);
+ assert(clen != (size_t)-1);
+ cp += clen;
+ }
static char sccsid[] = "@(#)regerror.c 8.4 (Berkeley) 3/20/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/regex/regerror.c,v 1.8 2002/10/02 07:49:35 mike Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/regex/regerror.c,v 1.9 2004/07/12 06:07:26 tjr Exp $");
#include <sys/types.h>
#include <stdio.h>
= #define REG_EMPTY 14
= #define REG_ASSERT 15
= #define REG_INVARG 16
+ = #define REG_ILLSEQ 17
= #define REG_ATOI 255 // convert name to number (!)
= #define REG_ITOA 0400 // convert number to name (!)
*/
{REG_EMPTY, "REG_EMPTY", "empty (sub)expression"},
{REG_ASSERT, "REG_ASSERT", "\"can't happen\" -- you found a bug"},
{REG_INVARG, "REG_INVARG", "invalid argument to regex routine"},
+ {REG_ILLSEQ, "REG_ILLSEQ", "illegal byte sequence"},
{0, "", "*** unknown regexp error code ***"}
};
.\" SUCH DAMAGE.
.\"
.\" @(#)regex.3 8.4 (Berkeley) 3/20/94
-.\" $FreeBSD: src/lib/libc/regex/regex.3,v 1.12 2002/12/19 09:40:23 ru Exp $
+.\" $FreeBSD: src/lib/libc/regex/regex.3,v 1.17 2004/07/12 11:03:42 tjr Exp $
.\"
-.Dd October 2, 2002
+.Dd July 12, 2004
.Dt REGEX 3
.Os
.Sh NAME
of an RE.
.Pp
The header
-.Aq Pa regex.h
+.In regex.h
declares two structure types,
.Ft regex_t
and
.Ql |\&
cannot appear first or last in a (sub)expression or after another
.Ql |\& ,
-i.e. an operand of
+i.e., an operand of
.Ql |\&
cannot be an empty subexpression.
An empty parenthesized subexpression,
.It Dv REG_ASSERT
can't happen - you found a bug
.It Dv REG_INVARG
-invalid argument, e.g. negative-length string
+invalid argument, e.g.\& negative-length string
+.It Dv REG_ILLSEQ
+illegal byte sequence (bad multibyte character)
.El
.Sh HISTORY
Originally written by
* SUCH DAMAGE.
*
* @(#)regex2.h 8.4 (Berkeley) 3/20/94
- * $FreeBSD: src/lib/libc/regex/regex2.h,v 1.6 2002/03/22 23:41:56 obrien Exp $
+ * $FreeBSD: src/lib/libc/regex/regex2.h,v 1.8 2004/07/12 07:35:59 tjr Exp $
*/
/*
/* operators meaning operand */
/* (back, fwd are offsets) */
#define OEND (1L<<OPSHIFT) /* endmarker - */
-#define OCHAR (2L<<OPSHIFT) /* character unsigned char */
+#define OCHAR (2L<<OPSHIFT) /* character wide character */
#define OBOL (3L<<OPSHIFT) /* left anchor - */
#define OEOL (4L<<OPSHIFT) /* right anchor - */
#define OANY (5L<<OPSHIFT) /* . - */
#define OEOW (20L<<OPSHIFT) /* end word - */
/*
- * Structure for [] character-set representation. Character sets are
- * done as bit vectors, grouped 8 to a byte vector for compactness.
- * The individual set therefore has both a pointer to the byte vector
- * and a mask to pick out the relevant bit of each byte. A hash code
- * simplifies testing whether two sets could be identical.
- *
- * This will get trickier for multicharacter collating elements. As
- * preliminary hooks for dealing with such things, we also carry along
- * a string of multi-character elements, and decide the size of the
- * vectors at run time.
+ * Structures for [] character-set representation.
*/
typedef struct {
- uch *ptr; /* -> uch [csetsize] */
- uch mask; /* bit within array */
- short hash; /* hash code */
- size_t smultis;
- char *multis; /* -> char[smulti] ab\0cd\0ef\0\0 */
+ wint_t min;
+ wint_t max;
+} crange;
+typedef struct {
+ unsigned char bmp[NC / 8];
+ wctype_t *types;
+ int ntypes;
+ wint_t *wides;
+ int nwides;
+ crange *ranges;
+ int nranges;
+ int invert;
+ int icase;
} cset;
-/* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */
-#define CHadd(cs, c) ((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash += (uch)(c))
-#define CHsub(cs, c) ((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (uch)(c))
-#define CHIN(cs, c) ((cs)->ptr[(uch)(c)] & (cs)->mask)
-#define MCadd(p, cs, cp) mcadd(p, cs, cp) /* regcomp() internal fns */
-#define MCsub(p, cs, cp) mcsub(p, cs, cp)
-#define MCin(p, cs, cp) mcin(p, cs, cp)
-/* stuff for character categories */
-typedef unsigned char cat_t;
+static int
+CHIN1(cs, ch)
+cset *cs;
+wint_t ch;
+{
+ int i;
+
+ assert(ch >= 0);
+ if (ch < NC)
+ return (((cs->bmp[ch >> 3] & (1 << (ch & 7))) != 0) ^
+ cs->invert);
+ for (i = 0; i < cs->nwides; i++)
+ if (ch == cs->wides[i])
+ return (!cs->invert);
+ for (i = 0; i < cs->nranges; i++)
+ if (cs->ranges[i].min <= ch && ch <= cs->ranges[i].max)
+ return (!cs->invert);
+ for (i = 0; i < cs->ntypes; i++)
+ if (iswctype(ch, cs->types[i]))
+ return (!cs->invert);
+ return (cs->invert);
+}
+
+static __inline int
+CHIN(cs, ch)
+cset *cs;
+wint_t ch;
+{
+
+ assert(ch >= 0);
+ if (ch < NC)
+ return (((cs->bmp[ch >> 3] & (1 << (ch & 7))) != 0) ^
+ cs->invert);
+ else if (cs->icase)
+ return (CHIN1(cs, ch) || CHIN1(cs, towlower(ch)) ||
+ CHIN1(cs, towupper(ch)));
+ else
+ return (CHIN1(cs, ch));
+}
/*
* main compiled-expression structure
int magic;
# define MAGIC2 ((('R'^0200)<<8)|'E')
sop *strip; /* malloced area for strip */
- int csetsize; /* number of bits in a cset vector */
int ncsets; /* number of csets in use */
cset *sets; /* -> cset [ncsets] */
- uch *setbits; /* -> uch[csetsize][ncsets/CHAR_BIT] */
int cflags; /* copy of regcomp() cflags argument */
sopno nstates; /* = number of sops */
sopno firststate; /* the initial OEND (normally 0) */
# define BAD 04 /* something wrong */
int nbol; /* number of ^ used */
int neol; /* number of $ used */
- int ncategories; /* how many character categories */
- cat_t *categories; /* ->catspace[-CHAR_MIN] */
char *must; /* match must contain this string */
int moffset; /* latest point at which must may be located */
int *charjump; /* Boyer-Moore char jump table */
size_t nsub; /* copy of re_nsub */
int backrefs; /* does it use back references? */
sopno nplus; /* how deep does it nest +s? */
- /* catspace must be last */
- cat_t catspace[1]; /* actually [NC] */
};
/* misc utilities */
-#define OUT (CHAR_MAX+1) /* a non-character value */
-#define ISWORD(c) (isalnum((uch)(c)) || (c) == '_')
+#define OUT (-2) /* a non-character value */
+#define ISWORD(c) (iswalnum((uch)(c)) || (c) == '_')
--- /dev/null
+--- regex2.h.orig 2004-11-25 11:38:32.000000000 -0800
++++ regex2.h 2005-02-24 14:26:21.000000000 -0800
+@@ -127,9 +127,10 @@
+ } cset;
+
+ static int
+-CHIN1(cs, ch)
++CHIN1(cs, ch, loc)
+ cset *cs;
+ wint_t ch;
++locale_t loc;
+ {
+ int i;
+
+@@ -144,15 +145,16 @@
+ if (cs->ranges[i].min <= ch && ch <= cs->ranges[i].max)
+ return (!cs->invert);
+ for (i = 0; i < cs->ntypes; i++)
+- if (iswctype(ch, cs->types[i]))
++ if (iswctype_l(ch, cs->types[i], loc))
+ return (!cs->invert);
+ return (cs->invert);
+ }
+
+ static __inline int
+-CHIN(cs, ch)
++CHIN(cs, ch, loc)
+ cset *cs;
+ wint_t ch;
++locale_t loc;
+ {
+
+ assert(ch >= 0);
+@@ -160,10 +162,10 @@
+ return (((cs->bmp[ch >> 3] & (1 << (ch & 7))) != 0) ^
+ cs->invert);
+ else if (cs->icase)
+- return (CHIN1(cs, ch) || CHIN1(cs, towlower(ch)) ||
+- CHIN1(cs, towupper(ch)));
++ return (CHIN1(cs, ch, loc) || CHIN1(cs, towlower_l(ch, loc), loc) ||
++ CHIN1(cs, towupper_l(ch, loc), loc));
+ else
+- return (CHIN1(cs, ch));
++ return (CHIN1(cs, ch, loc));
+ }
+
+ /*
+@@ -193,8 +195,9 @@
+ size_t nsub; /* copy of re_nsub */
+ int backrefs; /* does it use back references? */
+ sopno nplus; /* how deep does it nest +s? */
++ locale_t loc; /* current locale */
+ };
+
+ /* misc utilities */
+ #define OUT (-2) /* a non-character value */
+-#define ISWORD(c) (iswalnum((uch)(c)) || (c) == '_')
++#define ISWORD(c,l) (iswalnum_l((uch)(c), l) || (c) == '_')
static char sccsid[] = "@(#)regexec.c 8.3 (Berkeley) 3/20/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/regex/regexec.c,v 1.5 2003/02/16 17:29:10 nectar Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/regex/regexec.c,v 1.6 2004/07/12 07:35:59 tjr Exp $");
/*
* the outer shell of regexec()
*
- * This file includes engine.c *twice*, after muchos fiddling with the
+ * This file includes engine.c three times, after muchos fiddling with the
* macros that code uses. This lets the same code operate on two different
- * representations for state sets.
+ * representations for state sets and characters.
*/
#include <sys/types.h>
#include <stdio.h>
#include <limits.h>
#include <ctype.h>
#include <regex.h>
+#include <wchar.h>
+#include <wctype.h>
#include "utils.h"
#include "regex2.h"
static int nope __unused = 0; /* for use in asserts; shuts lint up */
+static __inline size_t
+xmbrtowc(wi, s, n, mbs, dummy)
+wint_t *wi;
+const char *s;
+size_t n;
+mbstate_t *mbs;
+wint_t dummy;
+{
+ size_t nr;
+ wchar_t wc;
+
+ nr = mbrtowc(&wc, s, n, mbs);
+ if (wi != NULL)
+ *wi = wc;
+ if (nr == 0)
+ return (1);
+ else if (nr == (size_t)-1 || nr == (size_t)-2) {
+ memset(mbs, 0, sizeof(*mbs));
+ if (wi != NULL)
+ *wi = dummy;
+ return (1);
+ } else
+ return (nr);
+}
+
+static __inline size_t
+xmbrtowc_dummy(wi, s, n, mbs, dummy)
+wint_t *wi;
+const char *s;
+size_t n __unused;
+mbstate_t *mbs __unused;
+wint_t dummy __unused;
+{
+
+ if (wi != NULL)
+ *wi = (unsigned char)*s;
+ return (1);
+}
+
/* macros for manipulating states, small version */
#define states long
#define states1 states /* for later use in regexec() decision */
#define FWD(dst, src, n) ((dst) |= ((unsigned long)(src)&(here)) << (n))
#define BACK(dst, src, n) ((dst) |= ((unsigned long)(src)&(here)) >> (n))
#define ISSETBACK(v, n) (((v) & ((unsigned long)here >> (n))) != 0)
+/* no multibyte support */
+#define XMBRTOWC xmbrtowc_dummy
+#define ZAPSTATE(mbs) ((void)(mbs))
/* function names */
#define SNAMES /* engine.c looks after details */
#undef BACK
#undef ISSETBACK
#undef SNAMES
+#undef XMBRTOWC
+#undef ZAPSTATE
/* macros for manipulating states, large version */
#define states char *
#define FWD(dst, src, n) ((dst)[here+(n)] |= (src)[here])
#define BACK(dst, src, n) ((dst)[here-(n)] |= (src)[here])
#define ISSETBACK(v, n) ((v)[here - (n)])
+/* no multibyte support */
+#define XMBRTOWC xmbrtowc_dummy
+#define ZAPSTATE(mbs) ((void)(mbs))
/* function names */
#define LNAMES /* flag */
#include "engine.c"
+/* multibyte character & large states version */
+#undef LNAMES
+#undef XMBRTOWC
+#undef ZAPSTATE
+#define XMBRTOWC xmbrtowc
+#define ZAPSTATE(mbs) memset((mbs), 0, sizeof(*(mbs)))
+#define MNAMES
+
+#include "engine.c"
+
/*
- regexec - interface for matching
= extern int regexec(const regex_t *, const char *, size_t, \
return(REG_BADPAT);
eflags = GOODFLAGS(eflags);
- if (g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags®_LARGE))
+ if (MB_CUR_MAX > 1)
+ return(mmatcher(g, (char *)string, nmatch, pmatch, eflags));
+ else if (g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags®_LARGE))
return(smatcher(g, (char *)string, nmatch, pmatch, eflags));
else
return(lmatcher(g, (char *)string, nmatch, pmatch, eflags));
---- regexec.c.orig Sun Feb 16 09:29:10 2003
-+++ regexec.c Sat May 3 14:21:16 2003
-@@ -137,6 +137,8 @@
+--- regexec.c.orig 2004-11-25 11:38:33.000000000 -0800
++++ regexec.c 2005-02-24 14:20:50.000000000 -0800
+@@ -43,6 +43,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/regex/regexec.c,v 1.6 2004/07/12 07:35:59 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ /*
+ * the outer shell of regexec()
+ *
+@@ -66,17 +68,18 @@
+ static int nope __unused = 0; /* for use in asserts; shuts lint up */
+
+ static __inline size_t
+-xmbrtowc(wi, s, n, mbs, dummy)
++xmbrtowc(wi, s, n, mbs, dummy, loc)
+ wint_t *wi;
+ const char *s;
+ size_t n;
+ mbstate_t *mbs;
+ wint_t dummy;
++locale_t loc;
+ {
+ size_t nr;
+ wchar_t wc;
+
+- nr = mbrtowc(&wc, s, n, mbs);
++ nr = mbrtowc_l(&wc, s, n, mbs, loc);
+ if (wi != NULL)
+ *wi = wc;
+ if (nr == 0)
+@@ -91,12 +94,13 @@
+ }
+
+ static __inline size_t
+-xmbrtowc_dummy(wi, s, n, mbs, dummy)
++xmbrtowc_dummy(wi, s, n, mbs, dummy, loc)
+ wint_t *wi;
+ const char *s;
+ size_t n __unused;
+ mbstate_t *mbs __unused;
+ wint_t dummy __unused;
++locale_t loc;
+ {
+
+ if (wi != NULL)
+@@ -186,6 +190,8 @@
/* function names */
#define LNAMES /* flag */
+#define __FBSDID(x)
#include "engine.c"
- /*
+ /* multibyte character & large states version */
+@@ -235,7 +241,8 @@
+ return(REG_BADPAT);
+ eflags = GOODFLAGS(eflags);
+
+- if (MB_CUR_MAX > 1)
++ g->loc = __current_locale();
++ if (MB_CUR_MAX_L(g->loc) > 1)
+ return(mmatcher(g, (char *)string, nmatch, pmatch, eflags));
+ else if (g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags®_LARGE))
+ return(smatcher(g, (char *)string, nmatch, pmatch, eflags));
static char sccsid[] = "@(#)regfree.c 8.3 (Berkeley) 3/20/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/regex/regfree.c,v 1.5 2002/03/22 21:52:47 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/regex/regfree.c,v 1.6 2004/07/12 07:35:59 tjr Exp $");
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <regex.h>
+#include <wchar.h>
+#include <wctype.h>
#include "utils.h"
#include "regex2.h"
regex_t *preg;
{
struct re_guts *g;
+ int i;
if (preg->re_magic != MAGIC1) /* oops */
return; /* nice to complain, but hard */
if (g->strip != NULL)
free((char *)g->strip);
- if (g->sets != NULL)
+ if (g->sets != NULL) {
+ for (i = 0; i < g->ncsets; i++) {
+ free(g->sets[i].ranges);
+ free(g->sets[i].wides);
+ free(g->sets[i].types);
+ }
free((char *)g->sets);
- if (g->setbits != NULL)
- free((char *)g->setbits);
+ }
if (g->must != NULL)
free(g->must);
if (g->charjump != NULL)
FBSDHDRS= cclass.h cname.h engine.c regex2.h utils.h
.include "Makefile.fbsd_end"
+UNIX03SRCS += regcomp.c
+
.if ${LIB} == "c"
.include "Makefile.fbsd_begin"
FBSDMAN3= regex.3
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/_flock_stub.c,v 1.12 2002/03/22 21:53:04 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/_flock_stub.c,v 1.14 2004/03/09 04:51:58 jb Exp $");
#include "namespace.h"
#include <stdio.h>
--- /dev/null
+--- asprintf.c.orig 2003-05-20 15:22:40.000000000 -0700
++++ asprintf.c 2005-02-23 16:17:23.000000000 -0800
+@@ -30,6 +30,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/asprintf.c,v 1.13 2002/09/26 13:09:48 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <errno.h>
+@@ -57,7 +59,41 @@
+ f._extra = &ext;
+ INITEXTRA(&f);
+ va_start(ap, fmt);
+- ret = __vfprintf(&f, fmt, ap); /* Use unlocked __vfprintf */
++ ret = __vfprintf(&f, __current_locale(), fmt, ap); /* Use unlocked __vfprintf */
++ va_end(ap);
++ if (ret < 0) {
++ free(f._bf._base);
++ *str = NULL;
++ errno = ENOMEM;
++ return (-1);
++ }
++ *f._p = '\0';
++ *str = (char *)f._bf._base;
++ return (ret);
++}
++
++int
++asprintf_l(char **str, locale_t loc, char const *fmt, ...)
++{
++ int ret;
++ va_list ap;
++ FILE f;
++ struct __sFILEX ext;
++
++ NORMALIZE_LOCALE(loc);
++ f._file = -1;
++ f._flags = __SWR | __SSTR | __SALC;
++ f._bf._base = f._p = (unsigned char *)malloc(128);
++ if (f._bf._base == NULL) {
++ *str = NULL;
++ errno = ENOMEM;
++ return (-1);
++ }
++ f._bf._size = f._w = 127; /* Leave room for the NUL */
++ f._extra = &ext;
++ INITEXTRA(&f);
++ va_start(ap, fmt);
++ ret = __vfprintf(&f, loc, fmt, ap); /* Use unlocked __vfprintf */
+ va_end(ap);
+ if (ret < 0) {
+ free(f._bf._base);
static char sccsid[] = "@(#)feof.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/feof.c,v 1.8 2002/03/22 21:53:04 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/feof.c,v 1.9 2004/03/17 01:43:07 tjr Exp $");
#include "namespace.h"
#include <stdio.h>
#include "un-namespace.h"
#include "libc_private.h"
-/*
- * feof has traditionally been a macro in <stdio.h>. That is no
- * longer true because it needs to be thread-safe.
- *
- * #undef feof
- */
+#undef feof
+
int
feof(FILE *fp)
{
static char sccsid[] = "@(#)ferror.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/ferror.c,v 1.8 2002/03/22 21:53:04 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/ferror.c,v 1.9 2004/03/17 01:43:07 tjr Exp $");
#include "namespace.h"
#include <stdio.h>
#include "un-namespace.h"
#include "libc_private.h"
-/*
- * ferror has traditionally been a macro in <stdio.h>. That is no
- * longer true because it needs to be thread-safe.
- *
- * #undef ferror
- */
+#undef ferror
+
int
ferror(FILE *fp)
{
static char sccsid[] = "@(#)fflush.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/fflush.c,v 1.12 2002/03/22 21:53:04 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fflush.c,v 1.13 2004/07/04 20:17:00 cperciva Exp $");
#include "namespace.h"
#include <errno.h>
if (fp == NULL)
return (_fwalk(sflush_locked));
FLOCKFILE(fp);
+
+ /*
+ * There is disagreement about the correct behaviour of fflush()
+ * when passed a file which is not open for reading. According to
+ * the ISO C standard, the behaviour is undefined.
+ * Under linux, such an fflush returns success and has no effect;
+ * under Windows, such an fflush is documented as behaving instead
+ * as fpurge().
+ * Given that applications may be written with the expectation of
+ * either of these two behaviours, the only safe (non-astonishing)
+ * option is to return EBADF and ask that applications be fixed.
+ */
if ((fp->_flags & (__SWR | __SRW)) == 0) {
errno = EBADF;
retval = EOF;
static char sccsid[] = "@(#)fgetc.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/fgetc.c,v 1.11 2002/08/13 09:30:41 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fgetc.c,v 1.12 2004/03/19 09:04:56 tjr Exp $");
#include "namespace.h"
#include <stdio.h>
{
int retval;
FLOCKFILE(fp);
- ORIENT(fp, -1);
+ /* Orientation set by __sgetc() when buffer is empty. */
+ /* ORIENT(fp, -1); */
retval = __sgetc(fp);
FUNLOCKFILE(fp);
return (retval);
.\" SUCH DAMAGE.
.\"
.\" @(#)fgetln.3 8.3 (Berkeley) 4/19/94
-.\" $FreeBSD: src/lib/libc/stdio/fgetln.3,v 1.7 2001/10/01 16:08:59 ru Exp $
+.\" $FreeBSD: src/lib/libc/stdio/fgetln.3,v 1.8 2004/07/16 06:07:12 tjr Exp $
.\"
.Dd April 19, 1994
.Dt FGETLN 3
.Sh SEE ALSO
.Xr ferror 3 ,
.Xr fgets 3 ,
+.Xr fgetwln 3 ,
.Xr fopen 3 ,
.Xr putc 3
.Sh HISTORY
static char sccsid[] = "@(#)fgetln.c 8.2 (Berkeley) 1/2/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/fgetln.c,v 1.8 2002/03/22 21:53:04 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fgetln.c,v 1.10 2004/07/16 05:52:51 tjr Exp $");
#include "namespace.h"
#include <stdio.h>
* so we add 1 here.
#endif
*/
-static int
-slbexpand(FILE *fp, size_t newsize)
+int
+__slbexpand(FILE *fp, size_t newsize)
{
void *p;
size_t off;
FLOCKFILE(fp);
+ ORIENT(fp, -1);
/* make sure there is input */
if (fp->_r <= 0 && __srefill(fp)) {
*lenp = 0;
* file buffer to line buffer, refill file and look for
* newline. The loop stops only when we find a newline.
*/
- if (slbexpand(fp, len + OPTIMISTIC))
+ if (__slbexpand(fp, len + OPTIMISTIC))
goto error;
(void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p,
len - off);
p++;
diff = p - fp->_p;
len += diff;
- if (slbexpand(fp, len))
+ if (__slbexpand(fp, len))
goto error;
(void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p,
diff);
/*-
- * Copyright (c) 2002 Tim J. Robbins.
+ * Copyright (c) 2002-2004 Tim J. Robbins.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/fgetwc.c,v 1.6 2002/10/16 12:09:43 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fgetwc.c,v 1.12 2004/07/20 08:27:27 tjr Exp $");
#include "namespace.h"
#include <errno.h>
#include "un-namespace.h"
#include "libc_private.h"
#include "local.h"
-
-static __inline wint_t __fgetwc_nbf(FILE *);
-
-/*
- * Non-MT-safe version.
- */
-wint_t
-__fgetwc(FILE *fp)
-{
- wint_t wc;
-
- if (MB_CUR_MAX == 1) {
- /*
- * Assume we're using a single-byte locale. A safer test
- * might be to check _CurrentRuneLocale->encoding.
- */
- wc = (wint_t)__sgetc(fp);
- } else
- wc = __fgetwc_nbf(fp);
-
- return (wc);
-}
+#include "mblocal.h"
/*
* MT-safe version.
return (r);
}
-static __inline wint_t
-__fgetwc_nbf(FILE *fp)
+/*
+ * Non-MT-safe version.
+ */
+wint_t
+__fgetwc(FILE *fp)
{
- char buf[MB_LEN_MAX];
- mbstate_t mbs;
- size_t n, nconv;
- int c;
wchar_t wc;
+ size_t nconv;
- n = 0;
- while (n < MB_CUR_MAX) {
- if ((c = __sgetc(fp)) == EOF) {
- if (n == 0)
- return (WEOF);
+ if (fp->_r <= 0 && __srefill(fp))
+ return (WEOF);
+ if (MB_CUR_MAX == 1) {
+ /* Fast path for single-byte encodings. */
+ wc = *fp->_p++;
+ fp->_r--;
+ return (wc);
+ }
+ do {
+ nconv = __mbrtowc(&wc, fp->_p, fp->_r, &fp->_extra->mbstate);
+ if (nconv == (size_t)-1)
break;
- }
- buf[n++] = (char)c;
- memset(&mbs, 0, sizeof(mbs));
- nconv = mbrtowc(&wc, buf, n, &mbs);
- if (nconv == n)
- return (wc);
- else if (nconv == 0)
+ else if (nconv == (size_t)-2)
+ continue;
+ else if (nconv == 0) {
+ /*
+ * Assume that the only valid representation of
+ * the null wide character is a single null byte.
+ */
+ fp->_p++;
+ fp->_r--;
return (L'\0');
- else if (nconv == (size_t)-1)
- break;
- }
-
- while (n-- != 0)
- __ungetc((unsigned char)buf[n], fp);
- errno = EILSEQ;
+ } else {
+ fp->_p += nconv;
+ fp->_r -= nconv;
+ return (wc);
+ }
+ } while (__srefill(fp) == 0);
fp->_flags |= __SERR;
+ errno = EILSEQ;
return (WEOF);
}
--- /dev/null
+--- fgetwc.c.orig 2004-11-25 11:38:34.000000000 -0800
++++ fgetwc.c 2005-02-23 17:15:00.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/fgetwc.c,v 1.12 2004/07/20 08:27:27 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include "namespace.h"
+ #include <errno.h>
+ #include <stdio.h>
+@@ -47,7 +49,21 @@
+
+ FLOCKFILE(fp);
+ ORIENT(fp, 1);
+- r = __fgetwc(fp);
++ r = __fgetwc(fp, __current_locale());
++ FUNLOCKFILE(fp);
++
++ return (r);
++}
++
++wint_t
++fgetwc_l(FILE *fp, locale_t loc)
++{
++ wint_t r;
++
++ NORMALIZE_LOCALE(loc);
++ FLOCKFILE(fp);
++ ORIENT(fp, 1);
++ r = __fgetwc(fp, loc);
+ FUNLOCKFILE(fp);
+
+ return (r);
+@@ -57,21 +73,23 @@
+ * Non-MT-safe version.
+ */
+ wint_t
+-__fgetwc(FILE *fp)
++__fgetwc(FILE *fp, locale_t loc)
+ {
+ wchar_t wc;
+ size_t nconv;
++ struct __xlocale_st_runelocale *xrl = loc->__lc_ctype;
++ size_t (*__mbrtowc)(wchar_t * __restrict, const char * __restrict, size_t, mbstate_t * __restrict, locale_t) = xrl->__mbrtowc;
+
+ if (fp->_r <= 0 && __srefill(fp))
+ return (WEOF);
+- if (MB_CUR_MAX == 1) {
++ if (xrl->__mb_cur_max == 1) {
+ /* Fast path for single-byte encodings. */
+ wc = *fp->_p++;
+ fp->_r--;
+ return (wc);
+ }
+ do {
+- nconv = __mbrtowc(&wc, fp->_p, fp->_r, &fp->_extra->mbstate);
++ nconv = __mbrtowc(&wc, fp->_p, fp->_r, &fp->_extra->mbstate, loc);
+ if (nconv == (size_t)-1)
+ break;
+ else if (nconv == (size_t)-2)
--- /dev/null
+--- fgetws.3.orig Fri Mar 11 11:51:15 2005
++++ fgetws.3 Fri Mar 11 11:52:41 2005
+@@ -41,7 +41,8 @@
+ .Dt FGETWS 3
+ .Os
+ .Sh NAME
+-.Nm fgetws
++.Nm fgetws ,
++.Nm fgetws_l
+ .Nd get a line of wide characters from a stream
+ .Sh LIBRARY
+ .Lb libc
+@@ -50,6 +51,9 @@
+ .In wchar.h
+ .Ft "wchar_t *"
+ .Fn fgetws "wchar_t * restrict ws" "int n" "FILE * restrict fp"
++.In xlocale.h
++.Ft "wchar_t *"
++.Fn fgetws_l "wchar_t * restrict ws" "int n" "FILE * restrict fp" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn fgetws
+@@ -66,6 +70,14 @@
+ If any characters are read and there is no error, a
+ .Ql \e0
+ character is appended to end the string.
++.Pp
++While the
++.Fn fgetws
++function uses the current locale, the
++.Fn fgetws_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ Upon successful completion,
+ .Fn fgetws
+@@ -116,7 +128,8 @@
+ .Sh SEE ALSO
+ .Xr feof 3 ,
+ .Xr ferror 3 ,
+-.Xr fgets 3
++.Xr fgets 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn fgetws
/*-
- * Copyright (c) 2002 Tim J. Robbins.
+ * Copyright (c) 2002-2004 Tim J. Robbins.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/fgetws.c,v 1.4 2002/09/20 13:25:40 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fgetws.c,v 1.6 2004/10/03 15:48:32 stefanf Exp $");
#include "namespace.h"
#include <errno.h>
#include <stdio.h>
+#include <string.h>
#include <wchar.h>
#include "un-namespace.h"
#include "libc_private.h"
#include "local.h"
+#include "mblocal.h"
wchar_t *
fgetws(wchar_t * __restrict ws, int n, FILE * __restrict fp)
{
wchar_t *wsp;
- wint_t wc;
+ size_t nconv;
+ const char *src;
+ unsigned char *nl;
FLOCKFILE(fp);
ORIENT(fp, 1);
goto error;
}
+ if (fp->_r <= 0 && __srefill(fp))
+ /* EOF */
+ goto error;
wsp = ws;
- while (n-- > 1) {
- /* XXX Inefficient */
- if ((wc = __fgetwc(fp)) == WEOF && errno == EILSEQ)
+ do {
+ src = fp->_p;
+ nl = memchr(fp->_p, '\n', fp->_r);
+ nconv = __mbsnrtowcs(wsp, &src,
+ nl != NULL ? (nl - fp->_p + 1) : fp->_r,
+ n - 1, &fp->_extra->mbstate);
+ if (nconv == (size_t)-1)
+ /* Conversion error */
goto error;
- if (wc == WEOF) {
- if (wsp == ws)
- /* EOF/error, no characters read yet. */
- goto error;
- break;
+ if (src == NULL) {
+ /*
+ * We hit a null byte. Increment the character count,
+ * since mbsnrtowcs()'s return value doesn't include
+ * the terminating null, then resume conversion
+ * after the null.
+ */
+ nconv++;
+ src = memchr(fp->_p, '\0', fp->_r);
+ src++;
}
- *wsp++ = (wchar_t)wc;
- if (wc == L'\n')
- break;
- }
+ fp->_r -= (unsigned char *)src - fp->_p;
+ fp->_p = (unsigned char *)src;
+ n -= nconv;
+ wsp += nconv;
+ } while (wsp[-1] != L'\n' && n > 1 && (fp->_r > 0 ||
+ __srefill(fp) == 0));
+ if (wsp == ws)
+ /* EOF */
+ goto error;
+ if (!__mbsinit(&fp->_extra->mbstate))
+ /* Incomplete character */
+ goto error;
*wsp++ = L'\0';
FUNLOCKFILE(fp);
--- /dev/null
+--- fgetws.c.orig 2004-11-25 11:38:34.000000000 -0800
++++ fgetws.c 2005-02-24 16:20:29.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/fgetws.c,v 1.6 2004/10/03 15:48:32 stefanf Exp $");
+
++#include "xlocale_private.h"
++
+ #include "namespace.h"
+ #include <errno.h>
+ #include <stdio.h>
+@@ -38,13 +40,18 @@
+ #include "mblocal.h"
+
+ wchar_t *
+-fgetws(wchar_t * __restrict ws, int n, FILE * __restrict fp)
++fgetws_l(wchar_t * __restrict ws, int n, FILE * __restrict fp, locale_t loc)
+ {
+ wchar_t *wsp;
+ size_t nconv;
+ const char *src;
+ unsigned char *nl;
++ struct __xlocale_st_runelocale *rl;
++ size_t (*__mbsnrtowcs)(wchar_t * __restrict, const char ** __restrict, size_t, size_t, __darwin_mbstate_t * __restrict, locale_t);
+
++ NORMALIZE_LOCALE(loc);
++ rl = loc->__lc_ctype;
++ __mbsnrtowcs = rl->__mbsnrtowcs;
+ FLOCKFILE(fp);
+ ORIENT(fp, 1);
+
+@@ -58,11 +65,11 @@
+ goto error;
+ wsp = ws;
+ do {
+- src = fp->_p;
++ src = (const char *)fp->_p;
+ nl = memchr(fp->_p, '\n', fp->_r);
+ nconv = __mbsnrtowcs(wsp, &src,
+ nl != NULL ? (nl - fp->_p + 1) : fp->_r,
+- n - 1, &fp->_extra->mbstate);
++ n - 1, &fp->_extra->mbstate, loc);
+ if (nconv == (size_t)-1)
+ /* Conversion error */
+ goto error;
+@@ -86,7 +93,7 @@
+ if (wsp == ws)
+ /* EOF */
+ goto error;
+- if (!__mbsinit(&fp->_extra->mbstate))
++ if (!rl->__mbsinit(&fp->_extra->mbstate, loc))
+ /* Incomplete character */
+ goto error;
+ *wsp++ = L'\0';
+@@ -98,3 +105,9 @@
+ FUNLOCKFILE(fp);
+ return (NULL);
+ }
++
++wchar_t *
++fgetws(wchar_t * __restrict ws, int n, FILE * __restrict fp)
++{
++ return fgetws_l(ws, n, fp, __current_locale());
++}
static char sccsid[] = "@(#)fileno.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/fileno.c,v 1.9 2003/01/13 02:58:18 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fileno.c,v 1.10 2004/03/17 01:43:07 tjr Exp $");
#include "namespace.h"
#include <stdio.h>
#include "un-namespace.h"
#include "libc_private.h"
-/*
- * fileno has traditionally been a macro in <stdio.h>. That is
- * no longer true because it needs to be thread-safe.
- *
- * #undef fileno
- */
+#undef fileno
+
int
fileno(FILE *fp)
{
static char sccsid[] = "@(#)findfp.c 8.2 (Berkeley) 1/4/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/findfp.c,v 1.28 2002/11/14 14:06:14 imp Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/findfp.c,v 1.29 2004/05/22 15:19:41 tjr Exp $");
#include <sys/param.h>
#include <machine/atomic.h>
fp->_lb._size = 0;
/* fp->_lock = NULL; */ /* once set always set (reused) */
fp->_extra->orientation = 0;
-#ifdef notdef
- /* Stateful encoding/decoding is not yet supported. */
- memset(&fp->_extra->wstate, 0, sizeof(mbstate_t));
- memset(&fp->_extra->rstate, 0, sizeof(mbstate_t));
-#endif
+ memset(&fp->_extra->mbstate, 0, sizeof(mbstate_t));
return (fp);
}
---- findfp.c.orig Wed Dec 10 13:02:27 2003
-+++ findfp.c Wed Dec 10 13:04:25 2003
+--- /Volumes/XDisk/tmp/Libc/stdio/FreeBSD/findfp.c.orig 2004-05-22 08:19:41.000000000 -0700
++++ /Volumes/XDisk/tmp/Libc/stdio/FreeBSD/findfp.c 2004-10-24 17:08:30.000000000 -0700
@@ -47,6 +47,7 @@
#include <stdlib.h>
#include <string.h>
/* fp->_lock = NULL; */ /* once set always set (reused) */
+ fp->_extra->fl_mutex = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
fp->_extra->orientation = 0;
- #ifdef notdef
- /* Stateful encoding/decoding is not yet supported. */
+ memset(&fp->_extra->mbstate, 0, sizeof(mbstate_t));
+ return (fp);
--- /dev/null
+--- fprintf.c.orig 2003-05-20 15:22:41.000000000 -0700
++++ fprintf.c 2005-02-23 16:20:47.000000000 -0800
+@@ -40,6 +40,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/fprintf.c,v 1.10 2002/09/06 11:23:55 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdio.h>
+ #include <stdarg.h>
+
+@@ -50,7 +52,20 @@
+ va_list ap;
+
+ va_start(ap, fmt);
+- ret = vfprintf(fp, fmt, ap);
++ ret = vfprintf_l(fp, __current_locale(), fmt, ap);
++ va_end(ap);
++ return (ret);
++}
++
++int
++fprintf_l(FILE * __restrict fp, locale_t loc, const char * __restrict fmt, ...)
++{
++ int ret;
++ va_list ap;
++
++ /* no need to call NORMALIZE_LOCALE(loc), because vfprintf_l will */
++ va_start(ap, fmt);
++ ret = vfprintf_l(fp, loc, fmt, ap);
+ va_end(ap);
+ return (ret);
+ }
static char sccsid[] = "@(#)fputc.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/fputc.c,v 1.11 2002/08/13 09:30:41 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fputc.c,v 1.13 2004/03/19 09:04:56 tjr Exp $");
#include "namespace.h"
#include <stdio.h>
{
int retval;
FLOCKFILE(fp);
- ORIENT(fp, -1);
- retval = putc(c, fp);
+ /* Orientation set by __sputc() when buffer is full. */
+ /* ORIENT(fp, -1); */
+ retval = __sputc(c, fp);
FUNLOCKFILE(fp);
return (retval);
}
/*-
- * Copyright (c) 2002 Tim J. Robbins.
+ * Copyright (c) 2002-2004 Tim J. Robbins.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/fputwc.c,v 1.5 2002/10/16 12:09:43 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fputwc.c,v 1.10 2004/07/20 08:27:27 tjr Exp $");
#include "namespace.h"
#include <errno.h>
#include "un-namespace.h"
#include "libc_private.h"
#include "local.h"
+#include "mblocal.h"
/*
* Non-MT-safe version.
__fputwc(wchar_t wc, FILE *fp)
{
char buf[MB_LEN_MAX];
- mbstate_t mbs;
size_t i, len;
- if (MB_LEN_MAX == 1 && wc > 0 && wc <= UCHAR_MAX) {
+ if (MB_CUR_MAX == 1 && wc > 0 && wc <= UCHAR_MAX) {
/*
* Assume single-byte locale with no special encoding.
* A more careful test would be to check
*buf = (unsigned char)wc;
len = 1;
} else {
- memset(&mbs, 0, sizeof(mbs));
- if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) {
+ if ((len = __wcrtomb(buf, wc, &fp->_extra->mbstate)) ==
+ (size_t)-1) {
fp->_flags |= __SERR;
return (WEOF);
}
--- /dev/null
+--- fputwc.c.orig 2004-11-25 11:38:34.000000000 -0800
++++ fputwc.c 2005-02-23 17:21:10.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/fputwc.c,v 1.10 2004/07/20 08:27:27 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include "namespace.h"
+ #include <errno.h>
+ #include <limits.h>
+@@ -41,13 +43,14 @@
+ /*
+ * Non-MT-safe version.
+ */
+-wint_t
+-__fputwc(wchar_t wc, FILE *fp)
++__private_extern__ wint_t
++__fputwc(wchar_t wc, FILE *fp, locale_t loc)
+ {
+ char buf[MB_LEN_MAX];
+ size_t i, len;
++ struct __xlocale_st_runelocale *xrl = loc->__lc_ctype;
+
+- if (MB_CUR_MAX == 1 && wc > 0 && wc <= UCHAR_MAX) {
++ if (xrl->__mb_cur_max == 1 && wc > 0 && wc <= UCHAR_MAX) {
+ /*
+ * Assume single-byte locale with no special encoding.
+ * A more careful test would be to check
+@@ -56,7 +59,7 @@
+ *buf = (unsigned char)wc;
+ len = 1;
+ } else {
+- if ((len = __wcrtomb(buf, wc, &fp->_extra->mbstate)) ==
++ if ((len = xrl->__wcrtomb(buf, wc, &fp->_extra->mbstate, loc)) ==
+ (size_t)-1) {
+ fp->_flags |= __SERR;
+ return (WEOF);
+@@ -80,7 +83,21 @@
+
+ FLOCKFILE(fp);
+ ORIENT(fp, 1);
+- r = __fputwc(wc, fp);
++ r = __fputwc(wc, fp, __current_locale());
++ FUNLOCKFILE(fp);
++
++ return (r);
++}
++
++wint_t
++fputwc_l(wchar_t wc, FILE *fp, locale_t loc)
++{
++ wint_t r;
++
++ NORMALIZE_LOCALE(loc);
++ FLOCKFILE(fp);
++ ORIENT(fp, 1);
++ r = __fputwc(wc, fp, loc);
+ FUNLOCKFILE(fp);
+
+ return (r);
--- /dev/null
+--- fputws.3.orig Fri Mar 11 11:53:01 2005
++++ fputws.3 Fri Mar 11 11:53:53 2005
+@@ -41,7 +41,8 @@
+ .Dt FPUTWS 3
+ .Os
+ .Sh NAME
+-.Nm fputws
++.Nm fputws ,
++.Nm fputws_l
+ .Nd output a line of wide characters to a stream
+ .Sh LIBRARY
+ .Lb libc
+@@ -50,6 +51,9 @@
+ .In wchar.h
+ .Ft int
+ .Fn fputws "const wchar_t * restrict ws" "FILE * restrict fp"
++.In xlocale.h
++.Ft int
++.Fn fputws_l "const wchar_t * restrict ws" "FILE * restrict fp" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn fputws
+@@ -57,6 +61,14 @@
+ .Fa ws
+ to the stream pointed to by
+ .Fa fp .
++.Pp
++While the
++.Fn fputws
++function uses the current locale, the
++.Fn fputws_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn fputws
+@@ -84,7 +96,8 @@
+ .Xr ferror 3 ,
+ .Xr fputs 3 ,
+ .Xr putwc 3 ,
+-.Xr stdio 3
++.Xr stdio 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn fputws
/*-
- * Copyright (c) 2002 Tim J. Robbins.
+ * Copyright (c) 2002-2004 Tim J. Robbins.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/fputws.c,v 1.4 2002/09/20 13:25:40 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fputws.c,v 1.6 2004/07/21 10:54:57 tjr Exp $");
#include "namespace.h"
#include <errno.h>
+#include <limits.h>
#include <stdio.h>
#include <wchar.h>
#include "un-namespace.h"
+#include "fvwrite.h"
#include "libc_private.h"
#include "local.h"
+#include "mblocal.h"
int
fputws(const wchar_t * __restrict ws, FILE * __restrict fp)
{
+ size_t nbytes;
+ char buf[BUFSIZ];
+ struct __suio uio;
+ struct __siov iov;
FLOCKFILE(fp);
ORIENT(fp, 1);
- /* XXX Inefficient */
- while (*ws != '\0')
- if (__fputwc(*ws++, fp) == WEOF) {
- FUNLOCKFILE(fp);
- return (-1);
- }
+ if (prepwrite(fp) != 0)
+ goto error;
+ uio.uio_iov = &iov;
+ uio.uio_iovcnt = 1;
+ iov.iov_base = buf;
+ do {
+ nbytes = __wcsnrtombs(buf, &ws, SIZE_T_MAX, sizeof(buf),
+ &fp->_extra->mbstate);
+ if (nbytes == (size_t)-1)
+ goto error;
+ iov.iov_len = uio.uio_resid = nbytes;
+ if (__sfvwrite(fp, &uio) != 0)
+ goto error;
+ } while (ws != NULL);
FUNLOCKFILE(fp);
-
return (0);
+
+error:
+ FUNLOCKFILE(fp);
+ return (-1);
}
--- /dev/null
+--- fputws.c.orig 2004-11-25 11:38:34.000000000 -0800
++++ fputws.c 2005-02-23 17:23:49.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/fputws.c,v 1.6 2004/07/21 10:54:57 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include "namespace.h"
+ #include <errno.h>
+ #include <limits.h>
+@@ -39,13 +41,17 @@
+ #include "mblocal.h"
+
+ int
+-fputws(const wchar_t * __restrict ws, FILE * __restrict fp)
++fputws_l(const wchar_t * __restrict ws, FILE * __restrict fp, locale_t loc)
+ {
+ size_t nbytes;
+ char buf[BUFSIZ];
+ struct __suio uio;
+ struct __siov iov;
++ size_t (*__wcsnrtombs)(char * __restrict, const wchar_t ** __restrict,
++ size_t, size_t, mbstate_t * __restrict, locale_t);
+
++ NORMALIZE_LOCALE(loc);
++ __wcsnrtombs = loc->__lc_ctype->__wcsnrtombs;
+ FLOCKFILE(fp);
+ ORIENT(fp, 1);
+ if (prepwrite(fp) != 0)
+@@ -55,7 +61,7 @@
+ iov.iov_base = buf;
+ do {
+ nbytes = __wcsnrtombs(buf, &ws, SIZE_T_MAX, sizeof(buf),
+- &fp->_extra->mbstate);
++ &fp->_extra->mbstate, loc);
+ if (nbytes == (size_t)-1)
+ goto error;
+ iov.iov_len = uio.uio_resid = nbytes;
+@@ -69,3 +75,9 @@
+ FUNLOCKFILE(fp);
+ return (-1);
+ }
++
++int
++fputws(const wchar_t * __restrict ws, FILE * __restrict fp)
++{
++ return fputws_l(ws, fp, __current_locale());
++}
static char sccsid[] = "@(#)freopen.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/freopen.c,v 1.12 2003/01/26 11:45:54 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/freopen.c,v 1.13 2004/05/22 15:19:41 tjr Exp $");
#include "namespace.h"
#include <sys/types.h>
FREELB(fp);
fp->_lb._size = 0;
fp->_extra->orientation = 0;
+ memset(&fp->_extra->mbstate, 0, sizeof(mbstate_t));
if (f < 0) { /* did not get it after all */
fp->_flags = 0; /* set it free */
--- /dev/null
+--- freopen.c.orig 2004-10-28 23:51:35.000000000 -0700
++++ freopen.c 2004-10-28 23:53:14.000000000 -0700
+@@ -136,6 +136,8 @@
+ * descriptor (if any) was associated with it. If it was attached to
+ * a descriptor, defer closing it; freopen("/dev/stdin", "r", stdin)
+ * should work. This is unnecessary if it was not a Unix file.
++ *
++ * For UNIX03, we always close if it was open.
+ */
+ if (fp->_flags == 0) {
+ fp->_flags = __SEOF; /* hold on to it */
+@@ -146,11 +148,18 @@
+ if (fp->_flags & __SWR)
+ (void) __sflush(fp);
+ /* if close is NULL, closing is a no-op, hence pointless */
++#if __DARWIN_UNIX03
++ if (fp->_close)
++ (void) (*fp->_close)(fp->_cookie);
++ isopen = 0;
++ wantfd = -1;
++#else /* !__DARWIN_UNIX03 */
+ isopen = fp->_close != NULL;
+ if ((wantfd = fp->_file) < 0 && isopen) {
+ (void) (*fp->_close)(fp->_cookie);
+ isopen = 0;
+ }
++#endif /* __DARWIN_UNIX03 */
+ }
+
+ /* Get a new descriptor to refer to the new file. */
--- /dev/null
+--- fscanf.c.orig 2003-05-20 15:22:42.000000000 -0700
++++ fscanf.c 2005-02-23 16:23:38.000000000 -0800
+@@ -40,6 +40,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/fscanf.c,v 1.12 2003/01/03 23:27:27 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include "namespace.h"
+ #include <stdio.h>
+ #include <stdarg.h>
+@@ -55,7 +57,22 @@
+
+ va_start(ap, fmt);
+ FLOCKFILE(fp);
+- ret = __svfscanf(fp, fmt, ap);
++ ret = __svfscanf_l(fp, __current_locale(), fmt, ap);
++ va_end(ap);
++ FUNLOCKFILE(fp);
++ return (ret);
++}
++
++int
++fscanf_l(FILE * __restrict fp, locale_t loc, char const * __restrict fmt, ...)
++{
++ int ret;
++ va_list ap;
++
++ NORMALIZE_LOCALE(loc);
++ va_start(ap, fmt);
++ FLOCKFILE(fp);
++ ret = __svfscanf_l(fp, loc, fmt, ap);
+ va_end(ap);
+ FUNLOCKFILE(fp);
+ return (ret);
.\" SUCH DAMAGE.
.\"
.\" @(#)fseek.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/stdio/fseek.3,v 1.24 2002/12/19 09:40:24 ru Exp $
+.\" $FreeBSD: src/lib/libc/stdio/fseek.3,v 1.25 2004/03/20 08:38:27 tjr Exp $
.\"
-.Dd October 12, 2002
+.Dd March 19, 2004
.Dt FSEEK 3
.Os
.Sh NAME
and
.Fn fsetpos
functions
-are alternate interfaces equivalent to
+are alternate interfaces for retrieving and setting the current position in
+the file, similar to
.Fn ftell
and
-.Fn fseek
-(with whence set to
-.Dv SEEK_SET ) ,
-setting and storing the current value of
-the file offset into or from the object referenced by
+.Fn fseek ,
+except that the current position is stored in an opaque object of
+type
+.Vt fpos_t
+pointed to by
.Fa pos .
-On some
-.Pq non- Ns Tn UNIX
-systems an
-.Dq Fa fpos_t
-object may be a complex object
-and these routines may be the only way to portably reposition a text stream.
+These functions provide a portable way to seek to offsets larger than
+those that can be represented by a
+.Vt long int .
+They may also store additional state information in the
+.Vt fpos_t
+object to facilitate seeking within files containing multibyte
+characters with state-dependent encodings.
+Although
+.Vt fpos_t
+has traditionally been an integral type,
+applications cannot assume that it is;
+in particular, they must not perform arithmetic on objects
+of this type.
.Pp
If the stream is a wide character stream (see
.Xr fwide 3 ) ,
static char sccsid[] = "@(#)fseek.c 8.3 (Berkeley) 1/2/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/fseek.c,v 1.40 2002/03/22 21:53:04 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fseek.c,v 1.41 2004/05/22 15:19:41 tjr Exp $");
#include "namespace.h"
#include <sys/types.h>
if (HASUB(fp))
FREEUB(fp);
fp->_flags &= ~__SEOF;
+ memset(&fp->_extra->mbstate, 0, sizeof(mbstate_t));
return (0);
}
fp->_r = 0;
/* fp->_w = 0; */ /* unnecessary (I think...) */
fp->_flags &= ~__SEOF;
+ memset(&fp->_extra->mbstate, 0, sizeof(mbstate_t));
if (ltest && ret > LONG_MAX) {
fp->_flags |= __SERR;
errno = EOVERFLOW;
.\" SUCH DAMAGE.
.\"
.\" @(#)funopen.3 8.1 (Berkeley) 6/9/93
-.\" $FreeBSD: src/lib/libc/stdio/funopen.3,v 1.12 2001/10/01 16:08:59 ru Exp $
+.\" $FreeBSD: src/lib/libc/stdio/funopen.3,v 1.15 2004/07/03 22:30:09 ru Exp $
.\"
-.Dd June 9, 1993
+.Dd March 19, 2004
.Dt FUNOPEN 3
.Os
.Sh NAME
.Ft FILE *
.Fn funopen "const void *cookie" "int (*readfn)(void *, char *, int)" "int (*writefn)(void *, const char *, int)" "fpos_t (*seekfn)(void *, fpos_t, int)" "int (*closefn)(void *)"
.Ft FILE *
-.Fn fropen "void *cookie" "int (*readfn)(void *, char *, int)"
+.Fn fropen "void *cookie" "int (*readfn)(void *, char *, int)"
.Ft FILE *
-.Fn fwopen "void *cookie" "int (*writefn)(void *, const char *, int)"
+.Fn fwopen "void *cookie" "int (*writefn)(void *, const char *, int)"
.Sh DESCRIPTION
The
.Fn funopen
does not keep the stream open.
.Pp
As a convenience, the include file
-.Aq Pa stdio.h
+.In stdio.h
defines the macros
.Fn fropen
and
function
may not be portable to systems other than
.Bx .
+.Pp
+The
+.Fn funopen
+interface erroneously assumes that
+.Vt fpos_t
+is an integral type; see
+.Xr fseek 3
+for a discussion of this issue.
static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/fvwrite.c,v 1.16 2004/03/02 19:43:51 jkh Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fvwrite.c,v 1.17 2004/06/08 05:45:48 das Exp $");
-#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
if ((len = uio->uio_resid) == 0)
return (0);
/* make sure we can write */
- if (cantwrite(fp)) {
- errno = EBADF;
+ if (prepwrite(fp) != 0)
return (EOF);
- }
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define COPY(n) (void)memcpy((void *)fp->_p, (void *)p, (size_t)(n))
--- /dev/null
+--- fwprintf.c.orig 2003-05-20 15:22:42.000000000 -0700
++++ fwprintf.c 2005-02-23 16:28:45.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/fwprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdarg.h>
+ #include <stdio.h>
+ #include <wchar.h>
+@@ -38,7 +40,21 @@
+ va_list ap;
+
+ va_start(ap, fmt);
+- ret = vfwprintf(fp, fmt, ap);
++ ret = vfwprintf_l(fp, __current_locale(), fmt, ap);
++ va_end(ap);
++
++ return (ret);
++}
++
++int
++fwprintf_l(FILE * __restrict fp, locale_t loc, const wchar_t * __restrict fmt, ...)
++{
++ int ret;
++ va_list ap;
++
++ /* no need to call NORMALIZE_LOCALE(loc) because vfwprintf_l will */
++ va_start(ap, fmt);
++ ret = vfwprintf_l(fp, loc, fmt, ap);
+ va_end(ap);
+
+ return (ret);
--- /dev/null
+--- fwrite.c.orig 2004-11-01 00:27:25.000000000 -0800
++++ fwrite.c 2004-11-01 00:29:40.000000000 -0800
+@@ -63,6 +63,11 @@
+
+ iov.iov_base = (void *)buf;
+ uio.uio_resid = iov.iov_len = n = count * size;
++
++#if __DARWIN_UNIX03
++ if (n == 0) /* POSIX */
++ return 0;
++#endif /* __DARWIN_UNIX03 */
+ uio.uio_iov = &iov;
+ uio.uio_iovcnt = 1;
+
--- /dev/null
+--- fwscanf.c.orig 2003-05-20 15:22:42.000000000 -0700
++++ fwscanf.c 2005-02-23 16:32:29.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/fwscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdarg.h>
+ #include <stdio.h>
+ #include <wchar.h>
+@@ -38,7 +40,21 @@
+ int r;
+
+ va_start(ap, fmt);
+- r = vfwscanf(fp, fmt, ap);
++ r = vfwscanf_l(fp, __current_locale(), fmt, ap);
++ va_end(ap);
++
++ return (r);
++}
++
++int
++fwscanf_l(FILE * __restrict fp, locale_t loc, const wchar_t * __restrict fmt, ...)
++{
++ va_list ap;
++ int r;
++
++ /* no need to call NORMALIZE_LOCALE(loc) because vfwscanf_l will */
++ va_start(ap, fmt);
++ r = vfwscanf_l(fp, loc, fmt, ap);
+ va_end(ap);
+
+ return (r);
.\" SUCH DAMAGE.
.\"
.\" @(#)getc.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/stdio/getc.3,v 1.17 2003/02/23 01:47:47 ru Exp $
+.\" $FreeBSD: src/lib/libc/stdio/getc.3,v 1.19 2004/03/17 12:37:28 tjr Exp $
.\"
.Dd January 10, 2003
.Dt GETC 3
.Ft int
.Fn getchar
.Ft int
-.Fn getchar_unlocked "FILE *stream"
+.Fn getchar_unlocked "void"
.Ft int
.Fn getw "FILE *stream"
.Sh DESCRIPTION
.Fn getc
function
acts essentially identically to
-.Fn fgetc .
+.Fn fgetc ,
+but is a macro that expands in-line.
.Pp
The
.Fn getchar
static char sccsid[] = "@(#)getc.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/getc.c,v 1.11 2002/08/13 09:30:41 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/getc.c,v 1.13 2004/03/19 09:04:56 tjr Exp $");
#include "namespace.h"
#include <stdio.h>
#include "libc_private.h"
#include "local.h"
+#undef getc
+
int
getc(FILE *fp)
{
int retval;
FLOCKFILE(fp);
- ORIENT(fp, -1);
+ /* Orientation set by __sgetc() when buffer is empty. */
+ /* ORIENT(fp, -1); */
retval = __sgetc(fp);
FUNLOCKFILE(fp);
return (retval);
static char sccsid[] = "@(#)getchar.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/getchar.c,v 1.10 2002/08/13 09:30:41 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/getchar.c,v 1.12 2004/03/19 09:04:56 tjr Exp $");
/*
* A subroutine version of the macro getchar.
{
int retval;
FLOCKFILE(stdin);
- ORIENT(stdin, -1);
- retval = getc(stdin);
+ /* Orientation set by __sgetc() when buffer is empty. */
+ /* ORIENT(stdin, -1); */
+ retval = __sgetc(stdin);
FUNLOCKFILE(stdin);
return (retval);
}
.\" SUCH DAMAGE.
.\"
.\" @(#)getc.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/stdio/getwc.3,v 1.5 2002/12/04 18:57:45 ru Exp $
+.\" $FreeBSD: src/lib/libc/stdio/getwc.3,v 1.6 2004/03/16 13:30:11 tjr Exp $
.\"
-.Dd October 10, 2002
+.Dd March 3, 2004
.Dt GETWC 3
.Os
.Sh NAME
.Nm fgetwc ,
.Nm getwc ,
.Nm getwchar
-.Nd get next wide-character from input stream
+.Nd get next wide character from input stream
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
The
.Fn fgetwc
function
-obtains the next input wide-character (if present) from the stream pointed at by
+obtains the next input wide character (if present) from the stream pointed at by
.Fa stream ,
or the next character pushed back on the stream via
.Xr ungetwc 3 .
with the argument
.Dv stdin .
.Sh RETURN VALUES
-If successful, these routines return the next wide-character
+If successful, these routines return the next wide character
from the
.Fa stream .
If the stream is at end-of-file or a read error occurs,
--- /dev/null
+--- getwc.3.orig Fri Mar 11 17:08:31 2005
++++ getwc.3 Fri Mar 11 16:20:25 2005
+@@ -79,6 +79,12 @@
+ .Fn getwc
+ with the argument
+ .Dv stdin .
++.Pp
++Extended locale versions of these functions are documented in
++.Xr getwc_l 3 .
++See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ If successful, these routines return the next wide character
+ from the
+@@ -106,7 +112,8 @@
+ .Xr getc 3 ,
+ .Xr putwc 3 ,
+ .Xr stdio 3 ,
+-.Xr ungetwc 3
++.Xr ungetwc 3 ,
++.Xr getwc_l 3
+ .Sh STANDARDS
+ The
+ .Fn fgetwc ,
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/getwc.c,v 1.2 2002/09/28 07:43:44 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/getwc.c,v 1.3 2004/05/25 10:42:52 tjr Exp $");
#include "namespace.h"
#include <stdio.h>
#include "libc_private.h"
#include "local.h"
+#undef getwc
+
/*
* Synonym for fgetwc(). The only difference is that getwc(), if it is a
* macro, may evaluate `fp' more than once.
--- /dev/null
+--- getwc.c.orig 2004-11-25 11:38:35.000000000 -0800
++++ getwc.c 2005-02-23 17:28:11.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/getwc.c,v 1.3 2004/05/25 10:42:52 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include "namespace.h"
+ #include <stdio.h>
+ #include <wchar.h>
+@@ -44,5 +46,13 @@
+ getwc(FILE *fp)
+ {
+
+- return (fgetwc(fp));
++ return (fgetwc_l(fp, __current_locale()));
++}
++
++wint_t
++getwc_l(FILE *fp, locale_t loc)
++{
++
++ /* no need to call NORMALIZE_LOCALE(loc) because fgetwc_l will */
++ return (fgetwc_l(fp, loc));
+ }
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/getwchar.c,v 1.2 2002/09/28 07:43:44 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/getwchar.c,v 1.3 2004/05/25 10:42:52 tjr Exp $");
#include "namespace.h"
#include <stdio.h>
#include "libc_private.h"
#include "local.h"
+#undef getwchar
+
/*
* Synonym for fgetwc(stdin).
*/
--- /dev/null
+--- getwchar.c.orig 2004-11-25 11:38:35.000000000 -0800
++++ getwchar.c 2005-02-23 17:30:01.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/getwchar.c,v 1.3 2004/05/25 10:42:52 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include "namespace.h"
+ #include <stdio.h>
+ #include <wchar.h>
+@@ -43,5 +45,13 @@
+ getwchar(void)
+ {
+
+- return (fgetwc(stdin));
++ return (fgetwc_l(stdin, __current_locale()));
++}
++
++wint_t
++getwchar_l(locale_t loc)
++{
++
++ /* no need to call NORMALIZE_LOCALE(loc) because fgetwc_l will */
++ return (fgetwc_l(stdin, loc));
+ }
* SUCH DAMAGE.
*
* @(#)local.h 8.3 (Berkeley) 7/3/94
- * $FreeBSD: src/lib/libc/stdio/local.h,v 1.21 2002/10/25 07:01:56 tjr Exp $
+ * $FreeBSD: src/lib/libc/stdio/local.h,v 1.26 2004/07/16 05:52:51 tjr Exp $
*/
#include <sys/types.h> /* for off_t */
extern wint_t __fputwc(wchar_t, FILE *);
extern int __sflush(FILE *);
extern FILE *__sfp(void);
+extern int __slbexpand(FILE *, size_t);
extern int __srefill(FILE *);
extern int __sread(void *, char *, int);
extern int __swrite(void *, char const *, int);
pthread_t fl_owner; /* current owner */
int fl_count; /* recursive lock count */
int orientation; /* orientation for fwide() */
-#ifdef notdef
- /*
- * XXX These are not used yet -- they will be used to store the
- * multibyte conversion state for writing and reading when
- * stateful encodings are supported by the locale framework.
- */
- mbstate_t wstate; /* write conversion state */
- mbstate_t rstate; /* read conversion state */
-#endif
+ mbstate_t mbstate; /* multibyte conversion state */
};
/*
- * Return true iff the given FILE cannot be written now.
+ * Prepare the given FILE for writing, and return 0 iff it
+ * can be written now. Otherwise, return EOF and set errno.
*/
-#define cantwrite(fp) \
+#define prepwrite(fp) \
((((fp)->_flags & __SWR) == 0 || \
((fp)->_bf._base == NULL && ((fp)->_flags & __SSTR) == 0)) && \
__swsetup(fp))
(fp)->_extra->fl_owner = NULL; \
(fp)->_extra->fl_count = 0; \
(fp)->_extra->orientation = 0; \
- /* memset(&(fp)->_extra->wstate, 0, sizeof(mbstate_t)); */ \
- /* memset(&(fp)->_extra->rstate, 0, sizeof(mbstate_t)); */ \
+ memset(&(fp)->_extra->mbstate, 0, sizeof(mbstate_t)); \
}
/*
---- local.h.orig Fri Oct 25 00:01:56 2002
-+++ local.h Sat May 3 14:38:49 2003
-@@ -130,7 +130,7 @@
+--- local.h.orig 2004-11-25 11:38:35.000000000 -0800
++++ local.h 2005-02-23 17:26:30.000000000 -0800
+@@ -37,8 +37,11 @@
+ * $FreeBSD: src/lib/libc/stdio/local.h,v 1.26 2004/07/16 05:52:51 tjr Exp $
+ */
+
++#include <sys/cdefs.h>
++#include "xlocale_private.h"
+ #include <sys/types.h> /* for off_t */
+ #include <pthread.h>
++#include <limits.h>
+ #include <string.h>
+ #include <wchar.h>
+
+@@ -53,8 +56,8 @@
+ extern int _ftello(FILE *, fpos_t *);
+ extern int _fseeko(FILE *, off_t, int, int);
+ extern int __fflush(FILE *fp);
+-extern wint_t __fgetwc(FILE *);
+-extern wint_t __fputwc(wchar_t, FILE *);
++extern wint_t __fgetwc(FILE *, locale_t);
++extern wint_t __fputwc(wchar_t, FILE *, locale_t);
+ extern int __sflush(FILE *);
+ extern FILE *__sfp(void);
+ extern int __slbexpand(FILE *, size_t);
+@@ -69,16 +72,16 @@
+ extern void __smakebuf(FILE *);
+ extern int __swhatbuf(FILE *, size_t *, int *);
+ extern int _fwalk(int (*)(FILE *));
+-extern int __svfscanf(FILE *, const char *, __va_list);
++extern int __svfscanf_l(FILE *, locale_t, const char *, __va_list) __DARWIN_LDBL_COMPAT(__svfscanf_l);
+ extern int __swsetup(FILE *);
+ extern int __sflags(const char *, int *);
+ extern int __ungetc(int, FILE *);
+-extern wint_t __ungetwc(wint_t, FILE *);
+-extern int __vfprintf(FILE *, const char *, __va_list);
+-extern int __vfscanf(FILE *, const char *, __va_list);
+-extern int __vfwprintf(FILE *, const wchar_t *, __va_list);
+-extern int __vfwscanf(FILE * __restrict, const wchar_t * __restrict,
+- __va_list);
++extern wint_t __ungetwc(wint_t, FILE *, locale_t);
++extern int __vfprintf(FILE *, locale_t, const char *, __va_list) __DARWIN_LDBL_COMPAT(__vfprintf);
++extern int __vfscanf(FILE *, const char *, __va_list) __DARWIN_LDBL_COMPAT(__vfscanf);
++extern int __vfwprintf(FILE *, locale_t, const wchar_t *, __va_list) __DARWIN_LDBL_COMPAT(__vfwprintf);
++extern int __vfwscanf(FILE * __restrict, locale_t, const wchar_t * __restrict,
++ __va_list) __DARWIN_LDBL_COMPAT(__vfwscanf);
+
+ extern int __sdidinit;
+
+@@ -124,7 +127,7 @@
#define INITEXTRA(fp) { \
(fp)->_extra->_up = NULL; \
.\" SUCH DAMAGE.
.\"
.\" @(#)mktemp.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/stdio/mktemp.3,v 1.19 2002/12/24 13:41:45 ru Exp $
+.\" $FreeBSD: src/lib/libc/stdio/mktemp.3,v 1.20 2004/02/20 04:08:28 green Exp $
.\"
.Dd February 11, 1998
.Dt MKTEMP 3
This will ensure that the program does not continue blindly
in the event that an attacker has already created the file
with the intention of manipulating or reading its contents.
+.Pp
+The implementation of these functions calls
+.Xr arc4random 3 ,
+which is not reentrant.
+You must provide your own locking around this and other consumers of the
+.Xr arc4random 3
+API.
.Sh SEE ALSO
.Xr chmod 2 ,
.Xr getpid 2 ,
.\" SUCH DAMAGE.
.\"
.\" @(#)printf.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/stdio/printf.3,v 1.55 2003/01/06 06:19:19 tjr Exp $
+.\" $FreeBSD: src/lib/libc/stdio/printf.3,v 1.58 2004/10/16 16:00:01 stefanf Exp $
.\"
-.Dd January 4, 2003
+.Dd October 16, 2004
.Dt PRINTF 3
.Os
.Sh NAME
conversion:
.Bl -column ".Sy Modifier" ".Cm a , A , e , E , f , F , g , G"
.It Sy Modifier Ta Cm a , A , e , E , f , F , g , G
+.It Cm l No (ell) Ta Vt double
+(ignored, same behavior as without it)
.It Cm L Ta Vt "long double"
.El
.Pp
.It Cm aA
The
.Vt double
-argument is converted to hexadecimal notation in the style
+argument is rounded and converted to hexadecimal notation in the style
.Sm off
.Oo \- Oc Li 0x Ar h Li \&. Ar hhhp Oo \\*[Pm] Oc Ar d ,
.Sm on
where the number of digits after the hexadecimal-point character
is equal to the precision specification.
-If the precision is missing, it is taken as enough to exactly
-represent the floating-point number; if the precision is
-explicitly zero, no hexadecimal-point character appears.
-This is an exact conversion of the mantissa+exponent internal
-floating point representation; the
-.Sm off
-.Oo \- Oc Li 0x Ar h Li \&. Ar hhh
-.Sm on
-portion represents exactly the mantissa; only denormalized
-mantissas have a zero value to the left of the hexadecimal
-point.
+If the precision is missing, it is taken as enough to represent
+the floating-point number exactly, and no rounding occurs.
+If the precision is zero, no hexadecimal-point character appears.
The
.Cm p
is a literal character
-.Ql p ;
-the exponent is preceded by a positive or negative sign
-and is represented in decimal, using only enough characters
-to represent the exponent.
+.Ql p ,
+and the exponent consists of a positive or negative sign
+followed by a decimal number representing an exponent of 2.
The
.Cm A
conversion uses the prefix
(rather than
.Ql p )
to separate the mantissa and exponent.
+.Pp
+Note that there may be multiple valid ways to represent floating-point
+numbers in this hexadecimal format.
+For example,
+.Li 0x3.24p+0 , 0x6.48p-1
+and
+.Li 0xc.9p-2
+are all equivalent.
+The format chosen depends on the internal representation of the
+number, but the implementation guarantees that the length of the
+mantissa will be minimized.
+Zeroes are always represented with a mantissa of 0 (preceded by a
+.Ql -
+if appropriate) and an exponent of
+.Li +0 .
.It Cm C
Treated as
.Cm c
.Pp
The
.Nm
-family of functions currently lack the ability to use the
-.Cm '
-flag in conjunction with the
-.Cm f
-conversion specifier.
-The
-.Cm a
-and
-.Cm A
-conversion specifiers have not yet been implemented.
-The
-.Cm L
-modifier for floating point formats simply round the
-.Vt "long double"
-argument to
-.Vt double ,
-providing no additional precision.
-.Pp
-The
-.Nm
family of functions do not correctly handle multibyte characters in the
.Fa format
argument.
---- printf.3.orig Fri May 28 14:31:32 2004
-+++ printf.3 Fri May 28 14:33:23 2004
-@@ -287,6 +287,20 @@
+--- printf.3.orig Fri Mar 11 17:08:43 2005
++++ printf.3 Fri Mar 11 17:04:50 2005
+@@ -101,6 +101,12 @@
+ dynamically allocate a new string with
+ .Xr malloc 3 .
+ .Pp
++Extended locale versions of these functions are documented in
++.Xr printf_l 3 .
++See
++.Xr xlocale 3
++for more information.
++.Pp
+ These functions write the output under the control of a
+ .Fa format
+ string that specifies how subsequent arguments
+@@ -287,6 +293,20 @@
.Xr localeconv 3 .
.El
.It
An optional decimal digit string specifying a minimum field width.
If the converted value has fewer characters than the field width, it will
be padded with spaces on the left (or right, if the left-adjustment
-@@ -377,6 +391,28 @@
+@@ -379,6 +399,28 @@
.It Sy Modifier Ta Cm c Ta Cm s
.It Cm l No (ell) Ta Vt wint_t Ta Vt "wchar_t *"
.El
.It
A character that specifies the type of conversion to be applied.
.El
-@@ -785,11 +821,6 @@
+@@ -792,12 +834,8 @@
+ .Xr fmtcheck 3 ,
.Xr scanf 3 ,
.Xr setlocale 3 ,
- .Xr wprintf 3
+-.Xr wprintf 3
-.Rs
-.%T "The FreeBSD Security Architecture"
-.Re
-(See
-.Pa "/usr/share/doc/{to be determined}" . )
++.Xr wprintf 3 ,
++.Xr printf_l 3
.Sh STANDARDS
Subject to the caveats noted in the
.Sx BUGS
--- /dev/null
+--- printf.c.orig 2003-05-20 15:22:43.000000000 -0700
++++ printf.c 2005-02-23 16:34:28.000000000 -0800
+@@ -40,6 +40,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/printf.c,v 1.10 2002/09/06 11:23:55 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdio.h>
+ #include <stdarg.h>
+
+@@ -50,7 +52,20 @@
+ va_list ap;
+
+ va_start(ap, fmt);
+- ret = vfprintf(stdout, fmt, ap);
++ ret = vfprintf_l(stdout, __current_locale(), fmt, ap);
++ va_end(ap);
++ return (ret);
++}
++
++int
++printf_l(locale_t loc, char const * __restrict fmt, ...)
++{
++ int ret;
++ va_list ap;
++
++ /* no need to call NORMALIZE_LOCALE(loc) because vfprintf_l will */
++ va_start(ap, fmt);
++ ret = vfprintf_l(stdout, loc, fmt, ap);
+ va_end(ap);
+ return (ret);
+ }
.\" SUCH DAMAGE.
.\"
.\" @(#)putc.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/stdio/putc.3,v 1.14 2003/02/23 01:47:47 ru Exp $
+.\" $FreeBSD: src/lib/libc/stdio/putc.3,v 1.15 2004/03/17 12:46:17 tjr Exp $
.\"
.Dd January 10, 2003
.Dt PUTC 3
.Pp
The
.Fn putc
-function acts essentially identically to
-.Fn fputc .
+macro acts essentially identically to
+.Fn fputc ,
+but is a macro that expands in-line.
+It may evaluate
+.Fa stream
+more than once, so arguments given to
+.Fn putc
+should not be expressions with potential side effects.
.Pp
The
.Fn putchar
static char sccsid[] = "@(#)putc.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/putc.c,v 1.11 2002/08/13 09:30:41 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/putc.c,v 1.13 2004/03/19 09:04:56 tjr Exp $");
#include "namespace.h"
#include <stdio.h>
#include "local.h"
#include "libc_private.h"
-/*
- * putc has traditionally been a macro in <stdio.h>. That is no
- * longer true because POSIX requires it to be thread-safe. POSIX
- * does define putc_unlocked() which is defined as a macro and is
- * probably what you want to use instead.
- *
- * #undef putc
- */
+#undef putc
+
int
putc(c, fp)
int c;
{
int retval;
FLOCKFILE(fp);
- ORIENT(fp, -1);
+ /* Orientation set by __sputc() when buffer is full. */
+ /* ORIENT(fp, -1); */
retval = __sputc(c, fp);
FUNLOCKFILE(fp);
return (retval);
static char sccsid[] = "@(#)putchar.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/putchar.c,v 1.11 2002/08/13 09:30:41 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/putchar.c,v 1.13 2004/03/19 09:04:56 tjr Exp $");
#include "namespace.h"
#include <stdio.h>
#include "local.h"
#include "libc_private.h"
-/*
- * putchar has traditionally been a macro in <stdio.h>. That is no
- * longer true because POSIX requires it to be thread-safe. POSIX
- * does define putchar_unlocked() which is defined as a macro and is
- * probably what you want to use instead.
- *
- * #undef putchar
- */
+#undef putchar
+
/*
* A subroutine version of the macro putchar
*/
FILE *so = stdout;
FLOCKFILE(so);
- ORIENT(so, -1);
+ /* Orientation set by __sputc() when buffer is full. */
+ /* ORIENT(so, -1); */
retval = __sputc(c, so);
FUNLOCKFILE(so);
return (retval);
static char sccsid[] = "@(#)puts.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/puts.c,v 1.9 2002/03/22 21:53:04 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/puts.c,v 1.10 2004/03/10 09:15:38 tjr Exp $");
#include "namespace.h"
#include <stdio.h>
#include "un-namespace.h"
#include "fvwrite.h"
#include "libc_private.h"
+#include "local.h"
/*
* Write the given string to stdout, appending a newline.
uio.uio_iov = &iov[0];
uio.uio_iovcnt = 2;
FLOCKFILE(stdout);
+ ORIENT(stdout, -1);
retval = __sfvwrite(stdout, &uio) ? EOF : '\n';
FUNLOCKFILE(stdout);
return (retval);
---- puts.c.orig Tue May 20 15:22:43 2003
-+++ puts.c Thu Jul 31 13:21:00 2003
-@@ -47,6 +47,9 @@
- #include "fvwrite.h"
+--- /Volumes/XDisk/tmp/Libc/stdio/FreeBSD/puts.c.orig 2004-03-10 01:15:38.000000000 -0800
++++ /Volumes/XDisk/tmp/Libc/stdio/FreeBSD/puts.c 2004-10-24 17:08:31.000000000 -0700
+@@ -48,6 +48,9 @@
#include "libc_private.h"
+ #include "local.h"
+// 3340719: __puts_null__ is used if string is NULL. Shared by fputs.c
+__private_extern__ char const __puts_null__[] = "(null)";
/*
* Write the given string to stdout, appending a newline.
*/
-@@ -55,12 +58,15 @@
+@@ -56,12 +59,15 @@
char const *s;
{
int retval;
.\" SUCH DAMAGE.
.\"
.\" @(#)putc.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/stdio/putwc.3,v 1.6 2002/12/04 18:57:45 ru Exp $
+.\" $FreeBSD: src/lib/libc/stdio/putwc.3,v 1.7 2004/03/16 13:30:11 tjr Exp $
.\"
-.Dd October 10, 2002
+.Dd March 3, 2004
.Dt PUTWC 3
.Os
.Sh NAME
.Nm fputwc ,
.Nm putwc ,
.Nm putwchar
-.Nd output a wide-character to a stream
+.Nd output a wide character to a stream
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
The
.Fn fputwc
function
-writes the wide-character
+writes the wide character
.Fa wc
to the output stream pointed to by
.Fa stream .
and
.Fn putwchar
functions
-return the wide-character written.
+return the wide character written.
If an error occurs, the value
.Dv WEOF
is returned.
--- /dev/null
+--- putwc.3.orig Fri Mar 11 17:08:50 2005
++++ putwc.3 Fri Mar 11 16:21:00 2005
+@@ -79,6 +79,12 @@
+ .Fn putwc
+ with an output stream of
+ .Dv stdout .
++.Pp
++Extended locale versions of these functions are documented in
++.Xr putwc_l 3 .
++See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn fputwc ,
+@@ -95,7 +101,8 @@
+ .Xr fopen 3 ,
+ .Xr getwc 3 ,
+ .Xr putc 3 ,
+-.Xr stdio 3
++.Xr stdio 3 ,
++.Xr putwc_l 3
+ .Sh STANDARDS
+ The
+ .Fn fputwc ,
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/putwc.c,v 1.2 2002/09/28 07:43:44 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/putwc.c,v 1.3 2004/05/25 10:42:52 tjr Exp $");
#include "namespace.h"
#include <stdio.h>
#include "libc_private.h"
#include "local.h"
+#undef putwc
+
/*
* Synonym for fputwc(). The only difference is that putwc(), if it is a
* macro, may evaluate `fp' more than once.
--- /dev/null
+--- putwc.c.orig 2004-11-25 11:38:35.000000000 -0800
++++ putwc.c 2005-02-23 17:32:05.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/putwc.c,v 1.3 2004/05/25 10:42:52 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include "namespace.h"
+ #include <stdio.h>
+ #include <wchar.h>
+@@ -44,5 +46,13 @@
+ putwc(wchar_t wc, FILE *fp)
+ {
+
+- return (fputwc(wc, fp));
++ return (fputwc_l(wc, fp, __current_locale()));
++}
++
++wint_t
++putwc_l(wchar_t wc, FILE *fp, locale_t loc)
++{
++
++ /* no need to call NORMALIZE_LOCALE(loc) because fputwc_l will */
++ return (fputwc_l(wc, fp, loc));
+ }
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/putwchar.c,v 1.2 2002/09/28 07:43:44 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/putwchar.c,v 1.3 2004/05/25 10:42:52 tjr Exp $");
#include "namespace.h"
#include <stdio.h>
#include "libc_private.h"
#include "local.h"
+#undef putwchar
+
/*
* Synonym for fputwc(wc, stdout).
*/
--- /dev/null
+--- putwchar.c.orig 2004-11-25 11:38:35.000000000 -0800
++++ putwchar.c 2005-02-23 17:33:23.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/putwchar.c,v 1.3 2004/05/25 10:42:52 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include "namespace.h"
+ #include <stdio.h>
+ #include <wchar.h>
+@@ -43,5 +45,13 @@
+ putwchar(wchar_t wc)
+ {
+
+- return (fputwc(wc, stdout));
++ return (fputwc_l(wc, stdout, __current_locale()));
++}
++
++wint_t
++putwchar_l(wchar_t wc, locale_t loc)
++{
++
++ /* no need to call NORMALIZE_LOCALE(loc) because fputwc_l will */
++ return (fputwc_l(wc, stdout, loc));
+ }
--- /dev/null
+Index: rewind.c
+===================================================================
+RCS file: /cvs/root/Libc/stdio/FreeBSD/rewind.c,v
+retrieving revision 1.2
+diff -u -d -b -w -p -u -r1.2 rewind.c
+--- rewind.c 2003/05/20 22:22:43 1.2
++++ rewind.c 2004/10/27 05:51:34
+@@ -58,8 +58,8 @@ rewind(FILE *fp)
+
+ FLOCKFILE(fp);
+ if (_fseeko(fp, (off_t)0, SEEK_SET, 1) == 0) {
+- clearerr_unlocked(fp);
+ errno = serrno;
+ }
++ clearerr_unlocked(fp); /* POSIX: clear stdio error regardless */
+ FUNLOCKFILE(fp);
+ }
--- /dev/null
+--- scanf.3.orig Fri Mar 11 17:08:59 2005
++++ scanf.3 Fri Mar 11 17:03:13 2005
+@@ -115,10 +115,18 @@
+ each successive conversion specifier
+ (but see the
+ .Cm *
+-conversion below).
++and
++.Cm %n$
++conversions below).
+ All conversions are introduced by the
+ .Cm %
+-(percent sign) character.
++(percent sign) character or
++.Cm %n$
++sequence. In the latter case the next
++.Em pointer
++will be the
++.Cm n
++th argument after the format string.
+ The
+ .Fa format
+ string
+@@ -132,10 +140,18 @@
+ when an input character does not match such a format character.
+ Scanning also stops
+ when an input conversion cannot be made (see below).
++.Pp
++Extended locale versions of these functions are documented in
++.Xr scanf_l 3 .
++See
++.Xr xlocale 3
++for more information.
+ .Sh CONVERSIONS
+ Following the
+ .Cm %
+-character introducing a conversion
++character or
++.Cm %n$
++sequence introducing a conversion
+ there may be a number of
+ .Em flag
+ characters, as follows:
+@@ -466,7 +482,8 @@
+ .Xr strtod 3 ,
+ .Xr strtol 3 ,
+ .Xr strtoul 3 ,
+-.Xr wscanf 3
++.Xr wscanf 3 ,
++.Xr scanf_l 3
+ .Sh STANDARDS
+ The functions
+ .Fn fscanf ,
+@@ -505,10 +522,6 @@
+ .Cm %512f
+ and
+ .Cm %512d .
+-.Pp
+-The
+-.Cm %n$
+-modifiers for positional arguments are not implemented.
+ .Pp
+ The
+ .Nm
--- /dev/null
+--- scanf.c.orig 2003-05-20 15:22:43.000000000 -0700
++++ scanf.c 2005-02-23 16:37:59.000000000 -0800
+@@ -40,6 +40,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/scanf.c,v 1.12 2003/01/03 23:27:27 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include "namespace.h"
+ #include <stdio.h>
+ #include <stdarg.h>
+@@ -55,7 +57,22 @@
+
+ va_start(ap, fmt);
+ FLOCKFILE(stdin);
+- ret = __svfscanf(stdin, fmt, ap);
++ ret = __svfscanf_l(stdin, __current_locale(), fmt, ap);
++ FUNLOCKFILE(stdin);
++ va_end(ap);
++ return (ret);
++}
++
++int
++scanf_l(locale_t loc, char const * __restrict fmt, ...)
++{
++ int ret;
++ va_list ap;
++
++ NORMALIZE_LOCALE(loc);
++ va_start(ap, fmt);
++ FLOCKFILE(stdin);
++ ret = __svfscanf_l(stdin, loc, fmt, ap);
+ FUNLOCKFILE(stdin);
+ va_end(ap);
+ return (ret);
.\" SUCH DAMAGE.
.\"
.\" @(#)setbuf.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/stdio/setbuf.3,v 1.14 2002/12/19 09:40:24 ru Exp $
+.\" $FreeBSD: src/lib/libc/stdio/setbuf.3,v 1.15 2004/08/24 21:48:21 alfred Exp $
.\"
.Dd June 4, 1993
.Dt SETBUF 3
.Fa size
bytes long;
this buffer will be used instead of the current buffer.
+If
+.Fa buf
+is not NULL, it is the caller's responsibility to
+.Xr free 3
+this buffer after closing the stream.
(If the
.Fa size
argument
--- /dev/null
+--- snprintf.c.orig 2003-05-20 15:22:43.000000000 -0700
++++ snprintf.c 2005-02-23 16:39:33.000000000 -0800
+@@ -40,6 +40,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/snprintf.c,v 1.20 2002/09/06 11:23:55 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <limits.h>
+ #include <stdio.h>
+ #include <stdarg.h>
+@@ -67,7 +69,37 @@
+ f._bf._size = f._w = n;
+ f._extra = &ext;
+ INITEXTRA(&f);
+- ret = __vfprintf(&f, fmt, ap);
++ ret = __vfprintf(&f, __current_locale(), fmt, ap);
++ if (on > 0)
++ *f._p = '\0';
++ va_end(ap);
++ return (ret);
++}
++
++int
++snprintf_l(char * __restrict str, size_t n, locale_t loc,
++ char const * __restrict fmt, ...)
++{
++ size_t on;
++ int ret;
++ va_list ap;
++ FILE f;
++ struct __sFILEX ext;
++
++ NORMALIZE_LOCALE(loc);
++ on = n;
++ if (n != 0)
++ n--;
++ if (n > INT_MAX)
++ n = INT_MAX;
++ va_start(ap, fmt);
++ f._file = -1;
++ f._flags = __SWR | __SSTR;
++ f._bf._base = f._p = (unsigned char *)str;
++ f._bf._size = f._w = n;
++ f._extra = &ext;
++ INITEXTRA(&f);
++ ret = __vfprintf(&f, loc, fmt, ap);
+ if (on > 0)
+ *f._p = '\0';
+ va_end(ap);
--- /dev/null
+--- sprintf.c.orig 2003-05-20 15:22:43.000000000 -0700
++++ sprintf.c 2005-02-23 16:40:52.000000000 -0800
+@@ -40,6 +40,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/sprintf.c,v 1.14 2002/09/06 11:23:55 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdio.h>
+ #include <stdarg.h>
+ #include <limits.h>
+@@ -60,7 +62,29 @@
+ f._extra = &ext;
+ INITEXTRA(&f);
+ va_start(ap, fmt);
+- ret = __vfprintf(&f, fmt, ap);
++ ret = __vfprintf(&f, __current_locale(), fmt, ap);
++ va_end(ap);
++ *f._p = 0;
++ return (ret);
++}
++
++int
++sprintf_l(char * __restrict str, locale_t loc, char const * __restrict fmt, ...)
++{
++ int ret;
++ va_list ap;
++ FILE f;
++ struct __sFILEX ext;
++
++ NORMALIZE_LOCALE(loc);
++ f._file = -1;
++ f._flags = __SWR | __SSTR;
++ f._bf._base = f._p = (unsigned char *)str;
++ f._bf._size = f._w = INT_MAX;
++ f._extra = &ext;
++ INITEXTRA(&f);
++ va_start(ap, fmt);
++ ret = __vfprintf(&f, loc, fmt, ap);
+ va_end(ap);
+ *f._p = 0;
+ return (ret);
--- /dev/null
+--- sscanf.c.orig 2003-05-20 15:22:44.000000000 -0700
++++ sscanf.c 2005-02-23 16:42:49.000000000 -0800
+@@ -40,6 +40,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/sscanf.c,v 1.11 2002/10/12 16:13:41 mike Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdio.h>
+ #include <string.h>
+ #include <stdarg.h>
+@@ -76,7 +78,31 @@
+ f._extra = &extra;
+ INITEXTRA(&f);
+ va_start(ap, fmt);
+- ret = __svfscanf(&f, fmt, ap);
++ ret = __svfscanf_l(&f, __current_locale(), fmt, ap);
++ va_end(ap);
++ return (ret);
++}
++
++int
++sscanf_l(const char * __restrict str, locale_t loc, char const * __restrict fmt, ...)
++{
++ int ret;
++ va_list ap;
++ struct __sFILEX extra;
++ FILE f;
++
++ NORMALIZE_LOCALE(loc);
++ f._file = -1;
++ f._flags = __SRD;
++ f._bf._base = f._p = (unsigned char *)str;
++ f._bf._size = f._r = strlen(str);
++ f._read = eofread;
++ f._ub._base = NULL;
++ f._lb._base = NULL;
++ f._extra = &extra;
++ INITEXTRA(&f);
++ va_start(ap, fmt);
++ ret = __svfscanf_l(&f, loc, fmt, ap);
+ va_end(ap);
+ return (ret);
+ }
.\" SUCH DAMAGE.
.\"
.\" @(#)stdio.3 8.7 (Berkeley) 4/19/94
-.\" $FreeBSD: src/lib/libc/stdio/stdio.3,v 1.24 2003/02/23 01:47:47 ru Exp $
+.\" $FreeBSD: src/lib/libc/stdio/stdio.3,v 1.26 2004/07/02 23:52:12 ru Exp $
.\"
.Dd January 10, 2003
.Dt STDIO 3
.Pp
A file may be subsequently reopened, by the same or another program
execution, and its contents reclaimed or modified (if it can be repositioned
-at the start). If the main function returns to its original caller, or
+at the start).
+If the main function returns to its original caller, or
the
.Xr exit 3
function is called, all open files are closed (hence all output
-streams are flushed) before program termination. Other methods
+streams are flushed) before program termination.
+Other methods
of program termination may not close files properly and hence
-buffered output may be lost. In particular,
+buffered output may be lost.
+In particular,
.Xr _exit 2
-does not flush stdio files. Neither does an exit due to a signal.
+does not flush stdio files.
+Neither does an exit due to a signal.
Buffers are flushed by
.Xr abort 3
as required by POSIX, although previous implementations did not.
.Dv SEEK_END ,
.Dv SEEK_SET ,
.Dv TMP_MAX ,
+.Dv clearerr ,
.Dv clearerr_unlocked ,
+.Dv feof ,
.Dv feof_unlocked ,
+.Dv ferror ,
.Dv ferror_unlocked ,
+.Dv fileno ,
.Dv fileno_unlocked ,
.Dv fropen ,
.Dv fwopen ,
+.Dv getc ,
.Dv getc_unlocked ,
+.Dv getchar ,
.Dv getchar_unlocked ,
+.Dv putc ,
.Dv putc_unlocked ,
+.Dv putchar ,
.Dv putchar_unlocked ,
.Dv stderr ,
.Dv stdin
and
.Dv stdout .
Function versions of the macro functions
+.Dv clearerr ,
.Dv clearerr_unlocked ,
+.Dv feof ,
.Dv feof_unlocked ,
+.Dv ferror ,
.Dv ferror_unlocked ,
+.Dv fileno ,
.Dv fileno_unlocked ,
+.Dv getc ,
.Dv getc_unlocked ,
+.Dv getchar ,
.Dv getchar_unlocked ,
-.Dv putc_unlocked
+.Dv putc ,
+.Dv putc_unlocked ,
+.Dv putchar ,
and
.Dv putchar_unlocked
exist and will be used if the macro
--- /dev/null
+--- swprintf.c.orig 2003-05-20 15:22:44.000000000 -0700
++++ swprintf.c 2005-02-23 16:44:36.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/swprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdarg.h>
+ #include <stdio.h>
+ #include <wchar.h>
+@@ -38,7 +40,22 @@
+ va_list ap;
+
+ va_start(ap, fmt);
+- ret = vswprintf(s, n, fmt, ap);
++ ret = vswprintf_l(s, n, __current_locale(), fmt, ap);
++ va_end(ap);
++
++ return (ret);
++}
++
++int
++swprintf_l(wchar_t * __restrict s, size_t n, locale_t loc,
++ const wchar_t * __restrict fmt, ...)
++{
++ int ret;
++ va_list ap;
++
++ /* no need to call NORMALIZE_LOCALE(loc) because vswprintf_l will */
++ va_start(ap, fmt);
++ ret = vswprintf_l(s, n, loc, fmt, ap);
+ va_end(ap);
+
+ return (ret);
--- /dev/null
+--- swscanf.c.orig 2003-05-20 15:22:44.000000000 -0700
++++ swscanf.c 2005-02-23 16:46:10.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/swscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdarg.h>
+ #include <stdio.h>
+ #include <wchar.h>
+@@ -38,7 +40,22 @@
+ int r;
+
+ va_start(ap, fmt);
+- r = vswscanf(str, fmt, ap);
++ r = vswscanf_l(str, __current_locale(), fmt, ap);
++ va_end(ap);
++
++ return (r);
++}
++
++int
++swscanf_l(const wchar_t * __restrict str, locale_t loc,
++ const wchar_t * __restrict fmt, ...)
++{
++ va_list ap;
++ int r;
++
++ /* no need to call NORMALIZE_LOCALE(loc) because vswscanf_l will */
++ va_start(ap, fmt);
++ r = vswscanf_l(str, loc, fmt, ap);
+ va_end(ap);
+
+ return (r);
.\" SUCH DAMAGE.
.\"
.\" @(#)tmpnam.3 8.2 (Berkeley) 11/17/93
-.\" $FreeBSD: src/lib/libc/stdio/tmpnam.3,v 1.14 2002/12/18 12:45:10 ru Exp $
+.\" $FreeBSD: src/lib/libc/stdio/tmpnam.3,v 1.16 2004/06/21 19:38:25 mpp Exp $
.\"
.Dd November 17, 1993
.Dt TMPFILE 3
past.
.Dv P_tmpdir
is defined in the include file
-.Aq Pa stdio.h .
+.In stdio.h .
If the argument
.Fa str
is
bytes in length.
.Dv L_tmpnam
is defined in the include file
-.Aq Pa stdio.h .
+.In stdio.h .
.Pp
The
.Fn tempnam
and
.Fn tempnam
functions are susceptible to a race condition
-occuring between the selection of the file name
+occurring between the selection of the file name
and the creation of the file,
which allows malicious users
to potentially overwrite arbitrary files in the system,
---- tmpnam.3.orig Fri May 28 14:35:53 2004
-+++ tmpnam.3 Fri May 28 14:36:02 2004
+--- /Volumes/XDisk/tmp/Libc/stdio/FreeBSD/tmpnam.3.orig 2004-06-21 12:38:25.000000000 -0700
++++ /Volumes/XDisk/tmp/Libc/stdio/FreeBSD/tmpnam.3 2004-10-24 17:08:31.000000000 -0700
@@ -229,11 +229,6 @@
.Sh SEE ALSO
.Xr mkstemp 3 ,
static char sccsid[] = "@(#)ungetc.c 8.2 (Berkeley) 11/3/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/ungetc.c,v 1.14 2002/08/13 09:30:41 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/ungetc.c,v 1.16 2004/03/10 12:41:11 tjr Exp $");
#include "namespace.h"
#include <stdio.h>
{
int ret;
- if (c == EOF)
- return (EOF);
if (!__sdidinit)
__sinit();
FLOCKFILE(fp);
+ ORIENT(fp, -1);
ret = __ungetc(c, fp);
FUNLOCKFILE(fp);
return (ret);
__ungetc(int c, FILE *fp)
{
- ORIENT(fp, -1);
-
if (c == EOF)
return (EOF);
if ((fp->_flags & __SRD) == 0) {
.\" SUCH DAMAGE.
.\"
.\" @(#)ungetc.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/stdio/ungetwc.3,v 1.4 2002/12/04 17:49:15 ru Exp $
+.\" $FreeBSD: src/lib/libc/stdio/ungetwc.3,v 1.5 2004/03/16 13:30:11 tjr Exp $
.\"
-.Dd October 24, 2001
+.Dd March 3, 2004
.Dt UNGETWC 3
.Os
.Sh NAME
.Nm ungetwc
-.Nd un-get wide-character from input stream
+.Nd un-get wide character from input stream
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.Sh DESCRIPTION
The
.Fn ungetwc
-function pushes the wide-character
+function pushes the wide character
.Fa wc
(converted to an
.Vt wchar_t )
back onto the input stream pointed to by
.Fa stream .
-The pushed-backed wide-characters will be returned by subsequent reads on the
+The pushed-backed wide characters will be returned by subsequent reads on the
stream (in reverse order).
A successful intervening call, using the same stream, to one of the file
positioning functions
.Xr fsetpos 3 ,
or
.Xr rewind 3
-will discard the pushed back wide-characters.
+will discard the pushed back wide characters.
.Pp
-One wide-character of push-back is guaranteed,
+One wide character of push-back is guaranteed,
but as long as there is
sufficient memory, an effectively infinite amount of pushback is allowed.
.Pp
.Fn ungetwc
function
returns
-the wide-character pushed-back after the conversion, or
+the wide character pushed-back after the conversion, or
.Dv WEOF
if the operation fails.
If the value of the argument
--- /dev/null
+--- ungetwc.3.orig Fri Mar 11 11:54:47 2005
++++ ungetwc.3 Fri Mar 11 11:55:38 2005
+@@ -42,7 +42,8 @@
+ .Dt UNGETWC 3
+ .Os
+ .Sh NAME
+-.Nm ungetwc
++.Nm ungetwc ,
++.Nm ungetwc_l
+ .Nd un-get wide character from input stream
+ .Sh LIBRARY
+ .Lb libc
+@@ -51,6 +52,9 @@
+ .In wchar.h
+ .Ft wint_t
+ .Fn ungetwc "wint_t wc" "FILE *stream"
++.In xlocale.h
++.Ft wint_t
++.Fn ungetwc_l "wint_t wc" "FILE *stream" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn ungetwc
+@@ -76,6 +80,14 @@
+ .Pp
+ If a character is successfully pushed-back,
+ the end-of-file indicator for the stream is cleared.
++.Pp
++While the
++.Fn ungetwc
++function uses the current locale, the
++.Fn ungetwc_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn ungetwc
+@@ -91,7 +103,8 @@
+ the operation will fail and the stream will remain unchanged.
+ .Sh SEE ALSO
+ .Xr fseek 3 ,
+-.Xr getwc 3
++.Xr getwc 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn ungetwc
/*-
- * Copyright (c) 2002 Tim J. Robbins.
+ * Copyright (c) 2002-2004 Tim J. Robbins.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/ungetwc.c,v 1.5 2002/10/16 12:09:43 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/ungetwc.c,v 1.9 2004/07/20 08:27:27 tjr Exp $");
#include "namespace.h"
#include <errno.h>
#include "un-namespace.h"
#include "libc_private.h"
#include "local.h"
+#include "mblocal.h"
/*
* Non-MT-safe version.
__ungetwc(wint_t wc, FILE *fp)
{
char buf[MB_LEN_MAX];
- mbstate_t mbs;
size_t len;
if (wc == WEOF)
return (WEOF);
- memset(&mbs, 0, sizeof(mbs));
- if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) {
+ if ((len = __wcrtomb(buf, wc, &fp->_extra->mbstate)) == (size_t)-1) {
fp->_flags |= __SERR;
return (WEOF);
}
--- /dev/null
+--- ungetwc.c.orig 2004-11-25 11:38:35.000000000 -0800
++++ ungetwc.c 2005-02-23 17:38:14.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/ungetwc.c,v 1.9 2004/07/20 08:27:27 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include "namespace.h"
+ #include <errno.h>
+ #include <stdio.h>
+@@ -41,14 +43,14 @@
+ * Non-MT-safe version.
+ */
+ wint_t
+-__ungetwc(wint_t wc, FILE *fp)
++__ungetwc(wint_t wc, FILE *fp, locale_t loc)
+ {
+ char buf[MB_LEN_MAX];
+ size_t len;
+
+ if (wc == WEOF)
+ return (WEOF);
+- if ((len = __wcrtomb(buf, wc, &fp->_extra->mbstate)) == (size_t)-1) {
++ if ((len = loc->__lc_ctype->__wcrtomb(buf, wc, &fp->_extra->mbstate, loc)) == (size_t)-1) {
+ fp->_flags |= __SERR;
+ return (WEOF);
+ }
+@@ -69,7 +71,21 @@
+
+ FLOCKFILE(fp);
+ ORIENT(fp, 1);
+- r = __ungetwc(wc, fp);
++ r = __ungetwc(wc, fp, __current_locale());
++ FUNLOCKFILE(fp);
++
++ return (r);
++}
++
++wint_t
++ungetwc_l(wint_t wc, FILE *fp, locale_t loc)
++{
++ wint_t r;
++
++ NORMALIZE_LOCALE(loc);
++ FLOCKFILE(fp);
++ ORIENT(fp, 1);
++ r = __ungetwc(wc, fp, loc);
+ FUNLOCKFILE(fp);
+
+ return (r);
--- /dev/null
+--- vasprintf.c.orig 2003-05-20 15:22:44.000000000 -0700
++++ vasprintf.c 2005-02-23 18:55:18.000000000 -0800
+@@ -30,6 +30,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/vasprintf.c,v 1.18 2002/09/26 13:11:24 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <errno.h>
+@@ -56,7 +58,42 @@
+ f._bf._size = f._w = 127; /* Leave room for the NUL */
+ f._extra = &ext;
+ INITEXTRA(&f);
+- ret = __vfprintf(&f, fmt, ap);
++ ret = __vfprintf(&f, __current_locale(), fmt, ap);
++ if (ret < 0) {
++ free(f._bf._base);
++ *str = NULL;
++ errno = ENOMEM;
++ return (-1);
++ }
++ *f._p = '\0';
++ *str = (char *)f._bf._base;
++ return (ret);
++}
++
++int
++vasprintf_l(str, loc, fmt, ap)
++ char **str;
++ locale_t loc;
++ const char *fmt;
++ __va_list ap;
++{
++ int ret;
++ FILE f;
++ struct __sFILEX ext;
++
++ NORMALIZE_LOCALE(loc);
++ f._file = -1;
++ f._flags = __SWR | __SSTR | __SALC;
++ f._bf._base = f._p = (unsigned char *)malloc(128);
++ if (f._bf._base == NULL) {
++ *str = NULL;
++ errno = ENOMEM;
++ return (-1);
++ }
++ f._bf._size = f._w = 127; /* Leave room for the NUL */
++ f._extra = &ext;
++ INITEXTRA(&f);
++ ret = __vfprintf(&f, loc, fmt, ap);
+ if (ret < 0) {
+ free(f._bf._base);
+ *str = NULL;
static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/vfprintf.c,v 1.65 2004/05/02 10:55:05 das Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/vfprintf.c,v 1.68 2004/08/26 06:25:28 des Exp $");
/*
* Actual printf innards.
decimal_point = localeconv()->decimal_point;
#endif
/* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
- if (cantwrite(fp))
+ if (prepwrite(fp) != 0)
return (EOF);
/* optimise fprintf(stderr) (and other unbuffered Unix files) */
done:
FLUSH();
error:
+ va_end(orgap);
#ifndef NO_FLOATING_POINT
if (dtoaresult != NULL)
freedtoa(dtoaresult);
*/
#define ADDTYPE(type) \
((nextarg >= tablesize) ? \
- __grow_type_table(nextarg, &typetable, &tablesize) : 0, \
+ __grow_type_table(nextarg, &typetable, &tablesize) : (void)0, \
(nextarg > tablemax) ? tablemax = nextarg : 0, \
typetable[nextarg++] = type)
---- vfprintf.c.orig Sun May 30 01:12:48 2004
-+++ vfprintf.c Sun May 30 01:18:16 2004
-@@ -58,6 +58,7 @@
+--- vfprintf.c.orig 2004-11-25 11:38:35.000000000 -0800
++++ vfprintf.c 2005-02-24 15:16:20.000000000 -0800
+@@ -40,6 +40,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/vfprintf.c,v 1.68 2004/08/26 06:25:28 des Exp $");
+
++#include "xlocale_private.h"
++
+ /*
+ * Actual printf innards.
+ *
+@@ -58,6 +60,7 @@
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <stdarg.h>
#include "un-namespace.h"
-@@ -66,6 +67,12 @@
+@@ -66,6 +69,12 @@
#include "local.h"
#include "fvwrite.h"
union arg {
int intarg;
u_int uintarg;
-@@ -93,6 +100,16 @@
+@@ -93,6 +102,16 @@
#endif
wint_t wintarg;
wchar_t *pwchararg;
};
/*
-@@ -103,7 +120,11 @@
+@@ -103,19 +122,56 @@
T_LONG, T_U_LONG, TP_LONG, T_LLONG, T_U_LLONG, TP_LLONG,
T_PTRDIFFT, TP_PTRDIFFT, T_SIZET, TP_SIZET,
T_INTMAXT, T_UINTMAXT, TP_INTMAXT, TP_VOID, TP_CHAR, TP_SCHAR,
};
static int __sprint(FILE *, struct __suio *);
-@@ -116,6 +137,37 @@
+-static int __sbprintf(FILE *, const char *, va_list) __printflike(2, 0);
++static int __sbprintf(FILE *, locale_t, const char *, va_list) __printflike(3, 0);
+ static char *__ujtoa(uintmax_t, char *, int, int, const char *, int, char,
+ const char *);
+ static char *__ultoa(u_long, char *, int, int, const char *, int, char,
+ const char *);
+-static char *__wcsconv(wchar_t *, int);
++static char *__wcsconv(wchar_t *, int, locale_t);
static void __find_arguments(const char *, va_list, union arg **);
static void __grow_type_table(int, enum typeid **, int *);
+ * processor would crash on illegal instruction. By isolating the calling
+ * sequence in getvec(), __vprintf() is callable by a non-Altivec processor.
+ *-----------------------------------------------------------------------*/
++static va_list getvec(union arg *, const union arg *, int, va_list) __attribute__((noinline));
++
+static va_list
+getvec(union arg *dst, const union arg *argtable, int nextarg, va_list ap)
+{
/*
* Flush out all the vectors defined by the given uio,
* then reset it so that it can be reused.
-@@ -451,6 +503,9 @@
+@@ -141,7 +197,7 @@
+ * worries about ungetc buffers and so forth.
+ */
+ static int
+-__sbprintf(FILE *fp, const char *fmt, va_list ap)
++__sbprintf(FILE *fp, locale_t loc, const char *fmt, va_list ap)
+ {
+ int ret;
+ FILE fake;
+@@ -160,7 +216,7 @@
+ fake._lbfsize = 0; /* not actually used, but Just In Case */
+
+ /* do the work, then copy any error status */
+- ret = __vfprintf(&fake, fmt, ap);
++ ret = __vfprintf(&fake, loc, fmt, ap);
+ if (ret >= 0 && __fflush(&fake))
+ ret = EOF;
+ if (fake._flags & __SERR)
+@@ -336,7 +392,7 @@
+ * that the wide char. string ends in a null character.
+ */
+ static char *
+-__wcsconv(wchar_t *wcsarg, int prec)
++__wcsconv(wchar_t *wcsarg, int prec, locale_t loc)
+ {
+ static const mbstate_t initial;
+ mbstate_t mbs;
+@@ -354,7 +410,7 @@
+ p = wcsarg;
+ mbs = initial;
+ for (;;) {
+- clen = wcrtomb(buf, *p++, &mbs);
++ clen = wcrtomb_l(buf, *p++, &mbs, loc);
+ if (clen == 0 || clen == (size_t)-1 ||
+ nbytes + clen > prec)
+ break;
+@@ -363,7 +419,7 @@
+ } else {
+ p = wcsarg;
+ mbs = initial;
+- nbytes = wcsrtombs(NULL, (const wchar_t **)&p, 0, &mbs);
++ nbytes = wcsrtombs_l(NULL, (const wchar_t **)&p, 0, &mbs, loc);
+ if (nbytes == (size_t)-1)
+ return (NULL);
+ }
+@@ -378,7 +434,7 @@
+ p = wcsarg;
+ mbs = initial;
+ while (mbp - convbuf < nbytes) {
+- clen = wcrtomb(mbp, *p++, &mbs);
++ clen = wcrtomb_l(mbp, *p++, &mbs, loc);
+ if (clen == 0 || clen == (size_t)-1)
+ break;
+ mbp += clen;
+@@ -402,7 +458,21 @@
+ int ret;
+
+ FLOCKFILE(fp);
+- ret = __vfprintf(fp, fmt0, ap);
++ ret = __vfprintf(fp, __current_locale(), fmt0, ap);
++ FUNLOCKFILE(fp);
++ return (ret);
++}
++
++int
++vfprintf_l(FILE * __restrict fp, locale_t loc, const char * __restrict fmt0,
++ va_list ap)
++
++{
++ int ret;
++
++ NORMALIZE_LOCALE(loc);
++ FLOCKFILE(fp);
++ ret = __vfprintf(fp, loc, fmt0, ap);
+ FUNLOCKFILE(fp);
+ return (ret);
+ }
+@@ -451,12 +521,15 @@
#define PTRDIFFT 0x800 /* ptrdiff_t */
#define INTMAXT 0x1000 /* intmax_t */
#define CHARINT 0x2000 /* print char using int format */
/*
* Non-MT-safe version
-@@ -502,6 +557,11 @@
+ */
+-int
+-__vfprintf(FILE *fp, const char *fmt0, va_list ap)
++__private_extern__ int
++__vfprintf(FILE *fp, locale_t loc, const char *fmt0, va_list ap)
+ {
+ char *fmt; /* format string */
+ int ch; /* character from fmt */
+@@ -502,6 +575,11 @@
int nseps; /* number of group separators with ' */
int nrepeats; /* number of repeats of the last group */
#endif
u_long ulval; /* integer arguments %[diouxX] */
uintmax_t ujval; /* %j, %ll, %q, %t, %z integers */
int base; /* base for [diouxX] conversion */
-@@ -574,15 +634,6 @@
+@@ -574,15 +652,6 @@
}
/*
* To extend shorts properly, we need both signed and unsigned
* argument extraction methods.
*/
-@@ -633,7 +684,6 @@
+@@ -633,22 +702,23 @@
val = GETARG (int); \
}
thousands_sep = '\0';
grouping = NULL;
convbuf = NULL;
-@@ -642,8 +692,10 @@
- decimal_point = localeconv()->decimal_point;
+ #ifndef NO_FLOATING_POINT
+ dtoaresult = NULL;
+- decimal_point = localeconv()->decimal_point;
++ decimal_point = localeconv_l(loc)->decimal_point;
#endif
/* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
-- if (cantwrite(fp))
-+ if (cantwrite(fp)) {
+- if (prepwrite(fp) != 0)
++ if (prepwrite(fp) != 0) {
+ errno = EBADF;
return (EOF);
+ }
/* optimise fprintf(stderr) (and other unbuffered Unix files) */
if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
-@@ -675,6 +727,9 @@
+ fp->_file >= 0)
+- return (__sbprintf(fp, fmt0, ap));
++ return (__sbprintf(fp, loc, fmt0, ap));
+
+ fmt = (char *)fmt0;
+ argtable = NULL;
+@@ -675,6 +745,9 @@
}
if (ch == '\0')
goto done;
fmt++; /* skip over '%' */
flags = 0;
-@@ -683,6 +738,9 @@
+@@ -683,6 +756,9 @@
prec = -1;
sign = '\0';
ox[1] = '\0';
rflag: ch = *fmt++;
reswitch: switch (ch) {
-@@ -698,6 +756,11 @@
+@@ -698,6 +774,11 @@
case '#':
flags |= ALT;
goto rflag;
case '*':
/*-
* ``A negative field width argument is taken as a
-@@ -793,6 +856,12 @@
+@@ -718,8 +799,8 @@
+ goto rflag;
+ case '\'':
+ flags |= GROUPING;
+- thousands_sep = *(localeconv()->thousands_sep);
+- grouping = localeconv()->grouping;
++ thousands_sep = *(localeconv_l(loc)->thousands_sep);
++ grouping = localeconv_l(loc)->grouping;
+ goto rflag;
+ case '.':
+ if ((ch = *fmt++) == '*') {
+@@ -793,14 +874,20 @@
flags |= LONGINT;
/*FALLTHROUGH*/
case 'c':
if (flags & LONGINT) {
static const mbstate_t initial;
mbstate_t mbs;
-@@ -817,6 +886,12 @@
+ size_t mbseqlen;
+
+ mbs = initial;
+- mbseqlen = wcrtomb(cp = buf,
+- (wchar_t)GETARG(wint_t), &mbs);
++ mbseqlen = wcrtomb_l(cp = buf,
++ (wchar_t)GETARG(wint_t), &mbs, loc);
+ if (mbseqlen == (size_t)-1) {
+ fp->_flags |= __SERR;
+ goto error;
+@@ -817,6 +904,12 @@
/*FALLTHROUGH*/
case 'd':
case 'i':
if (flags & INTMAX_SIZE) {
ujval = SJARG();
if ((intmax_t)ujval < 0) {
-@@ -835,6 +910,13 @@
+@@ -835,6 +928,13 @@
#ifndef NO_FLOATING_POINT
case 'a':
case 'A':
if (ch == 'a') {
ox[1] = 'x';
xdigs = xdigs_lower;
-@@ -866,6 +948,13 @@
+@@ -848,6 +948,12 @@
+ prec++;
+ if (dtoaresult != NULL)
+ freedtoa(dtoaresult);
++#ifdef LDBL_COMPAT
++ fparg.dbl = GETARG(double);
++ dtoaresult = cp =
++ __hdtoa(fparg.dbl, xdigs, prec,
++ &expt, &signflag, &dtoaend);
++#else /* !LDBL_COMPAT */
+ if (flags & LONGDBL) {
+ fparg.ldbl = GETARG(long double);
+ dtoaresult = cp =
+@@ -859,6 +965,7 @@
+ __hdtoa(fparg.dbl, xdigs, prec,
+ &expt, &signflag, &dtoaend);
+ }
++#endif /* LDBL_COMPAT */
+ if (prec < 0)
+ prec = dtoaend - cp;
+ if (expt == INT_MAX)
+@@ -866,6 +973,13 @@
goto fp_common;
case 'e':
case 'E':
expchar = ch;
if (prec < 0) /* account for digit before decpt */
prec = DEFPREC + 1;
-@@ -874,10 +963,24 @@
+@@ -874,10 +988,24 @@
goto fp_begin;
case 'f':
case 'F':
expchar = ch - ('g' - 'e');
if (prec == 0)
prec = 1;
-@@ -993,6 +1096,12 @@
+@@ -886,6 +1014,14 @@
+ prec = DEFPREC;
+ if (dtoaresult != NULL)
+ freedtoa(dtoaresult);
++#ifdef LDBL_COMPAT
++ fparg.dbl = GETARG(double);
++ dtoaresult = cp =
++ dtoa(fparg.dbl, expchar ? 2 : 3, prec,
++ &expt, &signflag, &dtoaend);
++ if (expt == 9999)
++ expt = INT_MAX;
++#else /* !LDBL_COMPAT */
+ if (flags & LONGDBL) {
+ fparg.ldbl = GETARG(long double);
+ dtoaresult = cp =
+@@ -899,6 +1035,7 @@
+ if (expt == 9999)
+ expt = INT_MAX;
+ }
++#endif /* LDBL_COMPAT */
+ fp_common:
+ if (signflag)
+ sign = '-';
+@@ -993,6 +1130,12 @@
flags |= LONGINT;
/*FALLTHROUGH*/
case 'o':
if (flags & INTMAX_SIZE)
ujval = UJARG();
else
-@@ -1007,6 +1116,12 @@
+@@ -1007,6 +1150,12 @@
* defined manner.''
* -- ANSI X3J11
*/
ujval = (uintmax_t)(uintptr_t)GETARG(void *);
base = 16;
xdigs = xdigs_lower;
-@@ -1056,6 +1171,12 @@
+@@ -1025,7 +1174,7 @@
+ if ((wcp = GETARG(wchar_t *)) == NULL)
+ cp = "(null)";
+ else {
+- convbuf = __wcsconv(wcp, prec);
++ convbuf = __wcsconv(wcp, prec, loc);
+ if (convbuf == NULL) {
+ fp->_flags |= __SERR;
+ goto error;
+@@ -1056,6 +1205,12 @@
flags |= LONGINT;
/*FALLTHROUGH*/
case 'u':
if (flags & INTMAX_SIZE)
ujval = UJARG();
else
-@@ -1068,6 +1189,12 @@
+@@ -1068,6 +1223,12 @@
case 'x':
xdigs = xdigs_lower;
hex:
if (flags & INTMAX_SIZE)
ujval = UJARG();
else
-@@ -1112,6 +1239,14 @@
+@@ -1112,6 +1273,14 @@
if (size > BUF) /* should never happen */
abort();
break;
default: /* "%?" prints ?, unless ? is NUL */
if (ch == '\0')
goto done;
-@@ -1123,6 +1258,184 @@
+@@ -1123,6 +1292,184 @@
break;
}
+#define VPRINT(cnt, ind, args...) do { \
+ if (flags & FPT) { \
+ velm.f = vval.vfloatarg[ind]; \
-+ vlen = asprintf(&vstr, vfmt , ## args, velm.f); \
++ vlen = asprintf_l(&vstr, loc, vfmt , ## args, velm.f); \
+ } else { \
+ switch (cnt) { \
+ default: \
+ velm.i = (unsigned char)vval.vchararg[ind]; \
+ break; \
+ } \
-+ vlen = asprintf(&vstr, vfmt , ## args, velm.i); \
++ vlen = asprintf_l(&vstr, loc, vfmt , ## args, velm.i); \
+ } \
+ ret += vlen; \
+ PRINT(vstr, vlen); \
/*
* All reasonable formats wind up here. At this point, `cp'
* points to a string which (if not flags&LADJUST) should be
-@@ -1405,6 +1718,11 @@
+@@ -1406,6 +1753,11 @@
if (flags & LONGINT)
ADDTYPE(T_WINT);
else
ADDTYPE(T_INT);
break;
case 'D':
-@@ -1412,6 +1730,11 @@
+@@ -1413,6 +1765,11 @@
/*FALLTHROUGH*/
case 'd':
case 'i':
ADDSARG();
break;
#ifndef NO_FLOATING_POINT
-@@ -1422,6 +1745,11 @@
+@@ -1423,6 +1780,11 @@
case 'f':
case 'g':
case 'G':
if (flags & LONGDBL)
ADDTYPE(T_LONG_DOUBLE);
else
-@@ -1450,9 +1778,19 @@
+@@ -1451,9 +1813,19 @@
flags |= LONGINT;
/*FALLTHROUGH*/
case 'o':
ADDTYPE(TP_VOID);
break;
case 'S':
-@@ -1470,6 +1808,11 @@
+@@ -1471,6 +1843,11 @@
case 'u':
case 'X':
case 'x':
ADDUARG();
break;
default: /* "%?" prints ?, unless ? is NUL */
-@@ -1555,6 +1898,12 @@
+@@ -1537,7 +1914,7 @@
+ (*argtable) [n].sizearg = va_arg (ap, size_t);
+ break;
+ case TP_SIZET:
+- (*argtable) [n].psizearg = va_arg (ap, ssize_t *);
++ (*argtable) [n].psizearg = va_arg (ap, size_t *);
+ break;
+ case T_INTMAXT:
+ (*argtable) [n].intmaxarg = va_arg (ap, intmax_t);
+@@ -1556,6 +1933,12 @@
(*argtable) [n].longdoublearg = va_arg (ap, long double);
break;
#endif
static char sccsid[] = "@(#)vfscanf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/vfscanf.c,v 1.32 2003/06/28 09:03:05 das Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/vfscanf.c,v 1.37 2004/05/02 10:55:05 das Exp $");
#include "namespace.h"
#include <ctype.h>
#include "libc_private.h"
#include "local.h"
-#define FLOATING_POINT
-
-#ifdef FLOATING_POINT
+#ifndef NO_FLOATING_POINT
#include <locale.h>
#endif
#define NDIGITS 0x80 /* no digits detected */
#define PFXOK 0x100 /* 0x prefix is (still) legal */
#define NZDIGITS 0x200 /* no zero digits detected */
+#define HAVESIGN 0x10000 /* sign detected */
/*
* Conversion types.
char buf[BUF]; /* buffer for numeric and mb conversions */
wchar_t *wcp; /* handy wide character pointer */
wchar_t *wcp0; /* saves original value of wcp */
- mbstate_t mbs; /* multibyte conversion state */
size_t nconv; /* length of multibyte sequence converted */
+ static const mbstate_t initial;
+ mbstate_t mbs;
/* `basefix' is used to avoid `if' tests in the integer scanner */
static short basefix[17] =
base = 16;
break;
-#ifdef FLOATING_POINT
+#ifndef NO_FLOATING_POINT
case 'A': case 'E': case 'F': case 'G':
case 'a': case 'e': case 'f': case 'g':
c = CT_FLOAT;
buf[n++] = *fp->_p;
fp->_p++;
fp->_r--;
- memset(&mbs, 0, sizeof(mbs));
+ mbs = initial;
nconv = mbrtowc(wcp, buf, n, &mbs);
if (nconv == (size_t)-1) {
fp->_flags |= __SERR;
buf[n++] = *fp->_p;
fp->_p++;
fp->_r--;
- memset(&mbs, 0, sizeof(mbs));
+ mbs = initial;
nconv = mbrtowc(wcp, buf, n, &mbs);
if (nconv == (size_t)-1) {
fp->_flags |= __SERR;
buf[n++] = *fp->_p;
fp->_p++;
fp->_r--;
- memset(&mbs, 0, sizeof(mbs));
+ mbs = initial;
nconv = mbrtowc(wcp, buf, n, &mbs);
if (nconv == (size_t)-1) {
fp->_flags |= __SERR;
case '+': case '-':
if (flags & SIGNOK) {
flags &= ~SIGNOK;
+ flags |= HAVESIGN;
goto ok;
}
break;
-
- /* x ok iff flag still set & 2nd char */
+
+ /*
+ * x ok iff flag still set & 2nd char (or
+ * 3rd char if we have a sign).
+ */
case 'x': case 'X':
- if (flags & PFXOK && p == buf + 1) {
+ if (flags & PFXOK && p ==
+ buf + 1 + !!(flags & HAVESIGN)) {
base = 16; /* if %i */
flags &= ~PFXOK;
goto ok;
nconversions++;
break;
-#ifdef FLOATING_POINT
+#ifndef NO_FLOATING_POINT
case CT_FLOAT:
/* scan a floating point number as if by strtod */
if (width == 0 || width > sizeof(buf) - 1)
nread += width;
nconversions++;
break;
-#endif /* FLOATING_POINT */
+#endif /* !NO_FLOATING_POINT */
}
}
input_failure:
/* NOTREACHED */
}
-#ifdef FLOATING_POINT
+#ifndef NO_FLOATING_POINT
static int
parsefloat(FILE *fp, char *buf, char *end)
{
goto reswitch;
}
case S_DIGITS:
- if (ishex && isxdigit(c) || isdigit(c))
+ if ((ishex && isxdigit(c)) || isdigit(c))
gotmantdig = 1;
else {
state = S_FRAC;
commit = p;
break;
case S_FRAC:
- if ((c == 'E' || c == 'e') && !ishex ||
- (c == 'P' || c == 'p') && ishex) {
+ if (((c == 'E' || c == 'e') && !ishex) ||
+ ((c == 'P' || c == 'p') && ishex)) {
if (!gotmantdig)
goto parsedone;
else
state = S_EXP;
- } else if (ishex && isxdigit(c) || isdigit(c)) {
+ } else if ((ishex && isxdigit(c)) || isdigit(c)) {
commit = p;
gotmantdig = 1;
} else
---- vfscanf.c.orig Tue Nov 18 16:48:06 2003
-+++ vfscanf.c Tue Nov 18 17:35:55 2003
-@@ -99,7 +99,9 @@
+--- vfscanf.c.orig 2004-11-25 11:38:35.000000000 -0800
++++ vfscanf.c 2005-02-23 19:24:50.000000000 -0800
+@@ -40,6 +40,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/vfscanf.c,v 1.37 2004/05/02 10:55:05 das Exp $");
+
++#include "xlocale_private.h"
++
+ #include "namespace.h"
+ #include <ctype.h>
+ #include <inttypes.h>
+@@ -97,10 +99,21 @@
+ #define CT_INT 3 /* %[dioupxX] conversion */
#define CT_FLOAT 4 /* %[efgEFG] conversion */
- static const u_char *__sccl(char *, const u_char *);
+-static const u_char *__sccl(char *, const u_char *);
-static int parsefloat(FILE *, char *, char *);
-+#ifdef FLOATING_POINT
-+static int parsefloat(FILE *, char **, size_t);
-+#endif /* FLOATING_POINT */
++static const u_char *__sccl(char *, const u_char *, locale_t);
++#ifndef NO_FLOATING_POINT
++static int parsefloat(FILE *, char **, size_t, locale_t);
++#endif /* !NO_FLOATING_POINT */
++/*
++ * For ppc, we need to have the 64-bit long double version defining storage for
++ * __scanfdebug, to be compatible with 10.3. For ppc64 and i386, we want the
++ * storage defined in the only version.
++ */
++#if defined(__ppc__) && !defined(BUILDING_VARIANT)
++extern int __scanfdebug;
++#else /* !__ppc__ || BUILDING_VARIANT */
int __scanfdebug = 0;
++#endif /* __ppc__ && !BUILDING_VARIANT */
+
+ __weak_reference(__vfscanf, vfscanf);
+
+@@ -108,12 +121,24 @@
+ * __vfscanf - MT-safe version
+ */
+ int
+-__vfscanf(FILE *fp, char const *fmt0, va_list ap)
++__vfscanf(FILE * __restrict fp, char const * __restrict fmt0, va_list ap)
++{
++ int ret;
++
++ FLOCKFILE(fp);
++ ret = __svfscanf_l(fp, __current_locale(), fmt0, ap);
++ FUNLOCKFILE(fp);
++ return (ret);
++}
++
++int
++vfscanf_l(FILE * __restrict fp, locale_t loc, char const * __restrict fmt0, va_list ap)
+ {
+ int ret;
-@@ -133,7 +135,6 @@
++ NORMALIZE_LOCALE(loc);
+ FLOCKFILE(fp);
+- ret = __svfscanf(fp, fmt0, ap);
++ ret = __svfscanf_l(fp, loc, fmt0, ap);
+ FUNLOCKFILE(fp);
+ return (ret);
+ }
+@@ -121,8 +146,8 @@
+ /*
+ * __svfscanf - non-MT-safe version of __vfscanf
+ */
+-int
+-__svfscanf(FILE *fp, const char *fmt0, va_list ap)
++__private_extern__ int
++__svfscanf_l(FILE * __restrict fp, locale_t loc, const char * __restrict fmt0, va_list ap)
+ {
+ const u_char *fmt = (const u_char *)fmt0;
+ int c; /* character from format, or conversion */
+@@ -132,7 +157,6 @@
int flags; /* flags as defined above */
char *p0; /* saves original value of p when necessary */
int nassigned; /* number of fields assigned */
int nread; /* number of characters consumed from fp */
int base; /* base argument to conversion function */
char ccltab[256]; /* character class table for %[...] */
-@@ -150,7 +151,6 @@
+@@ -140,24 +164,29 @@
+ wchar_t *wcp; /* handy wide character pointer */
+ wchar_t *wcp0; /* saves original value of wcp */
+ size_t nconv; /* length of multibyte sequence converted */
++ int index; /* %index$, zero if unset */
++ va_list ap_orig; /* to reset ap to first argument */
+ static const mbstate_t initial;
+ mbstate_t mbs;
++ int mb_cur_max;
+
+ /* `basefix' is used to avoid `if' tests in the integer scanner */
+ static short basefix[17] =
+ { 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
+
++ NORMALIZE_LOCALE(loc);
++ mb_cur_max = MB_CUR_MAX_L(loc);
ORIENT(fp, -1);
nassigned = 0;
- nconversions = 0;
nread = 0;
++ va_copy(ap_orig, ap);
for (;;) {
c = *fmt++;
-@@ -288,7 +288,6 @@
+ if (c == 0)
+ return (nassigned);
+- if (isspace(c)) {
+- while ((fp->_r > 0 || __srefill(fp) == 0) && isspace(*fp->_p))
++ if (isspace_l(c, loc)) {
++ while ((fp->_r > 0 || __srefill(fp) == 0) && isspace_l(*fp->_p, loc))
+ nread++, fp->_r--, fp->_p++;
+ continue;
+ }
+@@ -181,6 +210,18 @@
+ nread++;
+ continue;
+
++ case '$':
++ index = width;
++ if (index < 1 || index > NL_ARGMAX || fmt[-3] != '%') {
++ goto input_failure;
++ }
++ width = 0;
++ va_end(ap);
++ va_copy(ap, ap_orig); /* reset to %1$ */
++ for (; index > 1; index--) {
++ va_arg(ap, void*);
++ }
++ goto again;
+ case '*':
+ flags |= SUPPRESS;
+ goto again;
+@@ -267,7 +308,7 @@
+ break;
+
+ case '[':
+- fmt = __sccl(ccltab, fmt);
++ fmt = __sccl(ccltab, fmt, loc);
+ flags |= NOSKIP;
+ c = CT_CCL;
+ break;
+@@ -288,7 +329,6 @@
break;
case 'n':
if (flags & SUPPRESS) /* ??? */
continue;
if (flags & SHORTSHORT)
-@@ -421,7 +420,6 @@
+@@ -330,7 +370,7 @@
+ * that suppress this.
+ */
+ if ((flags & NOSKIP) == 0) {
+- while (isspace(*fp->_p)) {
++ while (isspace_l(*fp->_p, loc)) {
+ nread++;
+ if (--fp->_r > 0)
+ fp->_p++;
+@@ -360,7 +400,7 @@
+ wcp = NULL;
+ n = 0;
+ while (width != 0) {
+- if (n == MB_CUR_MAX) {
++ if (n == mb_cur_max) {
+ fp->_flags |= __SERR;
+ goto input_failure;
+ }
+@@ -368,7 +408,7 @@
+ fp->_p++;
+ fp->_r--;
+ mbs = initial;
+- nconv = mbrtowc(wcp, buf, n, &mbs);
++ nconv = mbrtowc_l(wcp, buf, n, &mbs, loc);
+ if (nconv == (size_t)-1) {
+ fp->_flags |= __SERR;
+ goto input_failure;
+@@ -421,7 +461,6 @@
nread += r;
nassigned++;
}
break;
case CT_CCL:
-@@ -525,7 +523,6 @@
+@@ -440,7 +479,7 @@
+ n = 0;
+ nchars = 0;
+ while (width != 0) {
+- if (n == MB_CUR_MAX) {
++ if (n == mb_cur_max) {
+ fp->_flags |= __SERR;
+ goto input_failure;
+ }
+@@ -448,7 +487,7 @@
+ fp->_p++;
+ fp->_r--;
+ mbs = initial;
+- nconv = mbrtowc(wcp, buf, n, &mbs);
++ nconv = mbrtowc_l(wcp, buf, n, &mbs, loc);
+ if (nconv == (size_t)-1) {
+ fp->_flags |= __SERR;
+ goto input_failure;
+@@ -456,8 +495,8 @@
+ if (nconv == 0)
+ *wcp = L'\0';
+ if (nconv != (size_t)-2) {
+- if (wctob(*wcp) != EOF &&
+- !ccltab[wctob(*wcp)]) {
++ if (wctob_l(*wcp, loc) != EOF &&
++ !ccltab[wctob_l(*wcp, loc)]) {
+ while (n != 0) {
+ n--;
+ __ungetc(buf[n],
+@@ -525,7 +564,6 @@
nassigned++;
}
nread += n;
break;
case CT_STRING:
-@@ -607,7 +604,6 @@
+@@ -540,8 +578,8 @@
+ else
+ wcp = &twc;
+ n = 0;
+- while (!isspace(*fp->_p) && width != 0) {
+- if (n == MB_CUR_MAX) {
++ while (!isspace_l(*fp->_p, loc) && width != 0) {
++ if (n == mb_cur_max) {
+ fp->_flags |= __SERR;
+ goto input_failure;
+ }
+@@ -549,7 +587,7 @@
+ fp->_p++;
+ fp->_r--;
+ mbs = initial;
+- nconv = mbrtowc(wcp, buf, n, &mbs);
++ nconv = mbrtowc_l(wcp, buf, n, &mbs, loc);
+ if (nconv == (size_t)-1) {
+ fp->_flags |= __SERR;
+ goto input_failure;
+@@ -557,7 +595,7 @@
+ if (nconv == 0)
+ *wcp = L'\0';
+ if (nconv != (size_t)-2) {
+- if (iswspace(*wcp)) {
++ if (iswspace_l(*wcp, loc)) {
+ while (n != 0) {
+ n--;
+ __ungetc(buf[n],
+@@ -585,7 +623,7 @@
+ }
+ } else if (flags & SUPPRESS) {
+ n = 0;
+- while (!isspace(*fp->_p)) {
++ while (!isspace_l(*fp->_p, loc)) {
+ n++, fp->_r--, fp->_p++;
+ if (--width == 0)
+ break;
+@@ -595,7 +633,7 @@
+ nread += n;
+ } else {
+ p0 = p = va_arg(ap, char *);
+- while (!isspace(*fp->_p)) {
++ while (!isspace_l(*fp->_p, loc)) {
+ fp->_r--;
+ *p++ = *fp->_p++;
+ if (--width == 0)
+@@ -607,7 +645,6 @@
nread += p - p0;
nassigned++;
}
continue;
case CT_INT:
-@@ -758,39 +754,42 @@
+@@ -738,9 +775,9 @@
+
+ *p = 0;
+ if ((flags & UNSIGNED) == 0)
+- res = strtoimax(buf, (char **)NULL, base);
++ res = strtoimax_l(buf, (char **)NULL, base, loc);
+ else
+- res = strtoumax(buf, (char **)NULL, base);
++ res = strtoumax_l(buf, (char **)NULL, base, loc);
+ if (flags & POINTER)
+ *va_arg(ap, void **) =
+ (void *)(uintptr_t)res;
+@@ -763,43 +800,52 @@
nassigned++;
}
nread += p - buf;
- nconversions++;
break;
- #ifdef FLOATING_POINT
+ #ifndef NO_FLOATING_POINT
case CT_FLOAT:
+ {
+ char *pbuf;
- if (width == 0 || width > sizeof(buf) - 1)
- width = sizeof(buf) - 1;
- if ((width = parsefloat(fp, buf, buf + width)) == 0)
-+ if ((width = parsefloat(fp, &pbuf, width)) == 0) {
++ if ((width = parsefloat(fp, &pbuf, width, loc)) == 0) {
+ if (pbuf)
+ free(pbuf);
goto match_failure;
if ((flags & SUPPRESS) == 0) {
if (flags & LONGDBL) {
- long double res = strtold(buf, &p);
-+ long double res = strtold(pbuf, &p);
++ long double res = strtold_l(pbuf, &p, loc);
*va_arg(ap, long double *) = res;
} else if (flags & LONG) {
- double res = strtod(buf, &p);
-+ double res = strtod(pbuf, &p);
++ double res = strtod_l(pbuf, &p, loc);
*va_arg(ap, double *) = res;
} else {
- float res = strtof(buf, &p);
-+ float res = strtof(pbuf, &p);
++ float res = strtof_l(pbuf, &p, loc);
*va_arg(ap, float *) = res;
}
- if (__scanfdebug && p - buf != width)
+ free(pbuf);
break;
+ }
- #endif /* FLOATING_POINT */
+ #endif /* !NO_FLOATING_POINT */
}
}
input_failure:
match_failure:
return (nassigned);
}
-@@ -910,7 +909,7 @@
- #ifdef FLOATING_POINT
++int
++__svfscanf(FILE * __restrict fp, const char * __restrict fmt0, va_list ap)
++{
++ return __svfscanf_l(fp, __current_locale(), fmt0, ap);
++}
++
+ /*
+ * Fill in the given table from the scanset at the given format
+ * (just after `['). Return a pointer to the character past the
+@@ -807,9 +853,10 @@
+ * considered part of the scanset.
+ */
+ static const u_char *
+-__sccl(tab, fmt)
++__sccl(tab, fmt, loc)
+ char *tab;
+ const u_char *fmt;
++ locale_t loc;
+ {
+ int c, n, v, i;
+
+@@ -845,6 +892,7 @@
+ return (fmt - 1);
+
+ case '-':
++ {
+ /*
+ * A scanset of the form
+ * [01+-]
+@@ -865,8 +913,8 @@
+ */
+ n = *fmt;
+ if (n == ']'
+- || (__collate_load_error ? n < c :
+- __collate_range_cmp (n, c) < 0
++ || (loc->__collate_load_error ? n < c :
++ __collate_range_cmp (n, c, loc) < 0
+ )
+ ) {
+ c = '-';
+@@ -874,14 +922,14 @@
+ }
+ fmt++;
+ /* fill in the range */
+- if (__collate_load_error) {
++ if (loc->__collate_load_error) {
+ do {
+ tab[++c] = v;
+ } while (c < n);
+ } else {
+ for (i = 0; i < 256; i ++)
+- if ( __collate_range_cmp (c, i) < 0
+- && __collate_range_cmp (i, n) <= 0
++ if ( __collate_range_cmp (c, i, loc) < 0
++ && __collate_range_cmp (i, n, loc) <= 0
+ )
+ tab[i] = v;
+ }
+@@ -901,7 +949,7 @@
+ return (fmt);
+ #endif
+ break;
+-
++ }
+ case ']': /* end of scanset */
+ return (fmt);
+
+@@ -915,7 +963,7 @@
+
+ #ifndef NO_FLOATING_POINT
static int
-parsefloat(FILE *fp, char *buf, char *end)
-+parsefloat(FILE *fp, char **buf, size_t width)
++parsefloat(FILE *fp, char **buf, size_t width, locale_t loc)
{
char *commit, *p;
int infnanpos = 0;
-@@ -921,7 +920,16 @@
+@@ -924,9 +972,18 @@
+ S_DIGITS, S_FRAC, S_EXP, S_EXPDIGITS
+ } state = S_START;
unsigned char c;
- char decpt = *localeconv()->decimal_point;
+- char decpt = *localeconv()->decimal_point;
++ char decpt = *localeconv_l(loc)->decimal_point;
_Bool gotmantdig = 0, ishex = 0;
+ char *b, *e;
+ size_t s;
/*
* We set commit = p whenever the string we have read so far
* constitutes a valid representation of a floating point
-@@ -931,8 +939,8 @@
+@@ -936,8 +993,8 @@
* always necessary to read at least one character that doesn't
* match; thus, we can't short-circuit "infinity" or "nan(...)".
*/
c = *fp->_p;
reswitch:
switch (state) {
-@@ -1046,6 +1054,17 @@
+@@ -997,7 +1054,7 @@
+ if (c == ')') {
+ commit = p;
+ infnanpos = -2;
+- } else if (!isalnum(c) && c != '_')
++ } else if (!isalnum_l(c, loc) && c != '_')
+ goto parsedone;
+ break;
+ }
+@@ -1013,7 +1070,7 @@
+ goto reswitch;
+ }
+ case S_DIGITS:
+- if ((ishex && isxdigit(c)) || isdigit(c))
++ if ((ishex && isxdigit_l(c, loc)) || isdigit_l(c, loc))
+ gotmantdig = 1;
+ else {
+ state = S_FRAC;
+@@ -1030,7 +1087,7 @@
+ goto parsedone;
+ else
+ state = S_EXP;
+- } else if ((ishex && isxdigit(c)) || isdigit(c)) {
++ } else if ((ishex && isxdigit_l(c, loc)) || isdigit_l(c, loc)) {
+ commit = p;
+ gotmantdig = 1;
+ } else
+@@ -1043,7 +1100,7 @@
+ else
+ goto reswitch;
+ case S_EXPDIGITS:
+- if (isdigit(c))
++ if (isdigit_l(c, loc))
+ commit = p;
+ else
+ goto parsedone;
+@@ -1051,6 +1108,17 @@
default:
abort();
}
*p++ = c;
if (--fp->_r > 0)
fp->_p++;
-@@ -1057,6 +1076,7 @@
+@@ -1062,6 +1130,7 @@
while (commit < --p)
__ungetc(*(u_char *)p, fp);
*++commit = '\0';
#endif /* LIBC_SCCS and not lint */
#endif
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/vfwprintf.c,v 1.20 2004/05/02 20:09:14 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/vfwprintf.c,v 1.23 2004/08/26 06:25:28 des Exp $");
/*
* Actual wprintf innards.
#endif
convbuf = NULL;
/* sorry, fwprintf(read_only_file, L"") returns WEOF, not 0 */
- if (cantwrite(fp))
+ if (prepwrite(fp) != 0)
return (EOF);
/* optimise fprintf(stderr) (and other unbuffered Unix files) */
}
done:
error:
+ va_end(orgap);
if (convbuf != NULL)
free(convbuf);
if (__sferror(fp))
*/
#define ADDTYPE(type) \
((nextarg >= tablesize) ? \
- __grow_type_table(nextarg, &typetable, &tablesize) : 0, \
+ __grow_type_table(nextarg, &typetable, &tablesize) : (void)0, \
(nextarg > tablemax) ? tablemax = nextarg : 0, \
typetable[nextarg++] = type)
---- vfwprintf.c.orig Sun May 30 01:25:05 2004
-+++ vfwprintf.c Sun May 30 01:26:53 2004
-@@ -63,12 +63,19 @@
+--- vfwprintf.c.orig 2004-11-25 11:38:36.000000000 -0800
++++ vfwprintf.c 2005-02-24 15:17:14.000000000 -0800
+@@ -42,6 +42,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/vfwprintf.c,v 1.23 2004/08/26 06:25:28 des Exp $");
+
++#include "xlocale_private.h"
++
+ /*
+ * Actual wprintf innards.
+ *
+@@ -63,12 +65,19 @@
#include <string.h>
#include <wchar.h>
#include <wctype.h>
union arg {
int intarg;
u_int uintarg;
-@@ -96,6 +103,16 @@
+@@ -96,6 +105,16 @@
#endif
wint_t wintarg;
wchar_t *pwchararg;
};
/*
-@@ -106,7 +123,11 @@
+@@ -106,26 +125,63 @@
T_LONG, T_U_LONG, TP_LONG, T_LLONG, T_U_LLONG, TP_LLONG,
T_PTRDIFFT, TP_PTRDIFFT, T_SIZET, TP_SIZET,
T_INTMAXT, T_UINTMAXT, TP_INTMAXT, TP_VOID, TP_CHAR, TP_SCHAR,
+#endif /* ALTIVEC */
};
- static int __sbprintf(FILE *, const wchar_t *, va_list);
-@@ -119,6 +140,37 @@
+-static int __sbprintf(FILE *, const wchar_t *, va_list);
+-static wint_t __xfputwc(wchar_t, FILE *);
++static int __sbprintf(FILE *, locale_t, const wchar_t *, va_list);
++static wint_t __xfputwc(wchar_t, FILE *, locale_t);
+ static wchar_t *__ujtoa(uintmax_t, wchar_t *, int, int, const char *, int,
+ char, const char *);
+ static wchar_t *__ultoa(u_long, wchar_t *, int, int, const char *, int,
+ char, const char *);
+-static wchar_t *__mbsconv(char *, int);
++static wchar_t *__mbsconv(char *, int, locale_t);
static void __find_arguments(const wchar_t *, va_list, union arg **);
static void __grow_type_table(int, enum typeid **, int *);
+ * processor would crash on illegal instruction. By isolating the calling
+ * sequence in getvec(), __vprintf() is callable by a non-Altivec processor.
+ *-----------------------------------------------------------------------*/
++static va_list getvec(union arg *, const union arg *, int, va_list) __attribute__((noinline));
++
+static va_list
+getvec(union arg *dst, const union arg *argtable, int nextarg, va_list ap)
+{
/*
* Helper function for `fprintf to unbuffered unix file': creates a
* temporary buffer. We only work on write-only files; this avoids
-@@ -474,6 +526,9 @@
+ * worries about ungetc buffers and so forth.
+ */
+ static int
+-__sbprintf(FILE *fp, const wchar_t *fmt, va_list ap)
++__sbprintf(FILE *fp, locale_t loc, const wchar_t *fmt, va_list ap)
+ {
+ int ret;
+ FILE fake;
+@@ -144,7 +200,7 @@
+ fake._lbfsize = 0; /* not actually used, but Just In Case */
+
+ /* do the work, then copy any error status */
+- ret = __vfwprintf(&fake, fmt, ap);
++ ret = __vfwprintf(&fake, loc, fmt, ap);
+ if (ret >= 0 && __fflush(&fake))
+ ret = WEOF;
+ if (fake._flags & __SERR)
+@@ -157,7 +213,7 @@
+ * File must already be locked.
+ */
+ static wint_t
+-__xfputwc(wchar_t wc, FILE *fp)
++__xfputwc(wchar_t wc, FILE *fp, locale_t loc)
+ {
+ static const mbstate_t initial;
+ mbstate_t mbs;
+@@ -167,10 +223,10 @@
+ size_t len;
+
+ if ((fp->_flags & __SSTR) == 0)
+- return (__fputwc(wc, fp));
++ return (__fputwc(wc, fp, loc));
+
+ mbs = initial;
+- if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) {
++ if ((len = wcrtomb_l(buf, wc, &mbs, loc)) == (size_t)-1) {
+ fp->_flags |= __SERR;
+ return (WEOF);
+ }
+@@ -350,13 +406,14 @@
+ * that the multibyte char. string ends in a null character.
+ */
+ static wchar_t *
+-__mbsconv(char *mbsarg, int prec)
++__mbsconv(char *mbsarg, int prec, locale_t loc)
+ {
+ static const mbstate_t initial;
+ mbstate_t mbs;
+ wchar_t *convbuf, *wcp;
+ const char *p;
+ size_t insize, nchars, nconv;
++ int mb_cur_max = MB_CUR_MAX_L(loc);
+
+ if (mbsarg == NULL)
+ return (NULL);
+@@ -374,7 +431,7 @@
+ insize = nchars = 0;
+ mbs = initial;
+ while (nchars != (size_t)prec) {
+- nconv = mbrlen(p, MB_CUR_MAX, &mbs);
++ nconv = mbrlen_l(p, mb_cur_max, &mbs, loc);
+ if (nconv == 0 || nconv == (size_t)-1 ||
+ nconv == (size_t)-2)
+ break;
+@@ -399,7 +456,7 @@
+ p = mbsarg;
+ mbs = initial;
+ while (insize != 0) {
+- nconv = mbrtowc(wcp, p, insize, &mbs);
++ nconv = mbrtowc_l(wcp, p, insize, &mbs, loc);
+ if (nconv == 0 || nconv == (size_t)-1 || nconv == (size_t)-2)
+ break;
+ wcp++;
+@@ -425,7 +482,21 @@
+ int ret;
+
+ FLOCKFILE(fp);
+- ret = __vfwprintf(fp, fmt0, ap);
++ ret = __vfwprintf(fp, __current_locale(), fmt0, ap);
++ FUNLOCKFILE(fp);
++ return (ret);
++}
++
++int
++vfwprintf_l(FILE * __restrict fp, locale_t loc, const wchar_t * __restrict fmt0,
++ va_list ap)
++
++{
++ int ret;
++
++ NORMALIZE_LOCALE(loc);
++ FLOCKFILE(fp);
++ ret = __vfwprintf(fp, loc, fmt0, ap);
+ FUNLOCKFILE(fp);
+ return (ret);
+ }
+@@ -474,12 +545,15 @@
#define PTRDIFFT 0x800 /* ptrdiff_t */
#define INTMAXT 0x1000 /* intmax_t */
#define CHARINT 0x2000 /* print char using int format */
/*
* Non-MT-safe version
-@@ -524,6 +579,11 @@
+ */
+-int
+-__vfwprintf(FILE *fp, const wchar_t *fmt0, va_list ap)
++__private_extern__ int
++__vfwprintf(FILE *fp, locale_t loc, const wchar_t *fmt0, va_list ap)
+ {
+ wchar_t *fmt; /* format string */
+ wchar_t ch; /* character from fmt */
+@@ -524,6 +598,11 @@
int nseps; /* number of group separators with ' */
int nrepeats; /* number of repeats of the last group */
#endif
u_long ulval; /* integer arguments %[diouxX] */
uintmax_t ujval; /* %j, %ll, %q, %t, %z integers */
int base; /* base for [diouxX] conversion */
-@@ -581,15 +641,6 @@
+@@ -560,7 +639,7 @@
+ */
+ #define PRINT(ptr, len) do { \
+ for (n3 = 0; n3 < (len); n3++) \
+- __xfputwc((ptr)[n3], fp); \
++ __xfputwc((ptr)[n3], fp, loc); \
+ } while (0)
+ #define PAD(howmany, with) do { \
+ if ((n = (howmany)) > 0) { \
+@@ -581,15 +660,6 @@
} while(0)
/*
* To extend shorts properly, we need both signed and unsigned
* argument extraction methods.
*/
-@@ -640,7 +691,6 @@
+@@ -640,21 +710,22 @@
val = GETARG (int); \
}
thousands_sep = '\0';
grouping = NULL;
#ifndef NO_FLOATING_POINT
-@@ -648,8 +698,10 @@
+- decimal_point = localeconv()->decimal_point;
++ decimal_point = localeconv_l(loc)->decimal_point;
#endif
convbuf = NULL;
/* sorry, fwprintf(read_only_file, L"") returns WEOF, not 0 */
-- if (cantwrite(fp))
-+ if (cantwrite(fp)) {
+- if (prepwrite(fp) != 0)
++ if (prepwrite(fp) != 0) {
+ errno = EBADF;
return (EOF);
+ }
/* optimise fprintf(stderr) (and other unbuffered Unix files) */
if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
-@@ -678,6 +730,9 @@
+ fp->_file >= 0)
+- return (__sbprintf(fp, fmt0, ap));
++ return (__sbprintf(fp, loc, fmt0, ap));
+
+ fmt = (wchar_t *)fmt0;
+ argtable = NULL;
+@@ -678,6 +749,9 @@
}
if (ch == '\0')
goto done;
fmt++; /* skip over '%' */
flags = 0;
-@@ -686,6 +741,9 @@
+@@ -686,6 +760,9 @@
prec = -1;
sign = '\0';
ox[1] = '\0';
rflag: ch = *fmt++;
reswitch: switch (ch) {
-@@ -701,6 +759,11 @@
+@@ -701,6 +778,11 @@
case '#':
flags |= ALT;
goto rflag;
case '*':
/*-
* ``A negative field width argument is taken as a
-@@ -796,6 +859,12 @@
+@@ -721,8 +803,8 @@
+ goto rflag;
+ case '\'':
+ flags |= GROUPING;
+- thousands_sep = *(localeconv()->thousands_sep);
+- grouping = localeconv()->grouping;
++ thousands_sep = *(localeconv_l(loc)->thousands_sep);
++ grouping = localeconv_l(loc)->grouping;
+ goto rflag;
+ case '.':
+ if ((ch = *fmt++) == '*') {
+@@ -796,10 +878,16 @@
flags |= LONGINT;
/*FALLTHROUGH*/
case 'c':
if (flags & LONGINT)
*(cp = buf) = (wchar_t)GETARG(wint_t);
else
-@@ -808,6 +877,12 @@
+- *(cp = buf) = (wchar_t)btowc(GETARG(int));
++ *(cp = buf) = (wchar_t)btowc_l(GETARG(int), loc);
+ size = 1;
+ sign = '\0';
+ break;
+@@ -808,6 +896,12 @@
/*FALLTHROUGH*/
case 'd':
case 'i':
if (flags & INTMAX_SIZE) {
ujval = SJARG();
if ((intmax_t)ujval < 0) {
-@@ -868,10 +943,24 @@
+@@ -837,6 +931,12 @@
+ }
+ if (prec >= 0)
+ prec++;
++#ifdef LDBL_COMPAT
++ fparg.dbl = GETARG(double);
++ dtoaresult =
++ __hdtoa(fparg.dbl, xdigs, prec,
++ &expt, &signflag, &dtoaend);
++#else /* !LDBL_COMPAT */
+ if (flags & LONGDBL) {
+ fparg.ldbl = GETARG(long double);
+ dtoaresult =
+@@ -848,6 +948,7 @@
+ __hdtoa(fparg.dbl, xdigs, prec,
+ &expt, &signflag, &dtoaend);
+ }
++#endif /* LDBL_COMPAT */
+ if (prec < 0)
+ prec = dtoaend - dtoaresult;
+ if (expt == INT_MAX)
+@@ -855,7 +956,7 @@
+ if (convbuf != NULL)
+ free(convbuf);
+ ndig = dtoaend - dtoaresult;
+- cp = convbuf = __mbsconv(dtoaresult, -1);
++ cp = convbuf = __mbsconv(dtoaresult, -1, loc);
+ freedtoa(dtoaresult);
+ goto fp_common;
+ case 'e':
+@@ -868,10 +969,24 @@
goto fp_begin;
case 'f':
case 'F':
expchar = ch - ('g' - 'e');
if (prec == 0)
prec = 1;
-@@ -989,6 +1078,12 @@
+@@ -880,6 +995,14 @@
+ prec = DEFPREC;
+ if (convbuf != NULL)
+ free(convbuf);
++#ifdef LDBL_COMPAT
++ fparg.dbl = GETARG(double);
++ dtoaresult =
++ dtoa(fparg.dbl, expchar ? 2 : 3, prec,
++ &expt, &signflag, &dtoaend);
++ if (expt == 9999)
++ expt = INT_MAX;
++#else /* !LDBL_COMPAT */
+ if (flags & LONGDBL) {
+ fparg.ldbl = GETARG(long double);
+ dtoaresult =
+@@ -893,8 +1016,9 @@
+ if (expt == 9999)
+ expt = INT_MAX;
+ }
++#endif /* LDBL_COMPAT */
+ ndig = dtoaend - dtoaresult;
+- cp = convbuf = __mbsconv(dtoaresult, -1);
++ cp = convbuf = __mbsconv(dtoaresult, -1, loc);
+ freedtoa(dtoaresult);
+ fp_common:
+ if (signflag)
+@@ -989,6 +1113,12 @@
flags |= LONGINT;
/*FALLTHROUGH*/
case 'o':
if (flags & INTMAX_SIZE)
ujval = UJARG();
else
-@@ -1003,6 +1098,12 @@
+@@ -1003,6 +1133,12 @@
* defined manner.''
* -- ANSI X3J11
*/
ujval = (uintmax_t)(uintptr_t)GETARG(void *);
base = 16;
xdigs = xdigs_lower;
-@@ -1055,6 +1156,12 @@
+@@ -1024,7 +1160,7 @@
+ if ((mbp = GETARG(char *)) == NULL)
+ cp = L"(null)";
+ else {
+- convbuf = __mbsconv(mbp, prec);
++ convbuf = __mbsconv(mbp, prec, loc);
+ if (convbuf == NULL) {
+ fp->_flags |= __SERR;
+ goto error;
+@@ -1055,6 +1191,12 @@
flags |= LONGINT;
/*FALLTHROUGH*/
case 'u':
if (flags & INTMAX_SIZE)
ujval = UJARG();
else
-@@ -1067,6 +1174,12 @@
+@@ -1067,6 +1209,12 @@
case 'x':
xdigs = xdigs_lower;
hex:
if (flags & INTMAX_SIZE)
ujval = UJARG();
else
-@@ -1111,6 +1224,14 @@
+@@ -1111,6 +1259,14 @@
if (size > BUF) /* should never happen */
abort();
break;
default: /* "%?" prints ?, unless ? is NUL */
if (ch == '\0')
goto done;
-@@ -1122,6 +1243,183 @@
+@@ -1122,6 +1278,183 @@
break;
}
+#define VPRINT(cnt, ind, args...) do { \
+ if (flags & FPT) { \
+ velm.f = vval.vfloatarg[ind]; \
-+ vlen = asprintf(&vstr, vfmt , ## args, velm.f); \
++ vlen = asprintf_l(&vstr, loc, vfmt , ## args, velm.f); \
+ } else { \
+ switch (cnt) { \
+ default: \
+ velm.i = (unsigned char)vval.vchararg[ind]; \
+ break; \
+ } \
-+ vlen = asprintf(&vstr, vfmt , ## args, velm.i); \
++ vlen = asprintf_l(&vstr, loc, vfmt , ## args, velm.i); \
+ } \
+ ret += vlen; \
+ PRINT(vstr, vlen); \
/*
* All reasonable formats wind up here. At this point, `cp'
* points to a string which (if not flags&LADJUST) should be
-@@ -1400,6 +1698,11 @@
+@@ -1401,6 +1734,11 @@
if (flags & LONGINT)
ADDTYPE(T_WINT);
else
ADDTYPE(T_INT);
break;
case 'D':
-@@ -1417,6 +1720,11 @@
+@@ -1418,6 +1756,11 @@
case 'f':
case 'g':
case 'G':
if (flags & LONGDBL)
ADDTYPE(T_LONG_DOUBLE);
else
-@@ -1445,9 +1753,19 @@
+@@ -1446,9 +1789,19 @@
flags |= LONGINT;
/*FALLTHROUGH*/
case 'o':
ADDTYPE(TP_VOID);
break;
case 'S':
-@@ -1465,6 +1783,11 @@
+@@ -1466,6 +1819,11 @@
case 'u':
case 'X':
case 'x':
ADDUARG();
break;
default: /* "%?" prints ?, unless ? is NUL */
-@@ -1550,6 +1873,12 @@
+@@ -1532,7 +1890,7 @@
+ (*argtable) [n].sizearg = va_arg (ap, size_t);
+ break;
+ case TP_SIZET:
+- (*argtable) [n].psizearg = va_arg (ap, ssize_t *);
++ (*argtable) [n].psizearg = va_arg (ap, size_t *);
+ break;
+ case T_INTMAXT:
+ (*argtable) [n].intmaxarg = va_arg (ap, intmax_t);
+@@ -1551,6 +1909,12 @@
(*argtable) [n].longdoublearg = va_arg (ap, long double);
break;
#endif
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#if 0
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)vfscanf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
-__FBSDID("FreeBSD: src/lib/libc/stdio/vfscanf.c,v 1.32 2003/06/28 09:03:05 das Exp ");
#endif
-__FBSDID("$FreeBSD: src/lib/libc/stdio/vfwscanf.c,v 1.6 2003/07/05 03:39:23 tjr Exp $");
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/libc/stdio/vfwscanf.c,v 1.12 2004/05/02 20:13:29 obrien Exp $");
#include "namespace.h"
#include <ctype.h>
#include "libc_private.h"
#include "local.h"
-#define FLOATING_POINT
-
-#ifdef FLOATING_POINT
+#ifndef NO_FLOATING_POINT
#include <locale.h>
#endif
#define NDIGITS 0x80 /* no digits detected */
#define PFXOK 0x100 /* 0x prefix is (still) legal */
#define NZDIGITS 0x200 /* no zero digits detected */
+#define HAVESIGN 0x10000 /* sign detected */
/*
* Conversion types.
wint_t wi; /* handy wint_t */
char *mbp; /* multibyte string pointer for %c %s %[ */
size_t nconv; /* number of bytes in mb. conversion */
- mbstate_t mbs; /* multibyte state */
char mbbuf[MB_LEN_MAX]; /* temporary mb. character buffer */
+ static const mbstate_t initial;
+ mbstate_t mbs;
/* `basefix' is used to avoid `if' tests in the integer scanner */
static short basefix[17] =
base = 16;
break;
-#ifdef FLOATING_POINT
+#ifndef NO_FLOATING_POINT
case 'A': case 'E': case 'F': case 'G':
case 'a': case 'e': case 'f': case 'g':
c = CT_FLOAT;
if (!(flags & SUPPRESS))
mbp = va_arg(ap, char *);
n = 0;
- memset(&mbs, 0, sizeof(mbs));
+ mbs = initial;
while (width != 0 &&
(wi = __fgetwc(fp)) != WEOF) {
if (width >= MB_CUR_MAX &&
if (!(flags & SUPPRESS))
mbp = va_arg(ap, char *);
n = 0;
- memset(&mbs, 0, sizeof(mbs));
+ mbs = initial;
while ((wi = __fgetwc(fp)) != WEOF &&
width != 0 && INCCL(wi)) {
if (width >= MB_CUR_MAX &&
} else {
if (!(flags & SUPPRESS))
mbp = va_arg(ap, char *);
- memset(&mbs, 0, sizeof(mbs));
+ mbs = initial;
while ((wi = __fgetwc(fp)) != WEOF &&
width != 0 &&
!iswspace(wi)) {
case '+': case '-':
if (flags & SIGNOK) {
flags &= ~SIGNOK;
+ flags |= HAVESIGN;
goto ok;
}
break;
-
- /* x ok iff flag still set & 2nd char */
+
+ /*
+ * x ok iff flag still set & 2nd char (or
+ * 3rd char if we have a sign).
+ */
case 'x': case 'X':
- if (flags & PFXOK && p == buf + 1) {
+ if (flags & PFXOK && p ==
+ buf + 1 + !!(flags & HAVESIGN)) {
base = 16; /* if %i */
flags &= ~PFXOK;
goto ok;
nconversions++;
break;
-#ifdef FLOATING_POINT
+#ifndef NO_FLOATING_POINT
case CT_FLOAT:
/* scan a floating point number as if by strtod */
if (width == 0 || width > sizeof(buf) /
nread += width;
nconversions++;
break;
-#endif /* FLOATING_POINT */
+#endif /* !NO_FLOATING_POINT */
}
}
input_failure:
return (nassigned);
}
-#ifdef FLOATING_POINT
+#ifndef NO_FLOATING_POINT
static int
parsefloat(FILE *fp, wchar_t *buf, wchar_t *end)
{
goto reswitch;
}
case S_DIGITS:
- if (ishex && iswxdigit(c) || iswdigit(c))
+ if ((ishex && iswxdigit(c)) || iswdigit(c))
gotmantdig = 1;
else {
state = S_FRAC;
commit = p;
break;
case S_FRAC:
- if ((c == 'E' || c == 'e') && !ishex ||
- (c == 'P' || c == 'p') && ishex) {
+ if (((c == 'E' || c == 'e') && !ishex) ||
+ ((c == 'P' || c == 'p') && ishex)) {
if (!gotmantdig)
goto parsedone;
else
state = S_EXP;
- } else if (ishex && iswxdigit(c) || iswdigit(c)) {
+ } else if ((ishex && iswxdigit(c)) || iswdigit(c)) {
commit = p;
gotmantdig = 1;
} else
---- vfwscanf.c.orig Tue Nov 18 16:48:06 2003
-+++ vfwscanf.c Tue Nov 18 17:36:22 2003
-@@ -100,7 +100,9 @@
+--- vfwscanf.c.orig 2004-11-25 11:38:36.000000000 -0800
++++ vfwscanf.c 2005-02-23 16:25:00.000000000 -0800
+@@ -42,6 +42,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/vfwscanf.c,v 1.12 2004/05/02 20:13:29 obrien Exp $");
+
++#include "xlocale_private.h"
++
+ #include "namespace.h"
+ #include <ctype.h>
+ #include <inttypes.h>
+@@ -98,7 +100,9 @@
#define CT_INT 3 /* %[dioupxX] conversion */
#define CT_FLOAT 4 /* %[efgEFG] conversion */
-static int parsefloat(FILE *, wchar_t *, wchar_t *);
-+#ifdef FLOATING_POINT
-+static int parsefloat(FILE *, wchar_t **, size_t);
-+#endif /* FLOATING_POINT */
++#ifndef NO_FLOATING_POINT
++static int parsefloat(FILE *, wchar_t **, size_t, locale_t loc);
++#endif /* !NO_FLOATING_POINT */
extern int __scanfdebug;
-@@ -136,7 +138,6 @@
+@@ -116,7 +120,21 @@
+
+ FLOCKFILE(fp);
+ ORIENT(fp, 1);
+- ret = __vfwscanf(fp, fmt, ap);
++ ret = __vfwscanf(fp, __current_locale(), fmt, ap);
++ FUNLOCKFILE(fp);
++ return (ret);
++}
++
++int
++vfwscanf_l(FILE * __restrict fp, locale_t loc, const wchar_t * __restrict fmt,
++ va_list ap)
++{
++ int ret;
++
++ NORMALIZE_LOCALE(loc);
++ FLOCKFILE(fp);
++ ORIENT(fp, 1);
++ ret = __vfwscanf(fp, loc, fmt, ap);
+ FUNLOCKFILE(fp);
+ return (ret);
+ }
+@@ -124,8 +142,9 @@
+ /*
+ * Non-MT-safe version.
+ */
+-int
+-__vfwscanf(FILE * __restrict fp, const wchar_t * __restrict fmt, va_list ap)
++__private_extern__ int
++__vfwscanf(FILE * __restrict fp, locale_t loc, const wchar_t * __restrict fmt,
++ va_list ap)
+ {
+ wint_t c; /* character from format, or conversion */
+ size_t width; /* field width, or 0 */
+@@ -134,7 +153,6 @@
int flags; /* flags as defined above */
wchar_t *p0; /* saves original value of p when necessary */
int nassigned; /* number of fields assigned */
int nread; /* number of characters consumed from fp */
int base; /* base argument to conversion function */
wchar_t buf[BUF]; /* buffer for numeric conversions */
-@@ -154,7 +155,6 @@
+@@ -145,27 +163,30 @@
+ char *mbp; /* multibyte string pointer for %c %s %[ */
+ size_t nconv; /* number of bytes in mb. conversion */
+ char mbbuf[MB_LEN_MAX]; /* temporary mb. character buffer */
++ int index; /* for %index$ */
++ va_list ap_orig; /* to reset ap to first argument */
+ static const mbstate_t initial;
+ mbstate_t mbs;
++ int mb_cur_max = MB_CUR_MAX_L(loc);
+
+ /* `basefix' is used to avoid `if' tests in the integer scanner */
+ static short basefix[17] =
{ 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
nassigned = 0;
- nconversions = 0;
nread = 0;
ccls = ccle = NULL;
++ va_copy(ap_orig, ap);
for (;;) {
-@@ -308,7 +308,6 @@
+ c = *fmt++;
+ if (c == 0)
+ return (nassigned);
+- if (iswspace(c)) {
+- while ((c = __fgetwc(fp)) != WEOF &&
+- iswspace(c))
++ if (iswspace_l(c, loc)) {
++ while ((c = __fgetwc(fp, loc)) != WEOF &&
++ iswspace_l(c, loc))
+ ;
+ if (c != WEOF)
+- __ungetwc(c, fp);
++ __ungetwc(c, fp, loc);
+ continue;
+ }
+ if (c != '%')
+@@ -180,15 +201,27 @@
+ switch (c) {
+ case '%':
+ literal:
+- if ((wi = __fgetwc(fp)) == WEOF)
++ if ((wi = __fgetwc(fp, loc)) == WEOF)
+ goto input_failure;
+ if (wi != c) {
+- __ungetwc(wi, fp);
++ __ungetwc(wi, fp, loc);
+ goto input_failure;
+ }
+ nread++;
+ continue;
+
++ case '$':
++ index = width;
++ if (index < 1 || index > NL_ARGMAX || fmt[-3] != '%') {
++ goto input_failure;
++ }
++ width = 0;
++ va_end(ap);
++ va_copy(ap, ap_orig); /* reset to %1$ */
++ for (; index > 1; index--) {
++ va_arg(ap, void*);
++ }
++ goto again;
+ case '*':
+ flags |= SUPPRESS;
+ goto again;
+@@ -307,7 +340,6 @@
break;
case 'n':
if (flags & SUPPRESS) /* ??? */
continue;
if (flags & SHORTSHORT)
-@@ -411,7 +410,6 @@
+@@ -343,11 +375,11 @@
+ * that suppress this.
+ */
+ if ((flags & NOSKIP) == 0) {
+- while ((wi = __fgetwc(fp)) != WEOF && iswspace(wi))
++ while ((wi = __fgetwc(fp, loc)) != WEOF && iswspace_l(wi, loc))
+ nread++;
+ if (wi == WEOF)
+ goto input_failure;
+- __ungetwc(wi, fp);
++ __ungetwc(wi, fp, loc);
+ }
+
+ /*
+@@ -364,7 +396,7 @@
+ p = va_arg(ap, wchar_t *);
+ n = 0;
+ while (width-- != 0 &&
+- (wi = __fgetwc(fp)) != WEOF) {
++ (wi = __fgetwc(fp, loc)) != WEOF) {
+ if (!(flags & SUPPRESS))
+ *p++ = (wchar_t)wi;
+ n++;
+@@ -380,19 +412,19 @@
+ n = 0;
+ mbs = initial;
+ while (width != 0 &&
+- (wi = __fgetwc(fp)) != WEOF) {
+- if (width >= MB_CUR_MAX &&
++ (wi = __fgetwc(fp, loc)) != WEOF) {
++ if (width >= mb_cur_max &&
+ !(flags & SUPPRESS)) {
+- nconv = wcrtomb(mbp, wi, &mbs);
++ nconv = wcrtomb_l(mbp, wi, &mbs, loc);
+ if (nconv == (size_t)-1)
+ goto input_failure;
+ } else {
+- nconv = wcrtomb(mbbuf, wi,
+- &mbs);
++ nconv = wcrtomb_l(mbbuf, wi,
++ &mbs, loc);
+ if (nconv == (size_t)-1)
+ goto input_failure;
+ if (nconv > width) {
+- __ungetwc(wi, fp);
++ __ungetwc(wi, fp, loc);
+ break;
+ }
+ if (!(flags & SUPPRESS))
+@@ -410,7 +442,6 @@
if (!(flags & SUPPRESS))
nassigned++;
}
break;
case CT_CCL:
-@@ -476,7 +474,6 @@
+@@ -420,20 +451,20 @@
+ /* take only those things in the class */
+ if ((flags & SUPPRESS) && (flags & LONG)) {
+ n = 0;
+- while ((wi = __fgetwc(fp)) != WEOF &&
++ while ((wi = __fgetwc(fp, loc)) != WEOF &&
+ width-- != 0 && INCCL(wi))
+ n++;
+ if (wi != WEOF)
+- __ungetwc(wi, fp);
++ __ungetwc(wi, fp, loc);
+ if (n == 0)
+ goto match_failure;
+ } else if (flags & LONG) {
+ p0 = p = va_arg(ap, wchar_t *);
+- while ((wi = __fgetwc(fp)) != WEOF &&
++ while ((wi = __fgetwc(fp, loc)) != WEOF &&
+ width-- != 0 && INCCL(wi))
+ *p++ = (wchar_t)wi;
+ if (wi != WEOF)
+- __ungetwc(wi, fp);
++ __ungetwc(wi, fp, loc);
+ n = p - p0;
+ if (n == 0)
+ goto match_failure;
+@@ -444,16 +475,16 @@
+ mbp = va_arg(ap, char *);
+ n = 0;
+ mbs = initial;
+- while ((wi = __fgetwc(fp)) != WEOF &&
++ while ((wi = __fgetwc(fp, loc)) != WEOF &&
+ width != 0 && INCCL(wi)) {
+- if (width >= MB_CUR_MAX &&
++ if (width >= mb_cur_max &&
+ !(flags & SUPPRESS)) {
+- nconv = wcrtomb(mbp, wi, &mbs);
++ nconv = wcrtomb_l(mbp, wi, &mbs, loc);
+ if (nconv == (size_t)-1)
+ goto input_failure;
+ } else {
+- nconv = wcrtomb(mbbuf, wi,
+- &mbs);
++ nconv = wcrtomb_l(mbbuf, wi,
++ &mbs, loc);
+ if (nconv == (size_t)-1)
+ goto input_failure;
+ if (nconv > width)
+@@ -468,14 +499,15 @@
+ n++;
+ }
+ if (wi != WEOF)
+- __ungetwc(wi, fp);
++ __ungetwc(wi, fp, loc);
++ if (n == 0)
++ goto match_failure;
+ if (!(flags & SUPPRESS)) {
+ *mbp = 0;
+ nassigned++;
}
}
nread += n;
break;
case CT_STRING:
-@@ -537,7 +534,6 @@
+@@ -483,39 +515,39 @@
+ if (width == 0)
+ width = (size_t)~0;
+ if ((flags & SUPPRESS) && (flags & LONG)) {
+- while ((wi = __fgetwc(fp)) != WEOF &&
++ while ((wi = __fgetwc(fp, loc)) != WEOF &&
+ width-- != 0 &&
+- !iswspace(wi))
++ !iswspace_l(wi, loc))
+ nread++;
+ if (wi != WEOF)
+- __ungetwc(wi, fp);
++ __ungetwc(wi, fp, loc);
+ } else if (flags & LONG) {
+ p0 = p = va_arg(ap, wchar_t *);
+- while ((wi = __fgetwc(fp)) != WEOF &&
++ while ((wi = __fgetwc(fp, loc)) != WEOF &&
+ width-- != 0 &&
+- !iswspace(wi)) {
++ !iswspace_l(wi, loc)) {
+ *p++ = (wchar_t)wi;
+ nread++;
+ }
+ if (wi != WEOF)
+- __ungetwc(wi, fp);
++ __ungetwc(wi, fp, loc);
+ *p = '\0';
+ nassigned++;
+ } else {
+ if (!(flags & SUPPRESS))
+ mbp = va_arg(ap, char *);
+ mbs = initial;
+- while ((wi = __fgetwc(fp)) != WEOF &&
++ while ((wi = __fgetwc(fp, loc)) != WEOF &&
+ width != 0 &&
+- !iswspace(wi)) {
+- if (width >= MB_CUR_MAX &&
++ !iswspace_l(wi, loc)) {
++ if (width >= mb_cur_max &&
+ !(flags & SUPPRESS)) {
+- nconv = wcrtomb(mbp, wi, &mbs);
++ nconv = wcrtomb_l(mbp, wi, &mbs, loc);
+ if (nconv == (size_t)-1)
+ goto input_failure;
+ } else {
+- nconv = wcrtomb(mbbuf, wi,
+- &mbs);
++ nconv = wcrtomb_l(mbbuf, wi,
++ &mbs, loc);
+ if (nconv == (size_t)-1)
+ goto input_failure;
+ if (nconv > width)
+@@ -530,13 +562,12 @@
+ nread++;
+ }
+ if (wi != WEOF)
+- __ungetwc(wi, fp);
++ __ungetwc(wi, fp, loc);
+ if (!(flags & SUPPRESS)) {
+ *mbp = 0;
nassigned++;
}
}
continue;
case CT_INT:
-@@ -680,47 +676,49 @@
+@@ -546,7 +577,7 @@
+ width = sizeof(buf) / sizeof(*buf) - 1;
+ flags |= SIGNOK | NDIGITS | NZDIGITS;
+ for (p = buf; width; width--) {
+- c = __fgetwc(fp);
++ c = __fgetwc(fp, loc);
+ /*
+ * Switch on the character; `goto ok'
+ * if we accept it as a part of number.
+@@ -630,7 +661,7 @@
+ * for a number. Stop accumulating digits.
+ */
+ if (c != WEOF)
+- __ungetwc(c, fp);
++ __ungetwc(c, fp, loc);
+ break;
+ ok:
+ /*
+@@ -646,22 +677,22 @@
+ */
+ if (flags & NDIGITS) {
+ if (p > buf)
+- __ungetwc(*--p, fp);
++ __ungetwc(*--p, fp, loc);
+ goto match_failure;
+ }
+ c = p[-1];
+ if (c == 'x' || c == 'X') {
+ --p;
+- __ungetwc(c, fp);
++ __ungetwc(c, fp, loc);
+ }
+ if ((flags & SUPPRESS) == 0) {
+ uintmax_t res;
+
+ *p = 0;
+ if ((flags & UNSIGNED) == 0)
+- res = wcstoimax(buf, NULL, base);
++ res = wcstoimax_l(buf, NULL, base, loc);
+ else
+- res = wcstoumax(buf, NULL, base);
++ res = wcstoumax_l(buf, NULL, base, loc);
+ if (flags & POINTER)
+ *va_arg(ap, void **) =
+ (void *)(uintptr_t)res;
+@@ -684,47 +715,49 @@
nassigned++;
}
nread += p - buf;
- nconversions++;
break;
- #ifdef FLOATING_POINT
+ #ifndef NO_FLOATING_POINT
case CT_FLOAT:
+ {
+ wchar_t *pbuf;
- sizeof(*buf) - 1)
- width = sizeof(buf) / sizeof(*buf) - 1;
- if ((width = parsefloat(fp, buf, buf + width)) == 0)
-+ if ((width = parsefloat(fp, &pbuf, width)) == 0) {
++ if ((width = parsefloat(fp, &pbuf, width, loc)) == 0) {
+ if (pbuf)
+ free(pbuf);
goto match_failure;
if ((flags & SUPPRESS) == 0) {
if (flags & LONGDBL) {
- long double res = wcstold(buf, &p);
-+ long double res = wcstold(pbuf, &p);
++ long double res = wcstold_l(pbuf, &p, loc);
*va_arg(ap, long double *) = res;
} else if (flags & LONG) {
- double res = wcstod(buf, &p);
-+ double res = wcstod(pbuf, &p);
++ double res = wcstod_l(pbuf, &p, loc);
*va_arg(ap, double *) = res;
} else {
- float res = wcstof(buf, &p);
-+ float res = wcstof(pbuf, &p);
++ float res = wcstof_l(pbuf, &p, loc);
*va_arg(ap, float *) = res;
}
- if (__scanfdebug && p - buf != width)
+ free(pbuf);
break;
+ }
- #endif /* FLOATING_POINT */
+ #endif /* !NO_FLOATING_POINT */
}
}
input_failure:
return (nassigned);
}
- #ifdef FLOATING_POINT
+ #ifndef NO_FLOATING_POINT
static int
-parsefloat(FILE *fp, wchar_t *buf, wchar_t *end)
-+parsefloat(FILE *fp, wchar_t **buf, size_t width)
++parsefloat(FILE *fp, wchar_t **buf, size_t width, locale_t loc)
{
wchar_t *commit, *p;
int infnanpos = 0;
-@@ -731,7 +729,16 @@
+@@ -733,9 +766,18 @@
+ S_DIGITS, S_FRAC, S_EXP, S_EXPDIGITS
+ } state = S_START;
wchar_t c;
- wchar_t decpt = (wchar_t)(unsigned char)*localeconv()->decimal_point;
+- wchar_t decpt = (wchar_t)(unsigned char)*localeconv()->decimal_point;
++ wchar_t decpt = (wchar_t)(unsigned char)*localeconv_l(loc)->decimal_point;
_Bool gotmantdig = 0, ishex = 0;
+ wchar_t *b, *e;
+ size_t s;
/*
* We set commit = p whenever the string we have read so far
* constitutes a valid representation of a floating point
-@@ -741,9 +748,9 @@
+@@ -745,10 +787,10 @@
* always necessary to read at least one character that doesn't
* match; thus, we can't short-circuit "infinity" or "nan(...)".
*/
+ commit = b - 1;
c = WEOF;
- for (p = buf; p < end; ) {
+- if ((c = __fgetwc(fp)) == WEOF)
+ for (p = b; width == 0 || p < e; ) {
- if ((c = __fgetwc(fp)) == WEOF)
++ if ((c = __fgetwc(fp, loc)) == WEOF)
break;
reswitch:
-@@ -858,6 +865,17 @@
+ switch (state) {
+@@ -808,7 +850,7 @@
+ if (c == ')') {
+ commit = p;
+ infnanpos = -2;
+- } else if (!iswalnum(c) && c != '_')
++ } else if (!iswalnum_l(c, loc) && c != '_')
+ goto parsedone;
+ break;
+ }
+@@ -824,7 +866,7 @@
+ goto reswitch;
+ }
+ case S_DIGITS:
+- if ((ishex && iswxdigit(c)) || iswdigit(c))
++ if ((ishex && iswxdigit_l(c, loc)) || iswdigit_l(c, loc))
+ gotmantdig = 1;
+ else {
+ state = S_FRAC;
+@@ -841,7 +883,7 @@
+ goto parsedone;
+ else
+ state = S_EXP;
+- } else if ((ishex && iswxdigit(c)) || iswdigit(c)) {
++ } else if ((ishex && iswxdigit_l(c, loc)) || iswdigit_l(c, loc)) {
+ commit = p;
+ gotmantdig = 1;
+ } else
+@@ -854,7 +896,7 @@
+ else
+ goto reswitch;
+ case S_EXPDIGITS:
+- if (iswdigit(c))
++ if (iswdigit_l(c, loc))
+ commit = p;
+ else
+ goto parsedone;
+@@ -862,16 +904,28 @@
default:
abort();
}
*p++ = c;
c = WEOF;
}
-@@ -868,6 +886,7 @@
+
+ parsedone:
+ if (c != WEOF)
+- __ungetwc(c, fp);
++ __ungetwc(c, fp, loc);
while (commit < --p)
- __ungetwc(*p, fp);
+- __ungetwc(*p, fp);
++ __ungetwc(*p, fp, loc);
*++commit = '\0';
- return (commit - buf);
+ *buf = b;
--- /dev/null
+--- vprintf.c.orig 2003-05-20 15:22:44.000000000 -0700
++++ vprintf.c 2005-02-23 16:51:20.000000000 -0800
+@@ -40,11 +40,21 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/vprintf.c,v 1.10 2002/09/06 11:23:56 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdio.h>
+
+ int
+ vprintf(const char * __restrict fmt, __va_list ap)
+ {
+
+- return (vfprintf(stdout, fmt, ap));
++ return (vfprintf_l(stdout, __current_locale(), fmt, ap));
++}
++
++int
++vprintf_l(locale_t loc, const char * __restrict fmt, __va_list ap)
++{
++
++ /* no need to call NORMALIZE_LOCALE(loc) because vfprintf_l will */
++ return (vfprintf_l(stdout, loc, fmt, ap));
+ }
--- /dev/null
+--- vscanf.c.orig 2003-05-20 15:22:44.000000000 -0700
++++ vscanf.c 2005-02-23 19:11:44.000000000 -0800
+@@ -40,6 +40,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/vscanf.c,v 1.12 2003/01/03 23:27:27 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include "namespace.h"
+ #include <stdio.h>
+ #include "un-namespace.h"
+@@ -54,7 +56,22 @@
+ int retval;
+
+ FLOCKFILE(stdin);
+- retval = __svfscanf(stdin, fmt, ap);
++ retval = __svfscanf_l(stdin, __current_locale(), fmt, ap);
++ FUNLOCKFILE(stdin);
++ return (retval);
++}
++
++int
++vscanf_l(loc, fmt, ap)
++ locale_t loc;
++ const char * __restrict fmt;
++ __va_list ap;
++{
++ int retval;
++
++ NORMALIZE_LOCALE(loc);
++ FLOCKFILE(stdin);
++ retval = __svfscanf_l(stdin, loc, fmt, ap);
+ FUNLOCKFILE(stdin);
+ return (retval);
+ }
--- /dev/null
+--- vsnprintf.c.orig 2003-07-24 12:42:14.000000000 -0700
++++ vsnprintf.c 2005-02-23 16:54:44.000000000 -0800
+@@ -40,6 +40,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/vsnprintf.c,v 1.22 2003/07/02 07:08:44 jkh Exp $");
+
++#include "xlocale_private.h"
++
+ #include <limits.h>
+ #include <stdio.h>
+ #include "local.h"
+@@ -72,7 +74,42 @@
+ f._bf._size = f._w = n;
+ f._extra = &ext;
+ INITEXTRA(&f);
+- ret = __vfprintf(&f, fmt, ap);
++ ret = __vfprintf(&f, __current_locale(), fmt, ap);
++ if (on > 0)
++ *f._p = '\0';
++ return (ret);
++}
++
++int
++vsnprintf_l(char * __restrict str, size_t n, locale_t loc,
++ const char * __restrict fmt, __va_list ap)
++{
++ size_t on;
++ int ret;
++ char dummy[2];
++ FILE f;
++ struct __sFILEX ext;
++
++ NORMALIZE_LOCALE(loc);
++ on = n;
++ if (n != 0)
++ n--;
++ if (n > INT_MAX)
++ n = INT_MAX;
++ /* Stdio internals do not deal correctly with zero length buffer */
++ if (n == 0) {
++ if (on > 0)
++ *str = '\0';
++ str = dummy;
++ n = 1;
++ }
++ f._file = -1;
++ f._flags = __SWR | __SSTR;
++ f._bf._base = f._p = (unsigned char *)str;
++ f._bf._size = f._w = n;
++ f._extra = &ext;
++ INITEXTRA(&f);
++ ret = __vfprintf(&f, loc, fmt, ap);
+ if (on > 0)
+ *f._p = '\0';
+ return (ret);
--- /dev/null
+--- vsprintf.c.orig 2003-05-20 15:22:44.000000000 -0700
++++ vsprintf.c 2005-02-23 16:56:03.000000000 -0800
+@@ -40,6 +40,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/vsprintf.c,v 1.14 2002/09/06 11:23:56 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdio.h>
+ #include <limits.h>
+ #include "local.h"
+@@ -57,7 +59,27 @@
+ f._bf._size = f._w = INT_MAX;
+ f._extra = &ext;
+ INITEXTRA(&f);
+- ret = __vfprintf(&f, fmt, ap);
++ ret = __vfprintf(&f, __current_locale(), fmt, ap);
++ *f._p = 0;
++ return (ret);
++}
++
++int
++vsprintf_l(char * __restrict str, locale_t loc, const char * __restrict fmt,
++ __va_list ap)
++{
++ int ret;
++ FILE f;
++ struct __sFILEX ext;
++
++ NORMALIZE_LOCALE(loc);
++ f._file = -1;
++ f._flags = __SWR | __SSTR;
++ f._bf._base = f._p = (unsigned char *)str;
++ f._bf._size = f._w = INT_MAX;
++ f._extra = &ext;
++ INITEXTRA(&f);
++ ret = __vfprintf(&f, loc, fmt, ap);
+ *f._p = 0;
+ return (ret);
+ }
--- /dev/null
+--- vsscanf.c.orig 2003-05-20 15:22:44.000000000 -0700
++++ vsscanf.c 2005-02-23 16:57:18.000000000 -0800
+@@ -40,6 +40,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/vsscanf.c,v 1.12 2002/10/12 16:13:41 mike Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdio.h>
+ #include <string.h>
+ #include "local.h"
+@@ -76,5 +78,28 @@
+ f._lb._base = NULL;
+ f._extra = &ext;
+ INITEXTRA(&f);
+- return (__svfscanf(&f, fmt, ap));
++ return (__svfscanf_l(&f, __current_locale(), fmt, ap));
++}
++
++int
++vsscanf_l(str, loc, fmt, ap)
++ const char * __restrict str;
++ locale_t loc;
++ const char * __restrict fmt;
++ __va_list ap;
++{
++ FILE f;
++ struct __sFILEX ext;
++
++ NORMALIZE_LOCALE(loc);
++ f._file = -1;
++ f._flags = __SRD;
++ f._bf._base = f._p = (unsigned char *)str;
++ f._bf._size = f._r = strlen(str);
++ f._read = eofread;
++ f._ub._base = NULL;
++ f._lb._base = NULL;
++ f._extra = &ext;
++ INITEXTRA(&f);
++ return (__svfscanf_l(&f, loc, fmt, ap));
+ }
#if 0
__FBSDID("FreeBSD: src/lib/libc/stdio/vasprintf.c,v 1.16 2002/08/21 16:19:57 mike Exp ");
#endif
-__FBSDID("$FreeBSD: src/lib/libc/stdio/vswprintf.c,v 1.3 2003/01/07 06:20:47 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/vswprintf.c,v 1.5 2004/04/07 09:55:05 tjr Exp $");
#include <errno.h>
#include <stdio.h>
vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt,
__va_list ap)
{
+ static const mbstate_t initial;
+ mbstate_t mbs;
FILE f;
struct __sFILEX ext;
- mbstate_t mbs;
char *mbp;
int ret, sverrno;
}
*f._p = '\0';
mbp = f._bf._base;
- memset(&mbs, 0, sizeof(mbs));
/*
* XXX Undo the conversion from wide characters to multibyte that
* fputwc() did in __vfwprintf().
*/
+ mbs = initial;
if (mbsrtowcs(s, (const char **)&mbp, n, &mbs) == (size_t)-1) {
free(f._bf._base);
errno = EILSEQ;
---- vswprintf.c.orig Tue May 20 15:22:44 2003
-+++ vswprintf.c Wed Nov 12 00:30:05 2003
-@@ -48,6 +48,7 @@
- mbstate_t mbs;
+--- vswprintf.c.orig 2004-11-25 11:38:36.000000000 -0800
++++ vswprintf.c 2005-02-24 15:20:20.000000000 -0800
+@@ -33,6 +33,8 @@
+ #endif
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/vswprintf.c,v 1.5 2004/04/07 09:55:05 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <errno.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+@@ -49,7 +51,66 @@
+ struct __sFILEX ext;
char *mbp;
int ret, sverrno;
+ size_t conv;
++ locale_t loc = __current_locale();
++
++ if (n == 0) {
++ errno = EINVAL;
++ return (-1);
++ }
++
++ f._file = -1;
++ f._flags = __SWR | __SSTR | __SALC;
++ f._bf._base = f._p = (unsigned char *)malloc(128);
++ if (f._bf._base == NULL) {
++ errno = ENOMEM;
++ return (-1);
++ }
++ f._bf._size = f._w = 127; /* Leave room for the NUL */
++ f._extra = &ext;
++ INITEXTRA(&f);
++ ret = __vfwprintf(&f, loc, fmt, ap);
++ if (ret < 0) {
++ sverrno = errno;
++ free(f._bf._base);
++ errno = sverrno;
++ return (-1);
++ }
++ *f._p = '\0';
++ mbp = (char *)f._bf._base;
++ /*
++ * XXX Undo the conversion from wide characters to multibyte that
++ * fputwc() did in __vfwprintf().
++ */
++ mbs = initial;
++ if ((conv = mbsrtowcs_l(s, (const char **)&mbp, n, &mbs, loc)) == (size_t)-1) {
++ free(f._bf._base);
++ errno = EILSEQ;
++ return (-1);
++ }
++ free(f._bf._base);
++ if (conv >= n) {
++ s[n - 1] = L'\0';
++ errno = EOVERFLOW;
++ return (-1);
++ }
++
++ return (ret);
++}
++
++int
++vswprintf_l(wchar_t * __restrict s, size_t n, locale_t loc,
++ const wchar_t * __restrict fmt, __va_list ap)
++{
++ static const mbstate_t initial;
++ mbstate_t mbs;
++ FILE f;
++ struct __sFILEX ext;
++ char *mbp;
++ int ret, sverrno;
++ size_t conv;
++ NORMALIZE_LOCALE(loc);
if (n == 0) {
errno = EINVAL;
-@@ -78,13 +79,13 @@
+ return (-1);
+@@ -65,7 +126,7 @@
+ f._bf._size = f._w = 127; /* Leave room for the NUL */
+ f._extra = &ext;
+ INITEXTRA(&f);
+- ret = __vfwprintf(&f, fmt, ap);
++ ret = __vfwprintf(&f, loc, fmt, ap);
+ if (ret < 0) {
+ sverrno = errno;
+ free(f._bf._base);
+@@ -73,19 +134,19 @@
+ return (-1);
+ }
+ *f._p = '\0';
+- mbp = f._bf._base;
++ mbp = (char *)f._bf._base;
+ /*
* XXX Undo the conversion from wide characters to multibyte that
* fputwc() did in __vfwprintf().
*/
+ mbs = initial;
- if (mbsrtowcs(s, (const char **)&mbp, n, &mbs) == (size_t)-1) {
-+ if ((conv = mbsrtowcs(s, (const char **)&mbp, n, &mbs)) == (size_t)-1) {
++ if ((conv = mbsrtowcs_l(s, (const char **)&mbp, n, &mbs, loc)) == (size_t)-1) {
free(f._bf._base);
errno = EILSEQ;
return (-1);
#endif /* LIBC_SCCS and not lint */
__FBSDID("FreeBSD: src/lib/libc/stdio/vsscanf.c,v 1.11 2002/08/21 16:19:57 mike Exp ");
#endif
-__FBSDID("$FreeBSD: src/lib/libc/stdio/vswscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/vswscanf.c,v 1.3 2004/04/07 09:55:05 tjr Exp $");
#include <limits.h>
#include <stdarg.h>
vswscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt,
va_list ap)
{
- FILE f;
+ static const mbstate_t initial;
mbstate_t mbs;
+ FILE f;
struct __sFILEX ext;
char *mbstr;
size_t mlen;
*/
if ((mbstr = malloc(wcslen(str) * MB_CUR_MAX + 1)) == NULL)
return (EOF);
- memset(&mbs, 0, sizeof(mbs));
+ mbs = initial;
if ((mlen = wcsrtombs(mbstr, &str, SIZE_T_MAX, &mbs)) == (size_t)-1) {
free(mbstr);
return (EOF);
--- /dev/null
+--- vswscanf.c.orig 2004-11-25 11:38:36.000000000 -0800
++++ vswscanf.c 2005-02-23 17:03:30.000000000 -0800
+@@ -43,6 +43,8 @@
+ #endif
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/vswscanf.c,v 1.3 2004/04/07 09:55:05 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <limits.h>
+ #include <stdarg.h>
+ #include <stdio.h>
+@@ -71,15 +73,55 @@
+ char *mbstr;
+ size_t mlen;
+ int r;
++ locale_t loc = __current_locale();
++
++ /*
++ * XXX Convert the wide character string to multibyte, which
++ * __vfwscanf() will convert back to wide characters.
++ */
++ if ((mbstr = malloc(wcslen(str) * MB_CUR_MAX_L(loc) + 1)) == NULL)
++ return (EOF);
++ mbs = initial;
++ if ((mlen = wcsrtombs_l(mbstr, &str, SIZE_T_MAX, &mbs, loc)) == (size_t)-1) {
++ free(mbstr);
++ return (EOF);
++ }
++ f._file = -1;
++ f._flags = __SRD;
++ f._bf._base = f._p = (unsigned char *)mbstr;
++ f._bf._size = f._r = mlen;
++ f._read = eofread;
++ f._ub._base = NULL;
++ f._lb._base = NULL;
++ f._extra = &ext;
++ INITEXTRA(&f);
++ r = __vfwscanf(&f, loc, fmt, ap);
++ free(mbstr);
++
++ return (r);
++}
++
++int
++vswscanf_l(const wchar_t * __restrict str, locale_t loc,
++ const wchar_t * __restrict fmt, va_list ap)
++{
++ static const mbstate_t initial;
++ mbstate_t mbs;
++ FILE f;
++ struct __sFILEX ext;
++ char *mbstr;
++ size_t mlen;
++ int r;
+
++ NORMALIZE_LOCALE(loc);
+ /*
+ * XXX Convert the wide character string to multibyte, which
+ * __vfwscanf() will convert back to wide characters.
+ */
+- if ((mbstr = malloc(wcslen(str) * MB_CUR_MAX + 1)) == NULL)
++ if ((mbstr = malloc(wcslen(str) * MB_CUR_MAX_L(loc) + 1)) == NULL)
+ return (EOF);
+ mbs = initial;
+- if ((mlen = wcsrtombs(mbstr, &str, SIZE_T_MAX, &mbs)) == (size_t)-1) {
++ if ((mlen = wcsrtombs_l(mbstr, &str, SIZE_T_MAX, &mbs, loc)) == (size_t)-1) {
+ free(mbstr);
+ return (EOF);
+ }
+@@ -92,7 +134,7 @@
+ f._lb._base = NULL;
+ f._extra = &ext;
+ INITEXTRA(&f);
+- r = __vfwscanf(&f, fmt, ap);
++ r = __vfwscanf(&f, loc, fmt, ap);
+ free(mbstr);
+
+ return (r);
--- /dev/null
+--- vwprintf.c.orig 2003-05-20 15:22:44.000000000 -0700
++++ vwprintf.c 2005-02-23 17:05:10.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/vwprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdarg.h>
+ #include <stdio.h>
+ #include <wchar.h>
+@@ -35,5 +37,13 @@
+ vwprintf(const wchar_t * __restrict fmt, va_list ap)
+ {
+
+- return (vfwprintf(stdout, fmt, ap));
++ return (vfwprintf_l(stdout, __current_locale(), fmt, ap));
++}
++
++int
++vwprintf_l(locale_t loc, const wchar_t * __restrict fmt, va_list ap)
++{
++
++ /* no need to call NORMALIZE_LOCALE(loc) because vfwprintf_l will */
++ return (vfwprintf_l(stdout, loc, fmt, ap));
+ }
--- /dev/null
+--- vwscanf.c.orig 2003-05-20 15:22:44.000000000 -0700
++++ vwscanf.c 2005-02-23 17:06:42.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/vwscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdarg.h>
+ #include <stdio.h>
+ #include <wchar.h>
+@@ -35,5 +37,13 @@
+ vwscanf(const wchar_t * __restrict fmt, va_list ap)
+ {
+
+- return (vfwscanf(stdin, fmt, ap));
++ return (vfwscanf_l(stdin, __current_locale(), fmt, ap));
++}
++
++int
++vwscanf_l(locale_t loc, const wchar_t * __restrict fmt, va_list ap)
++{
++
++ /* no need to call NORMALIZE_LOCALE(loc) because vfwscanf_l will */
++ return (vfwscanf_l(stdin, loc, fmt, ap));
+ }
static char sccsid[] = "@(#)wbuf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/wbuf.c,v 1.10 2002/08/13 09:30:41 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/wbuf.c,v 1.11 2004/06/08 05:45:32 das Exp $");
#include <stdio.h>
#include "local.h"
* calls might wrap _w from negative to positive.
*/
fp->_w = fp->_lbfsize;
- if (cantwrite(fp))
+ if (prepwrite(fp) != 0)
return (EOF);
c = (unsigned char)c;
---- wbuf.c.orig Mon Mar 22 13:35:00 2004
-+++ wbuf.c Mon Mar 22 13:38:02 2004
+--- wbuf.c.orig 2004-06-07 22:45:32.000000000 -0700
++++ wbuf.c 2004-10-25 00:49:10.000000000 -0700
@@ -41,6 +41,7 @@
- __FBSDID("$FreeBSD: src/lib/libc/stdio/wbuf.c,v 1.10 2002/08/13 09:30:41 tjr Exp $");
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/wbuf.c,v 1.11 2004/06/08 05:45:32 das Exp $");
#include <stdio.h>
+#include <errno.h>
* calls might wrap _w from negative to positive.
*/
fp->_w = fp->_lbfsize;
-- if (cantwrite(fp))
-+ if (cantwrite(fp)) {
+- if (prepwrite(fp) != 0)
++ if (prepwrite(fp) != 0) {
+ errno = EBADF;
return (EOF);
+ }
---- wprintf.3.orig Thu Aug 21 18:19:12 2003
-+++ wprintf.3 Thu Aug 21 18:16:28 2003
-@@ -224,6 +224,20 @@
+--- wprintf.3.orig Fri Mar 11 17:09:07 2005
++++ wprintf.3 Fri Mar 11 17:03:23 2005
+@@ -87,6 +87,12 @@
+ write to the wide character string
+ .Fa ws .
+ .Pp
++Extended locale versions of these functions are documented in
++.Xr wprintf_l 3 .
++See
++.Xr xlocale 3
++for more information.
++.Pp
+ These functions write the output under the control of a
+ .Fa format
+ string that specifies how subsequent arguments
+@@ -224,6 +230,20 @@
.Xr localeconv 3 .
.El
.It
An optional decimal digit string specifying a minimum field width.
If the converted value has fewer characters than the field width, it will
be padded with spaces on the left (or right, if the left-adjustment
-@@ -314,6 +328,28 @@
+@@ -314,6 +334,28 @@
.It Sy Modifier Ta Cm c Ta Cm s
.It Cm l No (ell) Ta Vt wint_t Ta Vt "wchar_t *"
.El
.It
A character that specifies the type of conversion to be applied.
.El
+@@ -602,7 +644,8 @@
+ .Xr putwc 3 ,
+ .Xr setlocale 3 ,
+ .Xr wcsrtombs 3 ,
+-.Xr wscanf 3
++.Xr wscanf 3 ,
++.Xr wprintf_l 3
+ .Sh STANDARDS
+ Subject to the caveats noted in the
+ .Sx BUGS
--- /dev/null
+--- wprintf.c.orig 2003-05-20 15:22:45.000000000 -0700
++++ wprintf.c 2005-02-23 17:09:14.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/wprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdarg.h>
+ #include <stdio.h>
+ #include <wchar.h>
+@@ -38,7 +40,21 @@
+ va_list ap;
+
+ va_start(ap, fmt);
+- ret = vfwprintf(stdout, fmt, ap);
++ ret = vfwprintf_l(stdout, __current_locale(), fmt, ap);
++ va_end(ap);
++
++ return (ret);
++}
++
++int
++wprintf_l(locale_t loc, const wchar_t * __restrict fmt, ...)
++{
++ int ret;
++ va_list ap;
++
++ /* no need to call NORMALIZE_LOCALE(loc) because vfwprintf_l will */
++ va_start(ap, fmt);
++ ret = vfwprintf_l(stdout, loc, fmt, ap);
+ va_end(ap);
+
+ return (ret);
--- /dev/null
+--- wscanf.3.orig Fri Mar 11 17:09:15 2005
++++ wscanf.3 Fri Mar 11 16:43:04 2005
+@@ -134,6 +134,12 @@
+ when an input character does not match such a format character.
+ Scanning also stops
+ when an input conversion cannot be made (see below).
++.Pp
++Extended locale versions of these functions are documented in
++.Xr wscanf_l 3 .
++See
++.Xr xlocale 3
++for more information.
+ .Sh CONVERSIONS
+ Following the
+ .Cm %
+@@ -459,7 +465,8 @@
+ .Xr wcstod 3 ,
+ .Xr wcstol 3 ,
+ .Xr wcstoul 3 ,
+-.Xr wprintf 3
++.Xr wprintf 3 ,
++.Xr wscanf_l 3
+ .Sh STANDARDS
+ The
+ .Fn fwscanf ,
--- /dev/null
+--- wscanf.c.orig 2003-05-20 15:22:45.000000000 -0700
++++ wscanf.c 2005-02-23 17:10:53.000000000 -0800
+@@ -27,6 +27,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdio/wscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdarg.h>
+ #include <stdio.h>
+ #include <wchar.h>
+@@ -38,7 +40,21 @@
+ int r;
+
+ va_start(ap, fmt);
+- r = vfwscanf(stdin, fmt, ap);
++ r = vfwscanf_l(stdin, __current_locale(), fmt, ap);
++ va_end(ap);
++
++ return (r);
++}
++
++int
++wscanf_l(locale_t loc, const wchar_t * __restrict fmt, ...)
++{
++ va_list ap;
++ int r;
++
++ /* no need to call NORMALIZE_LOCALE(loc) because vfwscanf_l will */
++ va_start(ap, fmt);
++ r = vfwscanf_l(stdin, loc, fmt, ap);
+ va_end(ap);
+
+ return (r);
static char sccsid[] = "@(#)wsetup.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/wsetup.c,v 1.8 2002/03/22 21:53:04 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/wsetup.c,v 1.9 2004/06/08 05:44:52 das Exp $");
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "local.h"
/*
* Various output routines call wsetup to be sure it is safe to write,
* because either _flags does not include __SWR, or _buf is NULL.
- * _wsetup returns 0 if OK to write, nonzero otherwise.
+ * _wsetup returns 0 if OK to write; otherwise, it returns EOF and sets errno.
*/
int
__swsetup(fp)
* If we are not writing, we had better be reading and writing.
*/
if ((fp->_flags & __SWR) == 0) {
- if ((fp->_flags & __SRW) == 0)
+ if ((fp->_flags & __SRW) == 0) {
+ errno = EBADF;
return (EOF);
+ }
if (fp->_flags & __SRD) {
/* clobber any ungetc data */
if (HASUB(fp))
FBSDHDRS= floatio.h fvwrite.h glue.h local.h
.include "Makefile.fbsd_end"
+# also build 64-bit long double versions (ppc only)
+LDBLSRCS += asprintf.c fprintf.c fscanf.c fwprintf.c fwscanf.c printf.c \
+ scanf.c snprintf.c sprintf.c sscanf.c swprintf.c swscanf.c \
+ vasprintf.c vfprintf.c vfscanf.c vfwprintf.c vfwscanf.c \
+ vprintf.c vscanf.c vsnprintf.c vsprintf.c vsscanf.c vswprintf.c \
+ vswscanf.c vwprintf.c vwscanf.c wprintf.c wscanf.c
+
.for _src in vfprintf-fbsd.c vfwprintf-fbsd.c
CFLAGS-${_src} += -fshort-enums
+# add altivec options on per file basis, since it now disables inlining
+.if (${MACHINE_ARCH} == ppc) || (${MACHINE_ARCH} == ppc64)
+CFLAGS-${_src} += -faltivec -DALTIVEC
+.endif
.endfor
+UNIX03SRCS+= freopen.c fwrite.c
+
.if ${LIB} == "c"
+MAN3+= getwc_l.3 putwc_l.3 printf_l.3 scanf_l.3 wprintf_l.3 wscanf_l.3
+
.include "Makefile.fbsd_begin"
FBSDMAN3= fclose.3 ferror.3 fflush.3 fgetln.3 fgets.3 fgetws.3 flockfile.3 \
fopen.3 fputs.3 fputws.3 fread.3 fseek.3 funopen.3 fwide.3 getc.3 \
ferror.3 fileno.3 ferror.3 fileno_unlocked.3
MLINKS+=fflush.3 fpurge.3
MLINKS+=fgets.3 gets.3
+MLINKS+=fgetws.3 fgetws_l.3
MLINKS+=flockfile.3 ftrylockfile.3 flockfile.3 funlockfile.3
MLINKS+=fopen.3 fdopen.3 fopen.3 freopen.3
MLINKS+=fputs.3 puts.3
+MLINKS+=fputws.3 fputws_l.3
MLINKS+=fread.3 fwrite.3
MLINKS+=fseek.3 fgetpos.3 fseek.3 fseeko.3 fseek.3 fsetpos.3 fseek.3 ftell.3 \
fseek.3 ftello.3 fseek.3 rewind.3
MLINKS+=getc.3 fgetc.3 getc.3 getc_unlocked.3 getc.3 getchar.3 \
getc.3 getchar_unlocked.3 getc.3 getw.3
MLINKS+=getwc.3 fgetwc.3 getwc.3 getwchar.3
+MLINKS+=getwc_l.3 fgetwc_l.3 getwc_l.3 getwchar_l.3
MLINKS+=mktemp.3 mkdtemp.3 mktemp.3 mkstemp.3 mktemp.3 mkstemps.3
MLINKS+=printf.3 asprintf.3 printf.3 fprintf.3 \
printf.3 snprintf.3 printf.3 sprintf.3 \
printf.3 vasprintf.3 \
printf.3 vfprintf.3 printf.3 vprintf.3 printf.3 vsnprintf.3 \
printf.3 vsprintf.3
+MLINKS+=printf_l.3 asprintf_l.3 printf_l.3 fprintf_l.3 \
+ printf_l.3 snprintf_l.3 printf_l.3 sprintf_l.3 \
+ printf_l.3 vasprintf_l.3 \
+ printf_l.3 vfprintf_l.3 printf_l.3 vprintf_l.3 printf_l.3 vsnprintf_l.3 \
+ printf_l.3 vsprintf_l.3
MLINKS+=putc.3 fputc.3 putc.3 putc_unlocked.3 putc.3 putchar.3 \
putc.3 putchar_unlocked.3 putc.3 putw.3
MLINKS+=putwc.3 fputwc.3 putwc.3 putwchar.3
+MLINKS+=putwc_l.3 fputwc_l.3 putwc_l.3 putwchar_l.3
MLINKS+=scanf.3 fscanf.3 scanf.3 sscanf.3 scanf.3 vfscanf.3 scanf.3 vscanf.3 \
scanf.3 vsscanf.3
+MLINKS+=scanf_l.3 fscanf_l.3 scanf_l.3 sscanf_l.3 scanf_l.3 vfscanf_l.3 \
+ scanf_l.3 vscanf_l.3 scanf_l.3 vsscanf_l.3
MLINKS+=setbuf.3 setbuffer.3 setbuf.3 setlinebuf.3 setbuf.3 setvbuf.3
MLINKS+=tmpnam.3 tempnam.3 tmpnam.3 tmpfile.3
+MLINKS+=ungetwc.3 ungetwc_l.3
MLINKS+=wprintf.3 fwprintf.3 wprintf.3 swprintf.3 \
wprintf.3 vwprintf.3 wprintf.3 vfwprintf.3 wprintf.3 vswprintf.3
+MLINKS+=wprintf_l.3 fwprintf_l.3 wprintf_l.3 swprintf_l.3 \
+ wprintf_l.3 vwprintf_l.3 wprintf_l.3 vfwprintf_l.3 \
+ wprintf_l.3 vswprintf_l.3
MLINKS+=wscanf.3 fwscanf.3 wscanf.3 swscanf.3 wscanf.3 vwscanf.3 \
wscanf.3 vswscanf.3 wscanf.3 vfwscanf.3
+MLINKS+=wscanf_l.3 fwscanf_l.3 wscanf_l.3 swscanf_l.3 wscanf_l.3 vwscanf_l.3 \
+ wscanf_l.3 vswscanf_l.3 wscanf_l.3 vfwscanf_l.3
.endif
--- /dev/null
+.\" $NetBSD: getwc.3,v 1.3 2002/02/07 07:00:26 ross Exp $
+.\"
+.\" Copyright (c) 1990, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Chris Torek and the American National Standards Committee X3,
+.\" on Information Processing Systems.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" @(#)getc.3 8.1 (Berkeley) 6/4/93
+.\" $FreeBSD: src/lib/libc/stdio/getwc.3,v 1.6 2004/03/16 13:30:11 tjr Exp $
+.\"
+.Dd March 11, 2005
+.Dt GETWC_L 3
+.Os
+.Sh NAME
+.Nm fgetwc_l ,
+.Nm getwc_l ,
+.Nm getwchar_l
+.Nd get next wide character from input stream
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdio.h
+.In wchar.h
+.In xlocale.h
+.Ft wint_t
+.Fn fgetwc_l "FILE *stream" "locale_t loc"
+.Ft wint_t
+.Fn getwc_l "FILE *stream" "locale_t loc"
+.Ft wint_t
+.Fn getwchar_l "locale_t loc"
+.Sh DESCRIPTION
+The
+.Fn fgetwc_l ,
+.Fn getwc_l ,
+and
+.Fn getwchar_l
+functions are extended locale versions of the
+.Fn fgetwc ,
+.Fn getwc ,
+and
+.Fn getwchar
+functions, respectively.
+Refer to their manual pages for details.
+Also, see
+.Xr xlocale 3 for more information about extended locales.
+.Sh SEE ALSO
+.Xr getwc 3 ,
+.Xr xlocale 3
--- /dev/null
+.\" Copyright (c) 1990, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Chris Torek and the American National Standards Committee X3,
+.\" on Information Processing Systems.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" @(#)printf.3 8.1 (Berkeley) 6/4/93
+.\" $FreeBSD: src/lib/libc/stdio/printf.3,v 1.58 2004/10/16 16:00:01 stefanf Exp $
+.\"
+.Dd March 11, 2005
+.Dt PRINTF_L 3
+.Os
+.Sh NAME
+.Nm printf_l , fprintf_l , sprintf_l , snprintf_l , asprintf_l ,
+.Nm vprintf_l , vfprintf_l , vsprintf_l , vsnprintf_l , vasprintf_l
+.Nd formatted output conversion
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdio.h
+.In xlocale.h
+.Ft int
+.Fn printf_l "locale_t loc" "const char * restrict format" ...
+.Ft int
+.Fn fprintf_l "FILE * restrict stream" "locale_t loc" "const char * restrict format" ...
+.Ft int
+.Fn sprintf_l "char * restrict str" "locale_t loc" "const char * restrict format" ...
+.Ft int
+.Fn snprintf_l "char * restrict str" "size_t size" "locale_t loc" "const char * restrict format" ...
+.Ft int
+.Fn asprintf_l "char **ret" "locale_t loc" "const char *format" ...
+.In stdarg.h
+.Ft int
+.Fn vprintf_l "locale_t loc" "const char * restrict format" "va_list ap"
+.Ft int
+.Fn vfprintf_l "FILE * restrict stream" "locale_t loc" "const char * restrict format" "va_list ap"
+.Ft int
+.Fn vsprintf_l "char * restrict str" "locale_t loc" "const char * restrict format" "va_list ap"
+.Ft int
+.Fn vsnprintf_l "char * restrict str" "size_t size" "locale_t loc" "const char * restrict format" "va_list ap"
+.Ft int
+.Fn vasprintf_l "char **ret" "locale_t loc" "const char *format" "va_list ap"
+.Sh DESCRIPTION
+The
+.Fn printf_l ,
+.Fn fprintf_l ,
+.Fn sprintf_l ,
+.Fn snprintf_l ,
+.Fn asprintf_l ,
+.Fn vprintf_l ,
+.Fn vfprintf_l ,
+.Fn vsprintf_l ,
+.Fn vsnprintf_l ,
+and
+.Fn vasprintf_l
+functions are extended locale versions of the
+.Fn printf ,
+.Fn fprintf ,
+.Fn sprintf ,
+.Fn snprintf ,
+.Fn asprintf ,
+.Fn vprintf ,
+.Fn vfprintf ,
+.Fn vsprintf ,
+.Fn vsnprintf ,
+and
+.Fn vasprintf
+functions, respectively.
+Refer to their manual pages for details.
+Also, see
+.Xr xlocale 3 for more information about extended locales.
+.Sh SEE ALSO
+.Xr printf 3 ,
+.Xr xlocale 3
--- /dev/null
+.\" $NetBSD: putwc.3,v 1.2 2002/02/07 07:00:26 ross Exp $
+.\"
+.\" Copyright (c) 1990, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Chris Torek and the American National Standards Committee X3,
+.\" on Information Processing Systems.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" @(#)putc.3 8.1 (Berkeley) 6/4/93
+.\" $FreeBSD: src/lib/libc/stdio/putwc.3,v 1.7 2004/03/16 13:30:11 tjr Exp $
+.\"
+.Dd March 11, 2005
+.Dt PUTWC_L 3
+.Os
+.Sh NAME
+.Nm fputwc_l ,
+.Nm putwc_l ,
+.Nm putwchar_l
+.Nd output a wide character to a stream
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdio.h
+.In wchar.h
+.In xlocale.h
+.Ft wint_t
+.Fn fputwc_l "wchar_t wc" "FILE *stream" "locale_t loc"
+.Ft wint_t
+.Fn putwc_l "wchar_t wc" "FILE *stream" "locale_t loc"
+.Ft wint_t
+.Fn putwchar_l "wchar_t wc" "locale_t loc"
+.Sh DESCRIPTION
+The
+.Fn fputwc_l ,
+.Fn putwc_l ,
+and
+.Fn putwchar_l
+functions are extended locale versions of the
+.Fn fputwc ,
+.Fn putwc ,
+and
+.Fn putwchar
+functions, respectively.
+Refer to their manual pages for details.
+Also, see
+.Xr xlocale 3 for more information about extended locales.
+.Sh SEE ALSO
+.Xr putwc 3 ,
+.Xr xlocale 3
--- /dev/null
+.\" Copyright (c) 1990, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Chris Torek and the American National Standards Committee X3,
+.\" on Information Processing Systems.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" @(#)scanf.3 8.2 (Berkeley) 12/11/93
+.\" $FreeBSD: src/lib/libc/stdio/scanf.3,v 1.24 2003/06/28 09:03:25 das Exp $
+.\"
+.Dd March 11, 2005
+.Dt SCANF_L 3
+.Os
+.Sh NAME
+.Nm scanf_l ,
+.Nm fscanf_l ,
+.Nm sscanf_l ,
+.Nm vscanf_l ,
+.Nm vsscanf_l ,
+.Nm vfscanf_l
+.Nd input format conversion
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdio.h
+.In xlocale.h
+.Ft int
+.Fn scanf_l "locale_t loc" "const char * restrict format" ...
+.Ft int
+.Fn fscanf_l "FILE * restrict stream" "locale_t loc" "const char * restrict format" ...
+.Ft int
+.Fn sscanf_l "const char * restrict str" "locale_t loc" "const char * restrict format" ...
+.In stdarg.h
+.Ft int
+.Fn vscanf_l "locale_t loc" "const char * restrict format" "va_list ap"
+.Ft int
+.Fn vsscanf_l "const char * restrict str" "locale_t loc" "const char * restrict format" "va_list ap"
+.Ft int
+.Fn vfscanf_l "FILE * restrict stream" "locale_t loc" "const char * restrict format" "va_list ap"
+.Sh DESCRIPTION
+The
+.Fn scanf_l ,
+.Fn fscanf_l ,
+.Fn sscanf_l ,
+.Fn vscanf_l ,
+.Fn vsscanf_l ,
+and
+.Fn vfscanf_l
+functions are extended locale versions of the
+.Fn scanf ,
+.Fn fscanf ,
+.Fn sscanf ,
+.Fn vscanf ,
+.Fn vsscanf ,
+and
+.Fn vfscanf
+functions, respectively.
+Refer to their manual pages for details.
+Also, see
+.Xr xlocale 3 for more information about extended locales.
+.Sh SEE ALSO
+.Xr scanf 3 ,
+.Xr xlocale 3
--- /dev/null
+.\" Copyright (c) 1990, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Chris Torek and the American National Standards Committee X3,
+.\" on Information Processing Systems.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" @(#)printf.3 8.1 (Berkeley) 6/4/93
+.\" FreeBSD: src/lib/libc/stdio/printf.3,v 1.47 2002/09/06 11:23:55 tjr Exp
+.\" $FreeBSD: src/lib/libc/stdio/wprintf.3,v 1.5 2003/07/05 07:55:34 tjr Exp $
+.\"
+.Dd March 11, 2005
+.Dt WPRINTF_L 3
+.Os
+.Sh NAME
+.Nm wprintf_l , fwprintf_l , swprintf_l ,
+.Nm vwprintf_l , vfwprintf_l , vswprintf_l
+.Nd formatted wide character output conversion
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdio.h
+.In wchar.h
+.In xlocale.h
+.Ft int
+.Fn fwprintf_l "FILE * restrict stream" "locale_t loc" "const wchar_t * restrict format" ...
+.Ft int
+.Fn swprintf_l "wchar_t * restrict ws" "size_t n" "locale_t loc" "const wchar_t * restrict format" ...
+.Ft int
+.Fn wprintf_l "locale_t loc" "const wchar_t * restrict format" ...
+.In stdarg.h
+.Ft int
+.Fn vfwprintf_l "FILE * restrict stream" "locale_t loc" "const wchar_t * restrict" "va_list ap"
+.Ft int
+.Fn vswprintf_l "wchar_t * restrict ws" "size_t n" "locale_t loc" "const wchar_t *restrict format" "va_list ap"
+.Ft int
+.Fn vwprintf_l "locale_t loc" "const wchar_t * restrict format" "va_list ap"
+.Sh DESCRIPTION
+The
+.Fn wprintf_l ,
+.Fn fwprintf_l ,
+.Fn swprintf_l ,
+.Fn vwprintf_l ,
+.Fn vfwprintf_l ,
+and
+.Fn vswprintf_l
+functions are extended locale versions of the
+.Fn wprintf ,
+.Fn fwprintf ,
+.Fn swprintf ,
+.Fn vwprintf ,
+.Fn vfwprintf ,
+and
+.Fn vswprintf
+functions, respectively.
+Refer to their manual pages for details.
+Also, see
+.Xr xlocale 3 for more information about extended locales.
+.Sh SEE ALSO
+.Xr wprintf 3 ,
+.Xr xlocale 3
--- /dev/null
+.\" Copyright (c) 1990, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Chris Torek and the American National Standards Committee X3,
+.\" on Information Processing Systems.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" @(#)scanf.3 8.2 (Berkeley) 12/11/93
+.\" FreeBSD: src/lib/libc/stdio/scanf.3,v 1.24 2003/06/28 09:03:25 das Exp
+.\" $FreeBSD: src/lib/libc/stdio/wscanf.3,v 1.6 2003/07/05 07:47:55 tjr Exp $
+.\"
+.Dd March 11, 2005
+.Dt WSCANF_L 3
+.Os
+.Sh NAME
+.Nm wscanf_l ,
+.Nm fwscanf_l ,
+.Nm swscanf_l ,
+.Nm vwscanf_l ,
+.Nm vswscanf_l ,
+.Nm vfwscanf_l
+.Nd wide character input format conversion
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdio.h
+.In wchar.h
+.In xlocale.h
+.Ft int
+.Fn wscanf_l "locale_t loc" "const wchar_t * restrict format" ...
+.Ft int
+.Fn fwscanf_l "FILE * restrict stream" "locale_t loc" "const wchar_t * restrict format" ...
+.Ft int
+.Fn swscanf_l "const wchar_t * restrict str" "locale_t loc" "const wchar_t * restrict format" ...
+.In stdarg.h
+.Ft int
+.Fn vwscanf_l "locale_t loc" "const wchar_t * restrict format" "va_list ap"
+.Ft int
+.Fn vswscanf_l "const wchar_t * restrict str" "locale_t loc" "const wchar_t * restrict format" "va_list ap"
+.Ft int
+.Fn vfwscanf_l "FILE * restrict stream" "locale_t loc" "const wchar_t * restrict format" "va_list ap"
+.Sh DESCRIPTION
+The
+.Fn wscanf_l ,
+.Fn fwscanf_l ,
+.Fn swscanf_l ,
+.Fn vwscanf_l ,
+.Fn vswscanf_l ,
+and
+.Fn vfwscanf_l
+functions are extended locale versions of the
+.Fn wscanf ,
+.Fn fwscanf ,
+.Fn swscanf ,
+.Fn vwscanf ,
+.Fn vswscanf ,
+and
+.Fn vfwscanf
+functions, respectively.
+Refer to their manual pages for details.
+Also, see
+.Xr xlocale 3 for more information about extended locales.
+.Sh SEE ALSO
+.Xr wscanf 3 ,
+.Xr xlocale 3
static char sccsid[] = "@(#)abort.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdlib/abort.c,v 1.8 2002/07/10 16:35:02 wollman Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdlib/abort.c,v 1.9 2003/08/16 11:43:57 davidxu Exp $");
+#include "namespace.h"
#include <signal.h>
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
#include <pthread.h>
+#include "un-namespace.h"
void (*__cleanup)();
-/* XXX - why are these declarations here? */
-extern int __sys_sigprocmask(int, const sigset_t *, sigset_t *);
-extern int __sys_sigaction(int, const struct sigaction *,
- struct sigaction *);
-
void
abort()
{
* any errors -- ISO C doesn't allow abort to return anyway.
*/
sigdelset(&act.sa_mask, SIGABRT);
- (void)__sys_sigprocmask(SIG_SETMASK, &act.sa_mask, NULL);
- (void)kill(getpid(), SIGABRT);
+ (void)_sigprocmask(SIG_SETMASK, &act.sa_mask, NULL);
+ (void)raise(SIGABRT);
/*
* If SIGABRT was ignored, or caught and the handler returns, do
act.sa_handler = SIG_DFL;
act.sa_flags = 0;
sigfillset(&act.sa_mask);
- (void)__sys_sigaction(SIGABRT, &act, NULL);
+ (void)_sigaction(SIGABRT, &act, NULL);
sigdelset(&act.sa_mask, SIGABRT);
- (void)__sys_sigprocmask(SIG_SETMASK, &act.sa_mask, NULL);
- (void)kill(getpid(), SIGABRT);
+ (void)_sigprocmask(SIG_SETMASK, &act.sa_mask, NULL);
+ (void)raise(SIGABRT);
exit(1);
}
---- abort.c.orig Mon Apr 28 16:37:26 2003
-+++ abort.c Sat May 3 14:27:55 2003
-@@ -43,12 +43,9 @@
- #include <unistd.h>
+--- abort.c.orig 2003-08-16 04:43:57.000000000 -0700
++++ abort.c 2004-10-26 17:29:31.000000000 -0700
+@@ -45,7 +45,7 @@
#include <pthread.h>
+ #include "un-namespace.h"
-void (*__cleanup)();
--
--/* XXX - why are these declarations here? */
--extern int __sys_sigprocmask(int, const sigset_t *, sigset_t *);
--extern int __sys_sigaction(int, const struct sigaction *,
-- struct sigaction *);
+extern void (*__cleanup)();
-+#define __sys_sigprocmask sigprocmask
-+#define __sys_sigaction sigaction
void
abort()
.\" SUCH DAMAGE.
.\"
.\" @(#)alloca.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/stdlib/alloca.3,v 1.8 2001/09/07 14:46:35 asmodai Exp $
+.\" $FreeBSD: src/lib/libc/stdlib/alloca.3,v 1.11 2003/06/28 22:12:30 ru Exp $
.\"
.Dd June 4, 1993
.Dt ALLOCA 3
.Xr getpagesize 3 ,
.Xr malloc 3 ,
.Xr realloc 3
-.Sh BUGS
+.Sh HISTORY
The
.Fn alloca
-function
-is machine dependent; its use is discouraged.
-.\" .Sh HISTORY
-.\" The
-.\" .Fn alloca
-.\" function appeared in
+function appeared in
+.At 32v .
.\" .Bx ?? .
.\" The function appeared in 32v, pwb and pwb.2 and in 3bsd 4bsd
.\" The first man page (or link to a man page that I can find at the
.\" moment is 4.3...
+.Sh BUGS
+The
+.Fn alloca
+function
+is machine and compiler dependent;
+its use is discouraged.
---- alloca.3.orig Mon Apr 28 16:37:26 2003
-+++ alloca.3 Mon May 19 14:22:55 2003
+--- /Volumes/XDisk/tmp/Libc/stdlib/FreeBSD/alloca.3.orig 2003-06-28 15:12:30.000000000 -0700
++++ /Volumes/XDisk/tmp/Libc/stdlib/FreeBSD/alloca.3 2004-10-24 17:08:31.000000000 -0700
@@ -41,6 +41,9 @@
.Sh LIBRARY
.Lb libc
---- atexit.c.orig Thu Mar 11 13:16:53 2004
-+++ atexit.c Mon Mar 15 12:47:39 2004
+--- atexit.c.orig 2004-03-11 13:16:53.000000000 -0800
++++ atexit.c 2004-09-15 00:14:26.000000000 -0700
@@ -45,6 +45,9 @@
#include <stdlib.h>
#include <unistd.h>
error = atexit_register(&fn);
return (error);
+@@ -156,7 +163,7 @@
+ * handlers are called.
+ */
+ void
+-__cxa_finalize(void *dso)
++__cxa_finalize(const void *dso)
+ {
+ struct atexit *p;
+ struct atexit_fn fn;
--- /dev/null
+--- atexit.h.orig 2004-03-11 13:16:53.000000000 -0800
++++ atexit.h 2004-09-15 00:15:16.000000000 -0700
+@@ -37,4 +37,4 @@
+ /* must be at least 32 to guarantee ANSI conformance */
+ #define ATEXIT_SIZE 32
+
+-void __cxa_finalize(void *dso);
++void __cxa_finalize(const void *dso);
--- /dev/null
+--- atof.3.orig Fri Mar 11 10:10:58 2005
++++ atof.3 Fri Mar 11 10:12:33 2005
+@@ -40,7 +40,8 @@
+ .Dt ATOF 3
+ .Os
+ .Sh NAME
+-.Nm atof
++.Nm atof ,
++.Nm atof_l
+ .Nd convert
+ .Tn ASCII
+ string to double
+@@ -50,6 +51,9 @@
+ .In stdlib.h
+ .Ft double
+ .Fn atof "const char *nptr"
++.In xlocale.h
++.Ft double
++.Fn atof_l "const char *nptr" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn atof
+@@ -67,6 +71,14 @@
+ The decimal point
+ character is defined in the program's locale (category
+ .Dv LC_NUMERIC ) .
++.Pp
++While the
++.Fn atof
++function uses the current locale, the
++.Fn atof_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh IMPLEMENTATION NOTES
+ The
+ .Fn atof
+@@ -88,7 +100,8 @@
+ .Xr atol 3 ,
+ .Xr strtod 3 ,
+ .Xr strtol 3 ,
+-.Xr strtoul 3
++.Xr strtoul 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn atof
* 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.
- *
- * $FreeBSD: src/lib/libc/stdlib/atof.c,v 1.4 2002/03/22 21:53:09 obrien Exp $
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)atof.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdlib/atof.c,v 1.4 2002/03/22 21:53:09 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdlib/atof.c,v 1.5 2004/02/10 20:42:32 cperciva Exp $");
#include <stdlib.h>
--- /dev/null
+--- atof.c.orig 2004-11-25 11:38:41.000000000 -0800
++++ atof.c 2005-02-23 18:31:38.000000000 -0800
+@@ -37,11 +37,22 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdlib/atof.c,v 1.5 2004/02/10 20:42:32 cperciva Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdlib.h>
+
+ double
+ atof(ascii)
+ const char *ascii;
+ {
+- return strtod(ascii, (char **)NULL);
++ return strtod_l(ascii, (char **)NULL, __current_locale());
++}
++
++double
++atof_l(ascii, loc)
++ const char *ascii;
++ locale_t loc;
++{
++ /* no need to call NORMALIZE_LOCALE(loc) because strtod_l will */
++ return strtod_l(ascii, (char **)NULL, loc);
+ }
--- /dev/null
+--- atoi.3.orig Fri Mar 11 10:13:22 2005
++++ atoi.3 Fri Mar 11 10:14:49 2005
+@@ -40,7 +40,8 @@
+ .Dt ATOI 3
+ .Os
+ .Sh NAME
+-.Nm atoi
++.Nm atoi ,
++.Nm atoi_l
+ .Nd convert
+ .Tn ASCII
+ string to integer
+@@ -50,6 +51,9 @@
+ .In stdlib.h
+ .Ft int
+ .Fn atoi "const char *nptr"
++.In xlocale.h
++.Ft int
++.Fn atoi_l "const char *nptr" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn atoi
+@@ -63,6 +67,14 @@
+ .Bd -literal -offset indent
+ (int)strtol(nptr, (char **)NULL, 10);
+ .Ed
++.Pp
++While the
++.Fn atoi
++function uses the current locale, the
++.Fn atoi_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh IMPLEMENTATION NOTES
+ The
+ .Fn atoi
+@@ -84,7 +96,8 @@
+ .Xr atol 3 ,
+ .Xr strtod 3 ,
+ .Xr strtol 3 ,
+-.Xr strtoul 3
++.Xr strtoul 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn atoi
--- /dev/null
+--- atoi.c.orig 2003-05-20 15:23:24.000000000 -0700
++++ atoi.c 2005-02-23 18:32:57.000000000 -0800
+@@ -37,11 +37,22 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdlib/atoi.c,v 1.5 2002/03/22 21:53:09 obrien Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdlib.h>
+
+ int
+ atoi(str)
+ const char *str;
+ {
+- return (int)strtol(str, (char **)NULL, 10);
++ return (int)strtol_l(str, (char **)NULL, 10, __current_locale());
++}
++
++int
++atoi_l(str, loc)
++ const char *str;
++ locale_t loc;
++{
++ /* no need to call NORMALIZE_LOCALE(loc) because strtol_l will */
++ return (int)strtol_l(str, (char **)NULL, 10, loc);
+ }
--- /dev/null
+--- atol.3.orig Fri Mar 11 10:15:17 2005
++++ atol.3 Fri Mar 11 10:53:10 2005
+@@ -40,7 +40,8 @@
+ .Dt ATOL 3
+ .Os
+ .Sh NAME
+-.Nm atol , atoll
++.Nm atol , atoll ,
++.Nm atol_l , atoll_l
+ .Nd convert
+ .Tn ASCII
+ string to
+@@ -56,6 +57,11 @@
+ .Fn atol "const char *nptr"
+ .Ft "long long"
+ .Fn atoll "const char *nptr"
++.In xlocale.h
++.Ft long
++.Fn atol_l "const char *nptr" "locale_t loc"
++.Ft "long long"
++.Fn atoll_l "const char *nptr" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn atol
+@@ -82,6 +88,18 @@
+ It is equivalent to:
+ .Pp
+ .Dl "strtoll(nptr, (char **)NULL, 10);"
++.Pp
++While the
++.Fn atol
++and
++.Fn atoll
++functions use the current locale, the
++.Fn atol_l
++and
++.Fn atoll_l
++functions may be passed locales directly. See
++.Xr xlocale 3
++for more information.
+ .Sh ERRORS
+ The functions
+ .Fn atol
+@@ -96,7 +114,8 @@
+ .Xr atoi 3 ,
+ .Xr strtod 3 ,
+ .Xr strtol 3 ,
+-.Xr strtoul 3
++.Xr strtoul 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn atol
--- /dev/null
+--- atol.c.orig 2003-05-20 15:23:24.000000000 -0700
++++ atol.c 2005-02-23 18:33:54.000000000 -0800
+@@ -37,11 +37,22 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdlib/atol.c,v 1.4 2002/03/22 21:53:09 obrien Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdlib.h>
+
+ long
+ atol(str)
+ const char *str;
+ {
+- return strtol(str, (char **)NULL, 10);
++ return strtol_l(str, (char **)NULL, 10, __current_locale());
++}
++
++long
++atol_l(str, loc)
++ const char *str;
++ locale_t loc;
++{
++ /* no need to call NORMALIZE_LOCALE(loc) because strtol_l will */
++ return strtol_l(str, (char **)NULL, 10, loc);
+ }
--- /dev/null
+--- atoll.c.orig 2003-05-20 15:23:24.000000000 -0700
++++ atoll.c 2005-02-23 18:35:02.000000000 -0800
+@@ -34,11 +34,22 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdlib/atoll.c,v 1.4 2002/03/22 21:53:10 obrien Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdlib.h>
+
+ long long
+ atoll(str)
+ const char *str;
+ {
+- return strtoll(str, (char **)NULL, 10);
++ return strtoll_l(str, (char **)NULL, 10, __current_locale());
++}
++
++long long
++atoll_l(str, loc)
++ const char *str;
++ locale_t loc;
++{
++ /* no need to call NORMALIZE_LOCALE(loc) because strtoll_l will */
++ return strtoll_l(str, (char **)NULL, 10, loc);
+ }
.\" SUCH DAMAGE.
.\"
.\" @(#)exit.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/stdlib/exit.3,v 1.13 2002/12/13 16:53:50 ru Exp $
+.\" $FreeBSD: src/lib/libc/stdlib/exit.3,v 1.15 2004/07/04 20:55:48 ru Exp $
.\"
.Dd September 9, 2002
.Dt EXIT 3
.Fa status .
Cooperating processes may use other values;
in a program which might be called by a mail transfer agent, the
-the values described in
+values described in
.Xr sysexits 3
may be used to provide more information to the parent process.
.Pp
functions
never return.
.Sh SEE ALSO
-.Xr wait 2 ,
.Xr _exit 2 ,
+.Xr wait 2 ,
.Xr atexit 3 ,
.Xr intro 3 ,
.Xr sysexits 3 ,
.\" SUCH DAMAGE.
.\"
.\" @(#)getenv.3 8.2 (Berkeley) 12/11/93
-.\" $FreeBSD: src/lib/libc/stdlib/getenv.3,v 1.13 2002/12/18 13:33:03 ru Exp $
+.\" $FreeBSD: src/lib/libc/stdlib/getenv.3,v 1.16 2004/07/07 19:57:13 ru Exp $
.\"
.Dd December 11, 1993
.Dt GETENV 3
.Fn getenv
function obtains the current value of the environment variable,
.Fa name .
-If the variable
-.Fa name
-is not in the current environment,
-a null pointer is returned.
.Pp
The
.Fn setenv
.Fa name
from the list.
.Sh RETURN VALUES
+The
+.Fn getenv
+function returns the value of the environment variable as a
+.Dv NUL Ns
+-terminated string.
+If the variable
+.Fa name
+is not in the current environment,
+.Dv NULL
+is returned.
+.Pp
.Rv -std setenv putenv
.Sh ERRORS
.Bl -tag -width Er
.Fa value
to the same
.Fa name
-will result in a memory leak. The
+will result in a memory leak.
+The
.Fx
semantics for these functions
(namely, that the contents of
.Fa value
are copied and that old values remain accessible indefinitely) make this
-bug unavoidable. Future versions may eliminate one or both of these
+bug unavoidable.
+Future versions may eliminate one or both of these
semantic guarantees in order to fix the bug.
.Sh HISTORY
The functions
---- getenv.c.orig Mon Apr 28 16:37:26 2003
-+++ getenv.c Sat May 3 14:29:07 2003
-@@ -40,6 +40,7 @@
+--- getenv.c.orig 2004-12-01 20:08:48.000000000 -0800
++++ getenv.c 2004-12-01 20:10:20.000000000 -0800
+@@ -40,8 +40,9 @@
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
+#include <crt_externs.h>
- inline char *__findenv(const char *, int *);
+-inline char *__findenv(const char *, int *);
++inline char *__findenv(const char *, int *) __attribute__((always_inline));
+ /*
+ * __findenv --
@@ -57,7 +58,7 @@
const char *name;
int *offset;
+.\" $NetBSD: getopt.3,v 1.31 2003/09/23 10:26:54 wiz Exp $
+.\"
.\" Copyright (c) 1988, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" SUCH DAMAGE.
.\"
.\" @(#)getopt.3 8.5 (Berkeley) 4/27/95
-.\" $FreeBSD: src/lib/libc/stdlib/getopt.3,v 1.21 2002/12/04 18:57:45 ru Exp $
+.\" $FreeBSD: src/lib/libc/stdlib/getopt.3,v 1.25 2004/07/31 01:00:50 imp Exp $
.\"
.Dd April 27, 1995
.Dt GETOPT 3
.Sh SYNOPSIS
.In unistd.h
.Vt extern char *optarg ;
-.Vt extern int optind ;
-.Vt extern int optopt ;
-.Vt extern int opterr ;
-.Vt extern int optreset ;
+.Vt extern int optind ;
+.Vt extern int optopt ;
+.Vt extern int opterr ;
+.Vt extern int optreset ;
.Ft int
-.Fn getopt "int argc" "char * const *argv" "const char *optstring"
+.Fn getopt "int argc" "char * const argv[]" "const char *optstring"
.Sh DESCRIPTION
The
.Fn getopt
option character returned by
.Fn getopt .
.Pp
-The variable
+The variables
.Va opterr
and
.Va optind
.Pp
The
.Fn getopt
-function
-returns \-1
-when the argument list is exhausted, or
-.Ql ?\&
-if a non-recognized
-option is encountered.
+function returns \-1 when the argument list is exhausted.
The interpretation of options in the argument list may be cancelled
by the option
.Ql --
argument),
.Fn getopt
returns \-1.
+.Sh RETURN VALUES
+The
+.Fn getopt
+function returns the next known option character in
+.Fa optstring .
+If
+.Fn getopt
+encounters a character not found in
+.Fa optstring
+or if it detects a missing option argument,
+it returns
+.Ql \&?
+(question mark).
+If
+.Fa optstring
+has a leading
+.Ql \&:
+then a missing option argument causes
+.Ql \&:
+to be returned instead of
+.Ql \&? .
+In either case, the variable
+.Va optopt
+is set to the character that caused the error.
+The
+.Fn getopt
+function returns \-1 when the argument list is exhausted.
+.Sh EXAMPLES
+.Bd -literal -compact
+#include <unistd.h>
+int bflag, ch, fd;
+
+bflag = 0;
+while ((ch = getopt(argc, argv, "bf:")) != -1) {
+ switch (ch) {
+ case 'b':
+ bflag = 1;
+ break;
+ case 'f':
+ if ((fd = open(optarg, O_RDONLY, 0)) \*[Lt] 0) {
+ (void)fprintf(stderr,
+ "myname: %s: %s\en", optarg, strerror(errno));
+ exit(1);
+ }
+ break;
+ case '?':
+ default:
+ usage();
+ }
+}
+argc -= optind;
+argv += optind;
+.Ed
.Sh DIAGNOSTICS
If the
.Fn getopt
function encounters a character not found in the string
-.Va optstring
+.Fa optstring
or detects
a missing option argument it writes an error message to the
.Dv stderr
and returns
-.Ql ?\& .
+.Ql \&? .
Setting
.Va opterr
to a zero will disable these error messages.
If
-.Va optstring
+.Fa optstring
has a leading
.Ql \&:
then a missing option argument causes a
.Pp
Option arguments are allowed to begin with
.Dq Li \- ;
-this is reasonable but
-reduces the amount of error checking possible.
-.Sh EXTENSIONS
+this is reasonable but reduces the amount of error checking possible.
+.Sh SEE ALSO
+.Xr getopt 1 ,
+.Xr getopt_long 3 ,
+.Xr getsubopt 3
+.Sh STANDARDS
The
.Va optreset
variable was added to make it possible to call the
This is an extension to the
.St -p1003.2
specification.
-.Sh EXAMPLES
-.Bd -literal -compact
-int bflag, ch, fd;
-
-bflag = 0;
-while ((ch = getopt(argc, argv, "bf:")) != -1)
- switch (ch) {
- case 'b':
- bflag = 1;
- break;
- case 'f':
- if ((fd = open(optarg, O_RDONLY, 0)) < 0)
- err(1, "%s", optarg);
- break;
- case '?':
- default:
- usage();
- }
-argc -= optind;
-argv += optind;
-.Ed
.Sh HISTORY
The
.Fn getopt
to decouple
.Fn getopt
from
-.Pa <stdio.h> .
+.In stdio.h .
.Pp
A single dash
.Dq Li -
This practice is wrong, and should not be used in any current development.
It is provided for backward compatibility
.Em only .
+Care should be taken not to use
+.Ql \&-
+as the first character in
+.Fa optstring
+to avoid a semantic conflict with
+.Tn GNU
+.Fn getopt ,
+which assigns different meaning to an
+.Fa optstring
+that begins with a
+.Ql \&- .
By default, a single dash causes
.Fn getopt
to return \-1.
-This is, we believe, compatible with System V.
.Pp
It is also possible to handle digits as option letters.
This allows
This practice is wrong, and should not be used in any current development.
It is provided for backward compatibility
.Em only .
-The following code fragment works in most (but not all) cases.
+The following code fragment works in most cases.
.Bd -literal -offset indent
-int length;
+int ch;
+long length;
char *p, *ep;
while ((ch = getopt(argc, argv, "0123456789")) != -1)
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
p = argv[optind - 1];
- if (p[0] == '-' && p[1] == ch && !p[2])
- length = strtol(++p, &ep, 10);
- else if (argv[optind] && argv[optind][1] == ch) {
+ if (p[0] == '-' \*[Am]\*[Am] p[1] == ch \*[Am]\*[Am] !p[2]) {
+ length = ch - '0';
+ ep = "";
+ } else if (argv[optind] \*[Am]\*[Am] argv[optind][1] == ch) {
length = strtol((p = argv[optind] + 1),
- &ep, 10);
+ \*[Am]ep, 10);
optind++;
optreset = 1;
} else
usage();
- if (*ep != '\0')
+ if (*ep != '\e0')
errx(EX_USAGE, "illegal number -- %s", p);
break;
}
+/* $NetBSD: getopt.c,v 1.26 2003/08/07 16:43:40 agc Exp $ */
+
/*
* Copyright (c) 1987, 1993, 1994
* The Regents of the University of California. All rights reserved.
static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdlib/getopt.c,v 1.6 2002/03/29 22:43:42 markm Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdlib/getopt.c,v 1.7 2004/03/06 17:05:45 ache Exp $");
#include "namespace.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include "un-namespace.h"
#include "libc_private.h"
int
getopt(nargc, nargv, ostr)
int nargc;
- char * const *nargv;
+ char * const nargv[];
const char *ostr;
{
static char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */
- if (optreset || !*place) { /* update scanning pointer */
+ if (optreset || *place == 0) { /* update scanning pointer */
optreset = 0;
- if (optind >= nargc || *(place = nargv[optind]) != '-') {
+ place = nargv[optind];
+ if (optind >= nargc || *place++ != '-') {
+ /* Argument is absent or is not an option */
place = EMSG;
return (-1);
}
- if (place[1] && *++place == '-') { /* found "--" */
+ optopt = *place++;
+ if (optopt == '-' && *place == 0) {
+ /* "--" => end of options */
++optind;
place = EMSG;
return (-1);
}
- } /* option letter okay? */
- if ((optopt = (int)*place++) == (int)':' ||
- !(oli = strchr(ostr, optopt))) {
- /*
- * if the user didn't specify '-' as an option,
- * assume it means -1.
- */
- if (optopt == (int)'-')
- return (-1);
- if (!*place)
+ if (optopt == 0) {
+ /* Solitary '-', treat as a '-' option
+ if the program (eg su) is looking for it. */
+ place = EMSG;
+ if (strchr(ostr, '-') == NULL)
+ return (-1);
+ optopt = '-';
+ }
+ } else
+ optopt = *place++;
+
+ /* See if option letter is one the caller wanted... */
+ if (optopt == ':' || (oli = strchr(ostr, optopt)) == NULL) {
+ if (*place == 0)
++optind;
- if (opterr && *ostr != ':' && optopt != BADCH)
- (void)fprintf(stderr, "%s: illegal option -- %c\n",
- _getprogname(), optopt);
+ if (opterr && *ostr != ':')
+ (void)fprintf(stderr,
+ "%s: illegal option -- %c\n", _getprogname(),
+ optopt);
return (BADCH);
}
- if (*++oli != ':') { /* don't need argument */
+
+ /* Does this option need an argument? */
+ if (oli[1] != ':') {
+ /* don't need argument */
optarg = NULL;
- if (!*place)
+ if (*place == 0)
++optind;
- }
- else { /* need an argument */
- if (*place) /* no white space */
+ } else {
+ /* Option-argument is either the rest of this argument or the
+ entire next argument. */
+ if (*place)
optarg = place;
- else if (nargc <= ++optind) { /* no arg */
+ else if (nargc > ++optind)
+ optarg = nargv[optind];
+ else {
+ /* option-argument absent */
place = EMSG;
if (*ostr == ':')
return (BADARG);
_getprogname(), optopt);
return (BADCH);
}
- else /* white space */
- optarg = nargv[optind];
place = EMSG;
++optind;
}
- return (optopt); /* dump back option letter */
+ return (optopt); /* return option letter */
}
-.\" $NetBSD: getopt_long.3,v 1.8 2002/06/03 12:01:43 wiz Exp $
+.\" $OpenBSD: getopt_long.3,v 1.10 2004/01/06 23:44:28 fgsch Exp $
+.\" $NetBSD: getopt_long.3,v 1.14 2003/08/07 16:43:40 agc Exp $
.\"
.\" Copyright (c) 1988, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\" 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.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
+.\" 3. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" SUCH DAMAGE.
.\"
.\" @(#)getopt.3 8.5 (Berkeley) 4/27/95
-.\" $FreeBSD: src/lib/libc/stdlib/getopt_long.3,v 1.3 2002/12/18 12:45:10 ru Exp $
+.\" $FreeBSD: src/lib/libc/stdlib/getopt_long.3,v 1.11 2004/03/06 14:47:49 ache Exp $
.\"
.Dd April 1, 2000
.Dt GETOPT_LONG 3
.Os
.Sh NAME
-.Nm getopt_long
+.Nm getopt_long ,
+.Nm getopt_long_only
.Nd get long options from command line argument list
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In getopt.h
+.Vt extern char *optarg ;
+.Vt extern int optind ;
+.Vt extern int optopt ;
+.Vt extern int opterr ;
+.Vt extern int optreset ;
.Ft int
.Fo getopt_long
.Fa "int argc" "char * const *argv" "const char *optstring"
-.Fa "struct option *long options" "int *index"
+.Fa "const struct option *longopts" "int *longindex"
+.Fc
+.Ft int
+.Fo getopt_long_only
+.Fa "int argc" "char * const *argv" "const char *optstring"
+.Fa "const struct option *longopts" "int *longindex"
.Fc
.Sh DESCRIPTION
The
to the corresponding short option will make this function act just
like
.Xr getopt 3 .
+.Pp
+If the
+.Fa longindex
+field is not
+.Dv NULL ,
+then the integer pointed to by it will be set to the index of the long
+option relative to
+.Fa longopts .
+.Pp
+The last element of the
+.Fa longopts
+array has to be filled with zeroes.
+.Pp
+The
+.Fn getopt_long_only
+function behaves identically to
+.Fn getopt_long
+with the exception that long options may start with
+.Ql -
+in addition to
+.Ql -- .
+If an option starting with
+.Ql -
+does not match a long option but does match a single-character option,
+the single-character option is returned.
+.Sh RETURN VALUES
+If the
+.Fa flag
+field in
+.Li struct option
+is
+.Dv NULL ,
+.Fn getopt_long
+and
+.Fn getopt_long_only
+return the value specified in the
+.Fa val
+field, which is usually just the corresponding short option.
+If
+.Fa flag
+is not
+.Dv NULL ,
+these functions return 0 and store
+.Fa val
+in the location pointed to by
+.Fa flag .
+These functions return
+.Ql \&:
+if there was a missing option argument,
+.Ql \&?
+if the user specified an unknown or ambiguous option, and
+\-1 when the argument list has been exhausted.
.Sh EXAMPLES
.Bd -literal -compact
-extern char *optarg;
-extern int optind;
int bflag, ch, fd;
int daggerset;
/* options descriptor */
static struct option longopts[] = {
- { "buffy", no_argument, 0, 'b' },
- { "floride", required_argument, 0, 'f' },
+ { "buffy", no_argument, NULL, 'b' },
+ { "fluoride", required_argument, NULL, 'f' },
{ "daggerset", no_argument, \*[Am]daggerset, 1 },
- { 0, 0, 0, 0 }
+ { NULL, 0, NULL, 0 }
};
bflag = 0;
while ((ch = getopt_long(argc, argv, "bf:", longopts, NULL)) != -1)
- switch(ch) {
+ switch (ch) {
case 'b':
bflag = 1;
break;
case 'f':
- if ((fd = open(optarg, O_RDONLY, 0)) \*[Lt] 0) {
- (void)fprintf(stderr,
- "myname: %s: %s\en", optarg, strerror(errno));
- exit(1);
- }
+ if ((fd = open(optarg, O_RDONLY, 0)) == -1)
+ err(1, "unable to open %s", optarg);
break;
case 0:
- if(daggerset) {
+ if (daggerset) {
fprintf(stderr,"Buffy will use her dagger to "
- "apply floride to dracula's teeth\en");
+ "apply fluoride to dracula's teeth\en");
}
break;
- case '?':
default:
usage();
}
implementation
found in glibc-2.1.3:
.Bl -bullet
-.It
-Handling of
-.Ql -
-as first char of option string in presence of
-environment variable
-.Ev POSIXLY_CORRECT :
-.Bl -tag -width ".Nx"
-.It Tn GNU
-ignores
-.Ev POSIXLY_CORRECT
-and returns non-options as
-arguments to option '\e1'.
-.It Nx
-honors
-.Ev POSIXLY_CORRECT
-and stops at the first non-option.
-.El
-.It
-Handling of
-.Ql ::
-in options string in presence of
-.Ev POSIXLY_CORRECT :
-.Bl -tag -width ".Nx"
-.It Both
-.Tn GNU
-and
-.Nx
-ignore
-.Ev POSIXLY_CORRECT
-here and take
-.Ql ::
-to
-mean the preceding option takes an optional argument.
-.El
-.It
-Return value in case of missing argument if first character
-(after
-.Ql +
-or
-.Ql - )
-in option string is not
-.Ql \&: :
-.Bl -tag -width ".Nx"
-.It Tn GNU
-returns
-.Ql \&?
-.It Nx
-returns
-.Ql \&:
-(since
-.Nx Ns 's
-.Fn getopt
-does).
-.El
-.It
-Handling of
-.Ql --a
-in getopt:
-.Bl -tag -width ".Nx"
-.It Tn GNU
-parses this as option
-.Ql - ,
-option
-.Ql a .
-.It Nx
-parses this as
-.Ql -- ,
-and returns \-1 (ignoring the
-.Ql a ) .
-(Because the original
-.Fn getopt
-does.)
-.El
+.\" .It
+.\" Handling of
+.\" .Ql -
+.\" as first char of option string in presence of
+.\" environment variable
+.\" .Ev POSIXLY_CORRECT :
+.\" .Bl -tag -width ".Bx"
+.\" .It Tn GNU
+.\" ignores
+.\" .Ev POSIXLY_CORRECT
+.\" and returns non-options as
+.\" arguments to option '\e1'.
+.\" .It Bx
+.\" honors
+.\" .Ev POSIXLY_CORRECT
+.\" and stops at the first non-option.
+.\" .El
+.\" .It
+.\" Handling of
+.\" .Ql -
+.\" within the option string (not the first character):
+.\" .Bl -tag -width ".Bx"
+.\" .It Tn GNU
+.\" treats a
+.\" .Ql -
+.\" on the command line as a non-argument.
+.\" .It Bx
+.\" a
+.\" .Ql -
+.\" within the option string matches a
+.\" .Ql -
+.\" (single dash) on the command line.
+.\" This functionality is provided for backward compatibility with
+.\" programs, such as
+.\" .Xr su 1 ,
+.\" that use
+.\" .Ql -
+.\" as an option flag.
+.\" This practice is wrong, and should not be used in any current development.
+.\" .El
+.\" .It
+.\" Handling of
+.\" .Ql ::
+.\" in options string in presence of
+.\" .Ev POSIXLY_CORRECT :
+.\" .Bl -tag -width ".Bx"
+.\" .It Both
+.\" .Tn GNU
+.\" and
+.\" .Bx
+.\" ignore
+.\" .Ev POSIXLY_CORRECT
+.\" here and take
+.\" .Ql ::
+.\" to
+.\" mean the preceding option takes an optional argument.
+.\" .El
+.\" .It
+.\" Return value in case of missing argument if first character
+.\" (after
+.\" .Ql +
+.\" or
+.\" .Ql - )
+.\" in option string is not
+.\" .Ql \&: :
+.\" .Bl -tag -width ".Bx"
+.\" .It Tn GNU
+.\" returns
+.\" .Ql \&?
+.\" .It Bx
+.\" returns
+.\" .Ql \&:
+.\" (since
+.\" .Bx Ns 's
+.\" .Fn getopt
+.\" does).
+.\" .El
+.\" .It
+.\" Handling of
+.\" .Ql --a
+.\" in getopt:
+.\" .Bl -tag -width ".Bx"
+.\" .It Tn GNU
+.\" parses this as option
+.\" .Ql - ,
+.\" option
+.\" .Ql a .
+.\" .It Bx
+.\" parses this as
+.\" .Ql -- ,
+.\" and returns \-1 (ignoring the
+.\" .Ql a ) .
+.\" (Because the original
+.\" .Fn getopt
+.\" does.)
+.\" .El
.It
Setting of
.Va optopt
.Va flag
!=
.Dv NULL :
-.Bl -tag -width ".Nx"
+.Bl -tag -width ".Bx"
.It Tn GNU
sets
.Va optopt
to
.Va val .
-.It Nx
+.It Bx
sets
.Va optopt
to 0 (since
.Va val
would never be returned).
.El
-.It
-Handling of
-.Ql -W
-with
-.Ql W ;
-in option string in
-.Fn getopt
-(not
-.Fn getopt_long ) :
-.Bl -tag -width ".Nx"
-.It Tn GNU
-causes a segfault.
-.It Nx
-returns \-1, with
-.Va optind
-pointing past the argument of
-.Ql -W
-(as if
-.Ql "-W arg"
-were
-.Ql --arg ,
-and thus
-.Ql --
-had been found).
-.\" How should we treat W; in the option string when called via
-.\" getopt? Ignore the ';' or treat it as a ':'? Issue a warning?
-.El
+.\" .It
+.\" Handling of
+.\" .Ql -W
+.\" with
+.\" .Ql W;
+.\" in option string in
+.\" .Fn getopt
+.\" (not
+.\" .Fn getopt_long ) :
+.\" .Bl -tag -width ".Bx"
+.\" .It Tn GNU
+.\" causes a segfault.
+.\" .It Bx
+.\" no special handling is done;
+.\" .Ql W;
+.\" is interpreted as two separate options, neither of which take an argument.
+.\" .El
.It
Setting of
.Va optarg
for long options without an argument that are
invoked via
.Ql -W
-.Ql ( W ;
+.Ql ( W;
in option string):
-.Bl -tag -width ".Nx"
+.Bl -tag -width ".Bx"
.It Tn GNU
sets
.Va optarg
to the option name (the argument of
.Ql -W ) .
-.It Nx
+.It Bx
sets
.Va optarg
to
.Ql -W
with an argument that is not (a prefix to) a known
long option
-.Ql ( W ;
+.Ql ( W;
in option string):
-.Bl -tag -width ".Nx"
+.Bl -tag -width ".Bx"
.It Tn GNU
returns
.Ql -W
with
.Va optarg
set to the unknown option.
-.It Nx
+.It Bx
treats this as an error (unknown option) and returns
.Ql \&?
with
.Tn GNU Ns 's
man page documents).
.El
+.\" .It
+.\" The error messages are different.
.It
-The error messages are different.
-.It
-.Nx
+.Bx
does not permute the argument vector at the same points in
the calling sequence as
.Tn GNU
to current positions) are the same, though.
(We do fewer variable swaps.)
.El
+.Sh ENVIRONMENT
+.Bl -tag -width POSIXLY_CORRECT
+.It Ev POSIXLY_CORRECT
+If set, option processing stops when the first non-option is found and
+a leading
+.Ql -
+or
+.Ql +
+in the
+.Ar optstring
+is ignored.
+.El
.Sh SEE ALSO
.Xr getopt 3
.Sh HISTORY
The
.Fn getopt_long
-function first appeared in
+and
+.Fn getopt_long_only
+functions first appeared in
.Tn GNU
libiberty.
The first
-.Nx
-implementation appeared in 1.5.
+.Bx
+implementation of
+.Fn getopt_long
+appeared in
+.Nx 1.5 ,
+the first
+.Bx
+implementation of
+.Fn getopt_long_only
+in
+.Ox 3.3 .
+.Fx
+first included
+.Fn getopt_long
+in
+.Fx 5.0 ,
+.Fn getopt_long_only
+in
+.Fx 5.2 .
.Sh BUGS
+The
+.Ar argv
+argument is not really
+.Dv const
+as its elements may be permuted (unless
+.Ev POSIXLY_CORRECT
+is set).
+.Pp
The implementation can completely replace
.Xr getopt 3 ,
but right now we are using separate code.
+/* $OpenBSD: getopt_long.c,v 1.17 2004/06/03 18:46:52 millert Exp $ */
/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */
-/* $FreeBSD: src/lib/libc/stdlib/getopt_long.c,v 1.2 2002/10/16 22:18:42 alfred Exp $ */
+/*
+ * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
+#if 0
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $");
+static char *rcsid = "$OpenBSD: getopt_long.c,v 1.16 2004/02/04 18:17:25 millert Exp $";
#endif /* LIBC_SCCS and not lint */
+#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/lib/libc/stdlib/getopt_long.c,v 1.12 2004/07/06 13:58:45 ache Exp $");
-#include "namespace.h"
-
-#include <assert.h>
#include <err.h>
#include <errno.h>
#include <getopt.h>
#include <stdlib.h>
#include <string.h>
-/* not part of the original file */
-#ifndef _DIAGASSERT
-#define _DIAGASSERT(X)
-#endif
+#define GNU_COMPATIBLE /* Be more compatible, configure's use us! */
-#if HAVE_CONFIG_H && !HAVE_GETOPT_LONG && !HAVE_DECL_OPTIND
-#define REPLACE_GETOPT
+#ifndef GNU_COMPATIBLE
+#define REPLACE_GETOPT /* use this getopt as the system getopt(3) */
#endif
#ifdef REPLACE_GETOPT
-#ifdef __weak_alias
-__weak_alias(getopt,_getopt)
-#endif
int opterr = 1; /* if error message should be printed */
int optind = 1; /* index into parent argv vector */
int optopt = '?'; /* character checked for validity */
int optreset; /* reset getopt */
char *optarg; /* argument associated with option */
-#elif HAVE_CONFIG_H && !HAVE_DECL_OPTRESET
-static int optreset;
#endif
-#ifdef __weak_alias
-__weak_alias(getopt_long,_getopt_long)
-#endif
+#define PRINT_ERROR ((opterr) && (*options != ':'))
-#if !HAVE_GETOPT_LONG
-#define IGNORE_FIRST (*options == '-' || *options == '+')
-#define PRINT_ERROR ((opterr) && ((*options != ':') \
- || (IGNORE_FIRST && options[1] != ':')))
-#define IS_POSIXLY_CORRECT (getenv("POSIXLY_CORRECT") != NULL)
-#define PERMUTE (!IS_POSIXLY_CORRECT && !IGNORE_FIRST)
-/* XXX: GNU ignores PC if *options == '-' */
-#define IN_ORDER (!IS_POSIXLY_CORRECT && *options == '-')
+#define FLAG_PERMUTE 0x01 /* permute non-options to the end of argv */
+#define FLAG_ALLARGS 0x02 /* treat non-options as args to option "-1" */
+#define FLAG_LONGONLY 0x04 /* operate as getopt_long_only */
/* return values */
-#define BADCH (int)'?'
-#define BADARG ((IGNORE_FIRST && options[1] == ':') \
- || (*options == ':') ? (int)':' : (int)'?')
-#define INORDER (int)1
+#define BADCH (int)'?'
+#define BADARG ((*options == ':') ? (int)':' : (int)'?')
+#define INORDER (int)1
+
+#define EMSG ""
-#define EMSG ""
+#ifdef GNU_COMPATIBLE
+#define NO_PREFIX (-1)
+#define D_PREFIX 0
+#define DD_PREFIX 1
+#define W_PREFIX 2
+#endif
-static int getopt_internal(int, char * const *, const char *);
+static int getopt_internal(int, char * const *, const char *,
+ const struct option *, int *, int);
+static int parse_long_options(char * const *, const char *,
+ const struct option *, int *, int, int);
static int gcd(int, int);
static void permute_args(int, int, int, char * const *);
/* Error messages */
static const char recargchar[] = "option requires an argument -- %c";
+static const char illoptchar[] = "illegal option -- %c"; /* From P1003.2 */
+#ifdef GNU_COMPATIBLE
+static int dash_prefix = NO_PREFIX;
+static const char gnuoptchar[] = "invalid option -- %c";
+
+static const char recargstring[] = "option `%s%s' requires an argument";
+static const char ambig[] = "option `%s%.*s' is ambiguous";
+static const char noarg[] = "option `%s%.*s' doesn't allow an argument";
+static const char illoptstring[] = "unrecognized option `%s%s'";
+#else
static const char recargstring[] = "option requires an argument -- %s";
static const char ambig[] = "ambiguous option -- %.*s";
static const char noarg[] = "option doesn't take an argument -- %.*s";
-static const char illoptchar[] = "unknown option -- %c";
static const char illoptstring[] = "unknown option -- %s";
-
+#endif
/*
* Compute the greatest common divisor of a and b.
*/
static int
-gcd(a, b)
- int a;
- int b;
+gcd(int a, int b)
{
int c;
b = c;
c = a % b;
}
-
- return b;
+
+ return (b);
}
/*
* in each block).
*/
static void
-permute_args(panonopt_start, panonopt_end, opt_end, nargv)
- int panonopt_start;
- int panonopt_end;
- int opt_end;
- char * const *nargv;
+permute_args(int panonopt_start, int panonopt_end, int opt_end,
+ char * const *nargv)
{
int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
char *swap;
- _DIAGASSERT(nargv != NULL);
-
/*
* compute lengths of blocks and number and size of cycles
*/
}
}
+/*
+ * parse_long_options --
+ * Parse long options in argc/argv argument vector.
+ * Returns -1 if short_too is set and the option does not match long_options.
+ */
+static int
+parse_long_options(char * const *nargv, const char *options,
+ const struct option *long_options, int *idx, int short_too, int flags)
+{
+ char *current_argv, *has_equal;
+#ifdef GNU_COMPATIBLE
+ char *current_dash;
+#endif
+ size_t current_argv_len;
+ int i, match, exact_match, second_partial_match;
+
+ current_argv = place;
+#ifdef GNU_COMPATIBLE
+ switch (dash_prefix) {
+ case D_PREFIX:
+ current_dash = "-";
+ break;
+ case DD_PREFIX:
+ current_dash = "--";
+ break;
+ case W_PREFIX:
+ current_dash = "-W ";
+ break;
+ default:
+ current_dash = "";
+ break;
+ }
+#endif
+ match = -1;
+ exact_match = 0;
+ second_partial_match = 0;
+
+ optind++;
+
+ if ((has_equal = strchr(current_argv, '=')) != NULL) {
+ /* argument found (--option=arg) */
+ current_argv_len = has_equal - current_argv;
+ has_equal++;
+ } else
+ current_argv_len = strlen(current_argv);
+
+ for (i = 0; long_options[i].name; i++) {
+ /* find matching long option */
+ if (strncmp(current_argv, long_options[i].name,
+ current_argv_len))
+ continue;
+
+ if (strlen(long_options[i].name) == current_argv_len) {
+ /* exact match */
+ match = i;
+ exact_match = 1;
+ break;
+ }
+ /*
+ * If this is a known short option, don't allow
+ * a partial match of a single character.
+ */
+ if (short_too && current_argv_len == 1)
+ continue;
+
+ if (match == -1) /* first partial match */
+ match = i;
+ else if ((flags & FLAG_LONGONLY) ||
+ long_options[i].has_arg !=
+ long_options[match].has_arg ||
+ long_options[i].flag != long_options[match].flag ||
+ long_options[i].val != long_options[match].val)
+ second_partial_match = 1;
+ }
+ if (!exact_match && second_partial_match) {
+ /* ambiguous abbreviation */
+ if (PRINT_ERROR)
+ warnx(ambig,
+#ifdef GNU_COMPATIBLE
+ current_dash,
+#endif
+ (int)current_argv_len,
+ current_argv);
+ optopt = 0;
+ return (BADCH);
+ }
+ if (match != -1) { /* option found */
+ if (long_options[match].has_arg == no_argument
+ && has_equal) {
+ if (PRINT_ERROR)
+ warnx(noarg,
+#ifdef GNU_COMPATIBLE
+ current_dash,
+#endif
+ (int)current_argv_len,
+ current_argv);
+ /*
+ * XXX: GNU sets optopt to val regardless of flag
+ */
+ if (long_options[match].flag == NULL)
+ optopt = long_options[match].val;
+ else
+ optopt = 0;
+#ifdef GNU_COMPATIBLE
+ return (BADCH);
+#else
+ return (BADARG);
+#endif
+ }
+ if (long_options[match].has_arg == required_argument ||
+ long_options[match].has_arg == optional_argument) {
+ if (has_equal)
+ optarg = has_equal;
+ else if (long_options[match].has_arg ==
+ required_argument) {
+ /*
+ * optional argument doesn't use next nargv
+ */
+ optarg = nargv[optind++];
+ }
+ }
+ if ((long_options[match].has_arg == required_argument)
+ && (optarg == NULL)) {
+ /*
+ * Missing argument; leading ':' indicates no error
+ * should be generated.
+ */
+ if (PRINT_ERROR)
+ warnx(recargstring,
+#ifdef GNU_COMPATIBLE
+ current_dash,
+#endif
+ current_argv);
+ /*
+ * XXX: GNU sets optopt to val regardless of flag
+ */
+ if (long_options[match].flag == NULL)
+ optopt = long_options[match].val;
+ else
+ optopt = 0;
+ --optind;
+ return (BADARG);
+ }
+ } else { /* unknown option */
+ if (short_too) {
+ --optind;
+ return (-1);
+ }
+ if (PRINT_ERROR)
+ warnx(illoptstring,
+#ifdef GNU_COMPATIBLE
+ current_dash,
+#endif
+ current_argv);
+ optopt = 0;
+ return (BADCH);
+ }
+ if (idx)
+ *idx = match;
+ if (long_options[match].flag) {
+ *long_options[match].flag = long_options[match].val;
+ return (0);
+ } else
+ return (long_options[match].val);
+}
+
/*
* getopt_internal --
* Parse argc/argv argument vector. Called by user level routines.
- * Returns -2 if -- is found (can be long option or end of options marker).
*/
static int
-getopt_internal(nargc, nargv, options)
- int nargc;
- char * const *nargv;
- const char *options;
+getopt_internal(int nargc, char * const *nargv, const char *options,
+ const struct option *long_options, int *idx, int flags)
{
char *oli; /* option letter list index */
- int optchar;
+ int optchar, short_too;
+ int posixly_correct;
- _DIAGASSERT(nargv != NULL);
- _DIAGASSERT(options != NULL);
+ if (options == NULL)
+ return (-1);
- optarg = NULL;
+ /*
+ * Disable GNU extensions if POSIXLY_CORRECT is set or options
+ * string begins with a '+'.
+ */
+ posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
+#ifdef GNU_COMPATIBLE
+ if (*options == '-')
+ flags |= FLAG_ALLARGS;
+ else if (posixly_correct || *options == '+')
+ flags &= ~FLAG_PERMUTE;
+#else
+ if (posixly_correct || *options == '+')
+ flags &= ~FLAG_PERMUTE;
+ else if (*options == '-')
+ flags |= FLAG_ALLARGS;
+#endif
+ if (*options == '+' || *options == '-')
+ options++;
/*
- * XXX Some programs (like rsyncd) expect to be able to
- * XXX re-initialize optind to 0 and have getopt_long(3)
- * XXX properly function again. Work around this braindamage.
+ * XXX Some GNU programs (like cvs) set optind to 0 instead of
+ * XXX using optreset. Work around this braindamage.
*/
if (optind == 0)
- optind = 1;
+ optind = optreset = 1;
+ optarg = NULL;
if (optreset)
nonopt_start = nonopt_end = -1;
start:
optind = nonopt_start;
}
nonopt_start = nonopt_end = -1;
- return -1;
+ return (-1);
}
- if ((*(place = nargv[optind]) != '-')
- || (place[1] == '\0')) { /* found non-option */
- place = EMSG;
- if (IN_ORDER) {
+ if (*(place = nargv[optind]) != '-' ||
+#ifdef GNU_COMPATIBLE
+ place[1] == '\0') {
+#else
+ (place[1] == '\0' && strchr(options, '-') == NULL)) {
+#endif
+ place = EMSG; /* found non-option */
+ if (flags & FLAG_ALLARGS) {
/*
- * GNU extension:
+ * GNU extension:
* return non-option as argument to option 1
*/
optarg = nargv[optind++];
- return INORDER;
+ return (INORDER);
}
- if (!PERMUTE) {
+ if (!(flags & FLAG_PERMUTE)) {
/*
- * if no permutation wanted, stop parsing
- * at first non-option
+ * If no permutation wanted, stop parsing
+ * at first non-option.
*/
- return -1;
+ return (-1);
}
/* do permutation */
if (nonopt_start == -1)
}
if (nonopt_start != -1 && nonopt_end == -1)
nonopt_end = optind;
- if (place[1] && *++place == '-') { /* found "--" */
- place++;
- return -2;
+
+ /*
+ * If we have "-" do nothing, if "--" we are done.
+ */
+ if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
+ optind++;
+ place = EMSG;
+ /*
+ * We found an option (--), so if we skipped
+ * non-options, we have to permute.
+ */
+ if (nonopt_end != -1) {
+ permute_args(nonopt_start, nonopt_end,
+ optind, nargv);
+ optind -= nonopt_end - nonopt_start;
+ }
+ nonopt_start = nonopt_end = -1;
+ return (-1);
}
}
+
+ /*
+ * Check long options if:
+ * 1) we were passed some
+ * 2) the arg is not just "-"
+ * 3) either the arg starts with -- we are getopt_long_only()
+ */
+ if (long_options != NULL && place != nargv[optind] &&
+ (*place == '-' || (flags & FLAG_LONGONLY))) {
+ short_too = 0;
+#ifdef GNU_COMPATIBLE
+ dash_prefix = D_PREFIX;
+#endif
+ if (*place == '-') {
+ place++; /* --foo long option */
+#ifdef GNU_COMPATIBLE
+ dash_prefix = DD_PREFIX;
+#endif
+ } else if (*place != ':' && strchr(options, *place) != NULL)
+ short_too = 1; /* could be short option too */
+
+ optchar = parse_long_options(nargv, options, long_options,
+ idx, short_too, flags);
+ if (optchar != -1) {
+ place = EMSG;
+ return (optchar);
+ }
+ }
+
if ((optchar = (int)*place++) == (int)':' ||
- (oli = strchr(options + (IGNORE_FIRST ? 1 : 0), optchar)) == NULL) {
- /* option letter unknown or ':' */
+ (optchar == (int)'-' && *place != '\0') ||
+ (oli = strchr(options, optchar)) == NULL) {
+ /*
+ * If the user specified "-" and '-' isn't listed in
+ * options, return -1 (non-option) as per POSIX.
+ * Otherwise, it is an unknown option character (or ':').
+ */
+ if (optchar == (int)'-' && *place == '\0')
+ return (-1);
if (!*place)
++optind;
+#ifdef GNU_COMPATIBLE
+ if (PRINT_ERROR)
+ warnx(posixly_correct ? illoptchar : gnuoptchar,
+ optchar);
+#else
if (PRINT_ERROR)
warnx(illoptchar, optchar);
+#endif
optopt = optchar;
- return BADCH;
+ return (BADCH);
}
- if (optchar == 'W' && oli[1] == ';') { /* -W long-option */
- /* XXX: what if no long options provided (called by getopt)? */
- if (*place)
- return -2;
-
- if (++optind >= nargc) { /* no arg */
+ if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
+ /* -W long-option */
+ if (*place) /* no space */
+ /* NOTHING */;
+ else if (++optind >= nargc) { /* no arg */
place = EMSG;
if (PRINT_ERROR)
warnx(recargchar, optchar);
optopt = optchar;
- return BADARG;
+ return (BADARG);
} else /* white space */
place = nargv[optind];
- /*
- * Handle -W arg the same as --arg (which causes getopt to
- * stop parsing).
- */
- return -2;
+#ifdef GNU_COMPATIBLE
+ dash_prefix = W_PREFIX;
+#endif
+ optchar = parse_long_options(nargv, options, long_options,
+ idx, 0, flags);
+ place = EMSG;
+ return (optchar);
}
if (*++oli != ':') { /* doesn't take argument */
if (!*place)
if (PRINT_ERROR)
warnx(recargchar, optchar);
optopt = optchar;
- return BADARG;
+ return (BADARG);
} else
optarg = nargv[optind];
+ } else if (!(flags & FLAG_PERMUTE)) {
+ /*
+ * If permutation is disabled, we can accept an
+ * optional arg separated by whitespace so long
+ * as it does not start with a dash (-).
+ */
+ if (optind + 1 < nargc && *nargv[optind + 1] != '-')
+ optarg = nargv[++optind];
}
place = EMSG;
++optind;
}
/* dump back option letter */
- return optchar;
+ return (optchar);
}
#ifdef REPLACE_GETOPT
* getopt --
* Parse argc/argv argument vector.
*
- * [eventually this will replace the real getopt]
+ * [eventually this will replace the BSD getopt]
*/
int
-getopt(nargc, nargv, options)
- int nargc;
- char * const *nargv;
- const char *options;
+getopt(int nargc, char * const *nargv, const char *options)
{
- int retval;
-
- _DIAGASSERT(nargv != NULL);
- _DIAGASSERT(options != NULL);
- if ((retval = getopt_internal(nargc, nargv, options)) == -2) {
- ++optind;
- /*
- * We found an option (--), so if we skipped non-options,
- * we have to permute.
- */
- if (nonopt_end != -1) {
- permute_args(nonopt_start, nonopt_end, optind,
- nargv);
- optind -= nonopt_end - nonopt_start;
- }
- nonopt_start = nonopt_end = -1;
- retval = -1;
- }
- return retval;
+ /*
+ * We don't pass FLAG_PERMUTE to getopt_internal() since
+ * the BSD getopt(3) (unlike GNU) has never done this.
+ *
+ * Furthermore, since many privileged programs call getopt()
+ * before dropping privileges it makes sense to keep things
+ * as simple (and bug-free) as possible.
+ */
+ return (getopt_internal(nargc, nargv, options, NULL, NULL, 0));
}
-#endif
+#endif /* REPLACE_GETOPT */
/*
* getopt_long --
const struct option *long_options;
int *idx;
{
- int retval;
-
- _DIAGASSERT(nargv != NULL);
- _DIAGASSERT(options != NULL);
- _DIAGASSERT(long_options != NULL);
- /* idx may be NULL */
- if ((retval = getopt_internal(nargc, nargv, options)) == -2) {
- char *current_argv, *has_equal;
- size_t current_argv_len;
- int i, match;
-
- current_argv = place;
- match = -1;
+ return (getopt_internal(nargc, nargv, options, long_options, idx,
+ FLAG_PERMUTE));
+}
- optind++;
- place = EMSG;
+/*
+ * getopt_long_only --
+ * Parse argc/argv argument vector.
+ */
+int
+getopt_long_only(nargc, nargv, options, long_options, idx)
+ int nargc;
+ char * const *nargv;
+ const char *options;
+ const struct option *long_options;
+ int *idx;
+{
- if (*current_argv == '\0') { /* found "--" */
- /*
- * We found an option (--), so if we skipped
- * non-options, we have to permute.
- */
- if (nonopt_end != -1) {
- permute_args(nonopt_start, nonopt_end,
- optind, nargv);
- optind -= nonopt_end - nonopt_start;
- }
- nonopt_start = nonopt_end = -1;
- return -1;
- }
- if ((has_equal = strchr(current_argv, '=')) != NULL) {
- /* argument found (--option=arg) */
- current_argv_len = has_equal - current_argv;
- has_equal++;
- } else
- current_argv_len = strlen(current_argv);
-
- for (i = 0; long_options[i].name; i++) {
- /* find matching long option */
- if (strncmp(current_argv, long_options[i].name,
- current_argv_len))
- continue;
-
- if (strlen(long_options[i].name) ==
- (unsigned)current_argv_len) {
- /* exact match */
- match = i;
- break;
- }
- if (match == -1) /* partial match */
- match = i;
- else {
- /* ambiguous abbreviation */
- if (PRINT_ERROR)
- warnx(ambig, (int)current_argv_len,
- current_argv);
- optopt = 0;
- return BADCH;
- }
- }
- if (match != -1) { /* option found */
- if (long_options[match].has_arg == no_argument
- && has_equal) {
- if (PRINT_ERROR)
- warnx(noarg, (int)current_argv_len,
- current_argv);
- /*
- * XXX: GNU sets optopt to val regardless of
- * flag
- */
- if (long_options[match].flag == NULL)
- optopt = long_options[match].val;
- else
- optopt = 0;
- return BADARG;
- }
- if (long_options[match].has_arg == required_argument ||
- long_options[match].has_arg == optional_argument) {
- if (has_equal)
- optarg = has_equal;
- else if (long_options[match].has_arg ==
- required_argument) {
- /*
- * optional argument doesn't use
- * next nargv
- */
- optarg = nargv[optind++];
- }
- }
- if ((long_options[match].has_arg == required_argument)
- && (optarg == NULL)) {
- /*
- * Missing argument; leading ':'
- * indicates no error should be generated
- */
- if (PRINT_ERROR)
- warnx(recargstring, current_argv);
- /*
- * XXX: GNU sets optopt to val regardless
- * of flag
- */
- if (long_options[match].flag == NULL)
- optopt = long_options[match].val;
- else
- optopt = 0;
- --optind;
- return BADARG;
- }
- } else { /* unknown option */
- if (PRINT_ERROR)
- warnx(illoptstring, current_argv);
- optopt = 0;
- return BADCH;
- }
- if (long_options[match].flag) {
- *long_options[match].flag = long_options[match].val;
- retval = 0;
- } else
- retval = long_options[match].val;
- if (idx)
- *idx = match;
- }
- return retval;
+ return (getopt_internal(nargc, nargv, options, long_options, idx,
+ FLAG_PERMUTE|FLAG_LONGONLY));
}
-#endif /* !GETOPT_LONG */
.\" SUCH DAMAGE.
.\"
.\" @(#)getsubopt.3 8.1 (Berkeley) 6/9/93
-.\" $FreeBSD: src/lib/libc/stdlib/getsubopt.3,v 1.9 2001/09/07 14:46:35 asmodai Exp $
+.\" $FreeBSD: src/lib/libc/stdlib/getsubopt.3,v 1.10 2004/02/23 03:32:10 ache Exp $
.\"
.Dd June 9, 1993
.Dt GETSUBOPT 3
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
-.In unistd.h
+.In stdlib.h
.Vt extern char *suboptarg ;
.Ft int
.Fn getsubopt "char **optionp" "char * const *tokens" "char **valuep"
static char sccsid[] = "@(#)getsubopt.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdlib/getsubopt.c,v 1.5 2003/01/03 23:31:50 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdlib/getsubopt.c,v 1.6 2004/02/23 03:30:02 ache Exp $");
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
/*
* The SVID interface to getsubopt provides no way of figuring out which
.\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
.\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/lib/libc/stdlib/grantpt.3,v 1.1 2003/01/02 20:44:41 jmallett Exp $
+.\" $FreeBSD: src/lib/libc/stdlib/grantpt.3,v 1.3 2003/09/14 13:41:57 ru Exp $
.\"
.Dd December 23, 2002
.Os
.In stdlib.h
.Ft int
.Fn grantpt "int fildes"
-.Ft char *
+.Ft "char *"
.Fn ptsname "int fildes"
.Ft int
.Fn unlockpt "int fildes"
function is used to establish ownership and permissions
of the slave device counterpart to the master device
specified with
-.Va fildes .
+.Fa fildes .
The slave device's ownership is set to the real user ID
of the calling process, and the permissions are set to
user readable-writable and group writable.
The group owner of the slave device is also set to the
-group "tty" if it exists on the system; otherwise, it
+group
+.Dq Li tty
+if it exists on the system; otherwise, it
is left untouched.
.Pp
The
.Fn ptsname
function returns the full pathname of the slave device
counterpart to the master device specified with
-.Va fildes .
+.Fa fildes .
This value can be used
to subsequently open the appropriate slave after
.Fn posix_openpt
.Fn unlockpt
function clears the lock held on the pseudo-terminal pair
for the master device specified with
-.Va fildes .
+.Fa fildes .
.Pp
The
.Fn posix_openpt
function opens the first available master pseudo-terminal
device and returns a descriptor to it.
-.Va mode
+The
+.Fa mode
+argument
specifies the flags used for opening the device:
-.Bl -tag -width O_NOCTTY
+.Bl -tag -width ".Dv O_NOCTTY"
.It Dv O_RDWR
Open for reading and writing.
.It Dv O_NOCTTY
the controlling terminal for the calling process.
.El
.Sh RETURN VALUES
-The
-.Fn grantpt
-and
-.Fn unlockpt
-functions return 0 on success; otherwise -1 is returned and
-.Va errno
-is set to indicate the error.
+.Rv -std grantpt unlockpt
.Pp
The
.Fn ptsname
function returns a pointer to the name
-of the slave device on success;
-otherwise a NULL pointer is returned and
+of the slave device on success; otherwise a
+.Dv NULL
+pointer is returned and the global variable
.Va errno
is set to indicate the error.
.Pp
.Fn posix_openpt
function returns a file descriptor to the first
available master pseudo-terminal device on success;
-otherwise -1 is returned and
+otherwise \-1 is returned and the global variable
.Va errno
is set to indicate the error.
.Sh ERRORS
.Va errno
to:
.Bl -tag -width Er
-.It EINVAL
-.Va fildes
+.It Bq Er EINVAL
+.Fa fildes
is not a master pseudo-terminal device.
.El
.Pp
.Va errno
to:
.Bl -tag -width Er
-.It EACCES
+.It Bq Er EACCES
The slave pseudo-terminal device could not be accessed.
.El
.Pp
.Va errno
to:
.Bl -tag -width Er
-.It EINVAL
-.Va mode
-consists an an invalid mode bit.
-.It EAGAIN
+.It Bq Er EINVAL
+.Fa mode
+consists of an invalid mode bit.
+.It Bq Er EAGAIN
The system has no available pseudo-terminal devices.
.El
.Pp
.Fn unlockpt
functions may also fail and set
.Va errno
-for any of the errors specified for the routine
-.Xr fstat 2 .
+for any of the errors specified for the
+.Xr fstat 2
+system call.
.Pp
The
.Fn posix_openpt
function may also fail and set
.Va errno
-for any of the errors specified for the routine
-.Xr open 2 .
+for any of the errors specified for the
+.Xr open 2
+system call.
.Sh SEE ALSO
.Xr open 2 ,
.Xr pty 4 ,
--- /dev/null
+--- /Volumes/XDisk/tmp/Libc/stdlib/FreeBSD/grantpt.3.orig 2003-09-14 06:41:57.000000000 -0700
++++ /Volumes/XDisk/tmp/Libc/stdlib/FreeBSD/grantpt.3 2004-10-24 17:08:31.000000000 -0700
+@@ -44,6 +44,7 @@
+ .Lb libc
+ .Sh SYNOPSIS
+ .In stdlib.h
++.In fcntl.h
+ .Ft int
+ .Fn grantpt "int fildes"
+ .Ft "char *"
--- /dev/null
+--- grantpt.c.orig 2004-09-14 19:06:46.000000000 -0700
++++ grantpt.c 2004-09-14 19:11:31.000000000 -0700
+@@ -54,18 +54,16 @@
+ #include <unistd.h>
+ #include "un-namespace.h"
+
+-#define PTM_MAJOR 6 /* pseudo tty master major */
+-#define PTS_MAJOR 5 /* pseudo tty slave major */
+ #define PTM_PREFIX "pty" /* pseudo tty master naming convention */
+ #define PTS_PREFIX "tty" /* pseudo tty slave naming convention */
+
+ /*
+ * The following are range values for pseudo TTY devices. Pseudo TTYs have a
+- * name of /dev/[pt]ty[p-sP-S][0-9a-v], yielding 256 combinations per major.
++ * name of /dev/[pt]ty[p-w][0-9a-f], yielding 128 combinations per major.
+ */
+-#define PT_MAX 256
+-#define PT_DEV1 "pqrsPQRS"
+-#define PT_DEV2 "0123456789abcdefghijklmnopqrstuv"
++#define PT_MAX 128
++#define PT_DEV1 "pqrstuvw"
++#define PT_DEV2 "0123456789abcdef"
+
+ /*
+ * grantpt(3) support utility.
+@@ -73,11 +71,32 @@
+ #define _PATH_PTCHOWN "/usr/libexec/pt_chown"
+
+ /*
++ * On Mac OS X, the major device number may not be the same between reboots.
++ * So we need to determine the major device number the first time.
++ */
++#define _PATH_A_PTY (_PATH_DEV PTM_PREFIX "p0")
++
++static int _ptm_major = -1;
++
++static int
++_init_major(void)
++{
++ struct stat st;
++
++ if (_ptm_major >= 0)
++ return _ptm_major;
++ if (stat(_PATH_A_PTY, &st) < 0)
++ return -1; /* should never happen */
++ _ptm_major = major(st.st_rdev);
++ return _ptm_major;
++}
++/*
+ * ISPTM(x) returns 0 for struct stat x if x is not a pty master.
+ * The bounds checking may be unnecessary but it does eliminate doubt.
+ */
+-#define ISPTM(x) (S_ISCHR((x).st_mode) && \
+- major((x).st_rdev) == PTM_MAJOR && \
++#define ISPTM(x) (_init_major() >= 0 && \
++ S_ISCHR((x).st_mode) && \
++ major((x).st_rdev) == _ptm_major && \
+ minor((x).st_rdev) >= 0 && \
+ minor((x).st_rdev) < PT_MAX)
+
+@@ -227,8 +246,8 @@
+ errno = EINVAL;
+ else {
+ (void)sprintf(slave, _PATH_DEV PTS_PREFIX "%c%c",
+- PT_DEV1[minor(sbuf.st_rdev) / 32],
+- PT_DEV2[minor(sbuf.st_rdev) % 32]);
++ PT_DEV1[minor(sbuf.st_rdev) / 16],
++ PT_DEV2[minor(sbuf.st_rdev) % 16]);
+ retval = slave;
+ }
+ }
-.\" $FreeBSD: src/lib/libc/stdlib/hcreate.3,v 1.3 2003/03/12 14:18:14 dwmalone Exp $
+.\" $FreeBSD: src/lib/libc/stdlib/hcreate.3,v 1.4 2003/09/08 19:57:15 ru Exp $
.\"
.Dd May 8, 2001
.Os
argument is a structure of type
.Vt ENTRY
(defined in the
-.Aq Pa search.h
+.In search.h
header) containing two pointers:
.Fa item.key
points to the comparison key (a
--- /dev/null
+--- putenv.c.orig 2003-05-20 15:23:25.000000000 -0700
++++ putenv.c 2004-10-24 01:10:20.000000000 -0700
+@@ -40,10 +40,22 @@
+ #include <stdlib.h>
+ #include <string.h>
+
++#if __DARWIN_UNIX03
++#include <errno.h>
++__private_extern__ int __setenv(const char *, const char *, int, int);
++#endif /* __DARWIN_UNIX03 */
++
+ int
+ putenv(str)
+- const char *str;
++ char *str;
+ {
++#if __DARWIN_UNIX03
++ if (str == NULL || *str == 0 || index(str, '=') == NULL) {
++ errno = EINVAL;
++ return (-1);
++ }
++ return (__setenv(str, NULL, 1, 0));
++#else /* !__DARWIN_UNIX03 */
+ char *p, *equal;
+ int rval;
+
+@@ -57,4 +69,5 @@
+ rval = setenv(p, equal + 1, 1);
+ (void)free(p);
+ return (rval);
++#endif /* __DARWIN_UNIX03 */
+ }
.\" SUCH DAMAGE.
.\"
.\" @(#)qsort.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/stdlib/qsort.3,v 1.13 2002/12/18 12:45:10 ru Exp $
+.\" $FreeBSD: src/lib/libc/stdlib/qsort.3,v 1.15 2004/07/02 23:52:12 ru Exp $
.\"
-.Dd September 7, 2002
+.Dd September 30, 2003
.Dt QSORT 3
.Os
.Sh NAME
.Fn qsort
and
.Fn qsort_r
-functions are an implementation of C.A.R. Hoare's
+functions are an implementation of C.A.R.
+Hoare's
.Dq quicksort
algorithm,
-a variant of partition-exchange sorting; in particular, see D.E. Knuth's
-Algorithm Q.
+a variant of partition-exchange sorting; in particular, see
+.An D.E. Knuth Ns 's
+.%T "Algorithm Q" .
.Sy Quicksort
takes O N lg N average time.
This implementation uses median selection to avoid its
.Pp
The
.Fn heapsort
-function is an implementation of J.W.J. William's
+function is an implementation of
+.An "J.W.J. William" Ns 's
.Dq heapsort
algorithm,
-a variant of selection sorting; in particular, see D.E. Knuth's Algorithm H.
+a variant of selection sorting; in particular, see
+.An "D.E. Knuth" Ns 's
+.%T "Algorithm H" .
.Sy Heapsort
takes O N lg N worst-case time.
Its
.%P pp. 114-123, 145-149
.Re
.Rs
-.%A Mcilroy, P.M.
+.%A McIlroy, P.M.
.%T "Optimistic Sorting and Information Theoretic Complexity"
.%J "Fourth Annual ACM-SIAM Symposium on Discrete Algorithms"
.%V January 1992
.Re
.Rs
.%A Bentley, J.L.
+.%A McIlroy, M.D.
.%T "Engineering a Sort Function"
-.%J "bentley@research.att.com"
-.%V January 1992
+.%J "Software--Practice and Experience"
+.%V Vol. 23(11)
+.%P pp. 1249-1265
+.%D November\ 1993
.Re
.Sh STANDARDS
The
--- /dev/null
+--- qsort.c.orig 2004-12-01 20:08:48.000000000 -0800
++++ qsort.c 2004-12-01 20:10:50.000000000 -0800
+@@ -44,8 +44,8 @@
+ #else
+ typedef int cmp_t(const void *, const void *);
+ #endif
+-static inline char *med3(char *, char *, char *, cmp_t *, void *);
+-static inline void swapfunc(char *, char *, int, int);
++static inline char *med3(char *, char *, char *, cmp_t *, void *) __attribute__((always_inline));
++static inline void swapfunc(char *, char *, int, int) __attribute__((always_inline));
+
+ #define min(a, b) (a) < (b) ? a : b
+
.\" SUCH DAMAGE.
.\"
.\" @(#)radixsort.3 8.2 (Berkeley) 1/27/94
-.\" $FreeBSD: src/lib/libc/stdlib/radixsort.3,v 1.9 2001/09/07 14:46:35 asmodai Exp $
+.\" $FreeBSD: src/lib/libc/stdlib/radixsort.3,v 1.11 2004/07/02 23:52:12 ru Exp $
.\"
.Dd January 27, 1994
.Dt RADIXSORT 3
.Os
.Sh NAME
-.Nm radixsort
+.Nm radixsort , sradixsort
.Nd radix sort
.Sh LIBRARY
.Lb libc
function is not stable, but uses no additional memory.
.Pp
These functions are variants of most-significant-byte radix sorting; in
-particular, see D.E. Knuth's Algorithm R and section 5.2.5, exercise 10.
+particular, see
+.An "D.E. Knuth" Ns 's
+.%T "Algorithm R"
+and section 5.2.5, exercise 10.
They take linear time relative to the number of bytes in the strings.
.Sh RETURN VALUES
.Rv -std radixsort
static char sccsid[] = "@(#)radixsort.c 8.2 (Berkeley) 4/28/95";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdlib/radixsort.c,v 1.6 2002/03/22 09:18:34 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdlib/radixsort.c,v 1.7 2003/11/11 04:59:23 kientzle Exp $");
/*
* Radixsort routines.
}
}
+ /*
+ * Special case: if all strings have the same
+ * character at position i, move on to the next
+ * character.
+ */
+ if (nc == 1 && count[bmin] == n) {
+ push(a, n, i+1);
+ nc = count[bmin] = 0;
+ continue;
+ }
+
/*
* Set top[]; push incompletely sorted bins onto stack.
* top[] = pointers to last out-of-place element in bins.
--- /dev/null
+--- radixsort.c.orig 2004-12-01 20:08:48.000000000 -0800
++++ radixsort.c 2004-12-01 20:11:23.000000000 -0800
+@@ -64,7 +64,7 @@
+ } stack;
+
+ static inline void simplesort
+-(const u_char **, int, int, const u_char *, u_int);
++(const u_char **, int, int, const u_char *, u_int) __attribute__((always_inline));
+ static void r_sort_a(const u_char **, int, int, const u_char *, u_int);
+ static void r_sort_b(const u_char **, const u_char **, int, int,
+ const u_char *, u_int);
.\" SUCH DAMAGE.
.\"
.\" @(#)rand.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/stdlib/rand.3,v 1.13 2002/12/18 12:45:10 ru Exp $
+.\" $FreeBSD: src/lib/libc/stdlib/rand.3,v 1.14 2003/09/08 19:57:15 ru Exp $
.\"
.Dd May 25, 1999
.Dt RAND 3
of 0 to
.Dv RAND_MAX
(as defined by the header file
-.Aq Pa stdlib.h ) .
+.In stdlib.h ) .
.Pp
The
.Fn srand
.\" SUCH DAMAGE.
.\"
.\" @(#)random.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/stdlib/random.3,v 1.17 2001/09/07 14:46:36 asmodai Exp $
+.\" $FreeBSD: src/lib/libc/stdlib/random.3,v 1.20 2004/07/02 23:52:12 ru Exp $
.\"
.Dd June 4, 1993
.Dt RANDOM 3
The difference is that
.Xr rand 3
produces a much less random sequence \(em in fact, the low dozen bits
-generated by rand go through a cyclic pattern. All the bits generated by
+generated by rand go through a cyclic pattern.
+All the bits generated by
.Fn random
-are usable. For example,
+are usable.
+For example,
.Sq Li random()&01
will produce a random binary
value.
.Pp
The
.Fn srandomdev
-routine initialize a state array using
+routine initializes a state array using the
.Xr random 4
random number device which returns good random numbers,
suitable for cryptographic use.
The
.Fn initstate
routine allows a state array, passed in as an argument, to be initialized
-for future use. The size of the state array (in bytes) is used by
+for future use.
+The size of the state array (in bytes) is used by
.Fn initstate
to decide how sophisticated a random number generator it should use \(em the
more state, the better the random numbers will be.
(Current "optimal" values for the amount of state information are
8, 32, 64, 128, and 256 bytes; other amounts will be rounded down to
-the nearest known amount. Using less than 8 bytes will cause an error.)
+the nearest known amount.
+Using less than 8 bytes will cause an error.)
The seed for the initialization (which specifies a starting point for
the random number sequence, and provides for restarting at the same
point) is also an argument.
detects that the state information has been garbled, error
messages are printed on the standard error output.
.Sh SEE ALSO
+.Xr arc4random 3 ,
.Xr rand 3 ,
.Xr srand 3 ,
.Xr random 4
random sequence did not vary much with the seed.
The current implementation employs a better pseudo-random number
generator for the initial state calculation.
+.Pp
+Applications requiring cryptographic quality randomness should use
+.Xr arc4random 3 .
static char sccsid[] = "@(#)random.c 8.2 (Berkeley) 5/19/95";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdlib/random.c,v 1.22 2003/02/04 11:24:08 ache Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdlib/random.c,v 1.24 2004/01/20 03:02:18 das Exp $");
#include "namespace.h"
#include <sys/time.h> /* for srandomdev() */
#include <fcntl.h> /* for srandomdev() */
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> /* for srandomdev() */
* congruential generator. If the amount of state information is less than
* 32 bytes, a simple linear congruential R.N.G. is used.
*
- * Internally, the state information is treated as an array of longs; the
+ * Internally, the state information is treated as an array of uint32_t's; the
* zeroeth element of the array is the type of R.N.G. being used (small
* integer); the remainder of the array is the state information for the
- * R.N.G. Thus, 32 bytes of state information will give 7 longs worth of
+ * R.N.G. Thus, 32 bytes of state information will give 7 ints worth of
* state information, which will allow a degree seven polynomial. (Note:
* the zeroeth word of state information also has some other information
* stored in it -- see setstate() for details).
*/
#define MAX_TYPES 5 /* max number of types above */
-#define NSHUFF 100 /* to drop part of seed -> 1st value correlation */
+#ifdef USE_WEAK_SEEDING
+#define NSHUFF 0
+#else /* !USE_WEAK_SEEDING */
+#define NSHUFF 50 /* to drop some "seed -> 1st value" linearity */
+#endif /* !USE_WEAK_SEEDING */
-static long degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 };
-static long seps [MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 };
+static const int degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 };
+static const int seps [MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 };
/*
* Initially, everything is set up as if from:
* MAX_TYPES * (rptr - state) + TYPE_3 == TYPE_3.
*/
-static long randtbl[DEG_3 + 1] = {
+static uint32_t randtbl[DEG_3 + 1] = {
TYPE_3,
#ifdef USE_WEAK_SEEDING
/* Historic implementation compatibility */
* in the initialization of randtbl) because the state table pointer is set
* to point to randtbl[1] (as explained below).
*/
-static long *fptr = &randtbl[SEP_3 + 1];
-static long *rptr = &randtbl[1];
+static uint32_t *fptr = &randtbl[SEP_3 + 1];
+static uint32_t *rptr = &randtbl[1];
/*
* The following things are the pointer to the state information table, the
* this is more efficient than indexing every time to find the address of
* the last element to see if the front and rear pointers have wrapped.
*/
-static long *state = &randtbl[1];
-static long rand_type = TYPE_3;
-static long rand_deg = DEG_3;
-static long rand_sep = SEP_3;
-static long *end_ptr = &randtbl[DEG_3 + 1];
+static uint32_t *state = &randtbl[1];
+static int rand_type = TYPE_3;
+static int rand_deg = DEG_3;
+static int rand_sep = SEP_3;
+static uint32_t *end_ptr = &randtbl[DEG_3 + 1];
-static inline long good_rand(long);
+static inline uint32_t good_rand(int32_t);
-static inline long good_rand (x)
- long x;
+static inline uint32_t good_rand (x)
+ int32_t x;
{
#ifdef USE_WEAK_SEEDING
/*
* Park and Miller, Communications of the ACM, vol. 31, no. 10,
* October 1988, p. 1195.
*/
- long hi, lo;
+ int32_t hi, lo;
/* Can't be initialized with 0, so use another value. */
if (x == 0)
srandom(x)
unsigned long x;
{
- long i, lim;
+ int i, lim;
- state[0] = x;
+ state[0] = (uint32_t)x;
if (rand_type == TYPE_0)
lim = NSHUFF;
else {
*
* Returns a pointer to the old state.
*
- * Note: The Sparc platform requires that arg_state begin on a long
+ * Note: The Sparc platform requires that arg_state begin on an int
* word boundary; otherwise a bus error will occur. Even so, lint will
* complain about mis-alignment, but you should disregard these messages.
*/
long n; /* # bytes of state info */
{
char *ostate = (char *)(&state[-1]);
- long *long_arg_state = (long *) arg_state;
+ uint32_t *int_arg_state = (uint32_t *)arg_state;
if (rand_type == TYPE_0)
state[-1] = rand_type;
rand_deg = DEG_4;
rand_sep = SEP_4;
}
- state = (long *) (long_arg_state + 1); /* first location */
+ state = int_arg_state + 1; /* first location */
end_ptr = &state[rand_deg]; /* must set end_ptr before srandom */
srandom(seed);
if (rand_type == TYPE_0)
- long_arg_state[0] = rand_type;
+ int_arg_state[0] = rand_type;
else
- long_arg_state[0] = MAX_TYPES * (rptr - state) + rand_type;
+ int_arg_state[0] = MAX_TYPES * (rptr - state) + rand_type;
return(ostate);
}
*
* Returns a pointer to the old state information.
*
- * Note: The Sparc platform requires that arg_state begin on a long
+ * Note: The Sparc platform requires that arg_state begin on an int
* word boundary; otherwise a bus error will occur. Even so, lint will
* complain about mis-alignment, but you should disregard these messages.
*/
setstate(arg_state)
char *arg_state; /* pointer to state array */
{
- long *new_state = (long *) arg_state;
- long type = new_state[0] % MAX_TYPES;
- long rear = new_state[0] / MAX_TYPES;
+ uint32_t *new_state = (uint32_t *)arg_state;
+ uint32_t type = new_state[0] % MAX_TYPES;
+ uint32_t rear = new_state[0] / MAX_TYPES;
char *ostate = (char *)(&state[-1]);
if (rand_type == TYPE_0)
(void)fprintf(stderr,
"random: state info corrupted; not changed.\n");
}
- state = (long *) (new_state + 1);
+ state = new_state + 1;
if (rand_type != TYPE_0) {
rptr = &state[rear];
fptr = &state[(rear + rand_sep) % rand_deg];
long
random()
{
- long i;
- long *f, *r;
+ uint32_t i;
+ uint32_t *f, *r;
if (rand_type == TYPE_0) {
i = state[0];
fptr = f; rptr = r;
}
- return(i);
+ return((long)i);
}
--- /dev/null
+--- random.c.orig 2004-12-01 20:08:48.000000000 -0800
++++ random.c 2004-12-01 20:12:11.000000000 -0800
+@@ -37,6 +37,14 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdlib/random.c,v 1.24 2004/01/20 03:02:18 das Exp $");
+
++/*
++ * We always compile with __DARWIN_UNIX03 set to one, relying on the fact that
++ * (for non-LP64) sizeof(int) == sizeof(long) == sizeof(size_t), so that we
++ * don't have to have two different versions of the prototypes. For LP64,
++ * we only support the POSIX-compatible prototypes.
++ */
++#undef __DARWIN_UNIX03
++#define __DARWIN_UNIX03 1
+ #include "namespace.h"
+ #include <sys/time.h> /* for srandomdev() */
+ #include <fcntl.h> /* for srandomdev() */
+@@ -220,7 +228,7 @@
+ static int rand_sep = SEP_3;
+ static uint32_t *end_ptr = &randtbl[DEG_3 + 1];
+
+-static inline uint32_t good_rand(int32_t);
++static inline uint32_t good_rand(int32_t) __attribute__((always_inline));
+
+ static inline uint32_t good_rand (x)
+ int32_t x;
+@@ -269,7 +277,7 @@
+ */
+ void
+ srandom(x)
+- unsigned long x;
++ unsigned x;
+ {
+ int i, lim;
+
+@@ -357,9 +365,9 @@
+ */
+ char *
+ initstate(seed, arg_state, n)
+- unsigned long seed; /* seed for R.N.G. */
++ unsigned seed; /* seed for R.N.G. */
+ char *arg_state; /* pointer to state array */
+- long n; /* # bytes of state info */
++ size_t n; /* # bytes of state info */
+ {
+ char *ostate = (char *)(&state[-1]);
+ uint32_t *int_arg_state = (uint32_t *)arg_state;
+@@ -425,7 +433,7 @@
+ */
+ char *
+ setstate(arg_state)
+- char *arg_state; /* pointer to state array */
++ const char *arg_state; /* pointer to state array */
+ {
+ uint32_t *new_state = (uint32_t *)arg_state;
+ uint32_t type = new_state[0] % MAX_TYPES;
---- realpath.c.orig Fri Aug 15 19:22:17 2003
-+++ realpath.c Tue Dec 9 14:36:32 2003
-@@ -40,8 +40,27 @@
+--- realpath.c.orig 2003-08-15 19:22:17.000000000 -0700
++++ realpath.c 2004-12-04 14:47:52.000000000 -0800
+@@ -35,13 +35,35 @@
+ #include "namespace.h"
+ #include <sys/param.h>
+ #include <sys/stat.h>
++#include <sys/mount.h>
+
+ #include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+struct attrs {
+ u_int32_t len;
+ attrreference_t name;
++ dev_t dev;
+ fsobj_type_t type;
++ fsobj_id_t id;
+ char buf[PATH_MAX];
+};
+
+static struct attrlist alist = {
+ ATTR_BIT_MAP_COUNT,
+ 0,
-+ ATTR_CMN_NAME | ATTR_CMN_OBJTYPE,
++ ATTR_CMN_NAME | ATTR_CMN_DEVID | ATTR_CMN_OBJTYPE | ATTR_CMN_OBJID,
+ 0,
+ 0,
+ 0,
/*
* char *realpath(const char *path, char resolved[PATH_MAX]);
*
-@@ -52,11 +71,12 @@
+@@ -52,13 +74,25 @@
char *
realpath(const char *path, char resolved[PATH_MAX])
{
- int serrno, slen;
+ int serrno, slen, useattrs, islink;
char left[PATH_MAX], next_token[PATH_MAX], symlink[PATH_MAX];
++ dev_t dev, lastdev;
++ struct statfs sfs;
++ static dev_t rootdev;
++ static int rootdev_inited = 0;
++ ino_t inode;
++ if (!rootdev_inited) {
++ rootdev_inited = 1;
++ if (stat("/", &sb) < 0)
++ return (NULL);
++ rootdev = sb.st_dev;
++ }
serrno = errno;
-@@ -127,6 +147,13 @@
+ symlinks = 0;
+ if (path[0] == '/') {
+@@ -80,6 +114,12 @@
+ errno = ENAMETOOLONG;
+ return (NULL);
+ }
++ if (resolved_len > 1) {
++ if (stat(resolved, &sb) < 0)
++ return (NULL);
++ lastdev = sb.st_dev;
++ } else
++ lastdev = rootdev;
+
+ /*
+ * Iterate over path components in `left'.
+@@ -127,6 +167,13 @@
}
/*
* Append the next path component and lstat() it. If
* lstat() fails we still can return successfully if
* there are no more path components left.
-@@ -136,14 +163,22 @@
+@@ -136,14 +183,72 @@
errno = ENAMETOOLONG;
return (NULL);
}
+ if (getattrlist(resolved, &alist, &attrs, sizeof(attrs), FSOPT_NOFOLLOW) == 0) {
+ useattrs = 1;
+ islink = (attrs.type == VLNK);
++ dev = attrs.dev;
++ inode = attrs.id.fid_objno;
+ } else if (errno == EOPNOTSUPP || errno == EINVAL) {
-+ if ((useattrs = lstat(resolved, &sb)) == 0)
++ if ((useattrs = lstat(resolved, &sb)) == 0) {
+ islink = S_ISLNK(sb.st_mode);
++ dev = sb.st_dev;
++ inode = sb.st_ino;
++ }
+ } else
+ useattrs = -1;
+ if (useattrs < 0) {
return (NULL);
}
- if (S_ISLNK(sb.st_mode)) {
++ if (dev != lastdev) {
++ /*
++ * We have crossed a mountpoint. For volumes like UDF
++ * the getattrlist name may not match the actual
++ * mountpoint, so we just copy the mountpoint directly.
++ * (3703138). However, the mountpoint may not be
++ * accessible, as when chroot-ed, so check first.
++ * There may be a file on the chroot-ed volume with
++ * the same name as the mountpoint, so compare device
++ * and inode numbers.
++ */
++ lastdev = dev;
++ if (statfs(resolved, &sfs) == 0 && lstat(sfs.f_mntonname, &sb) == 0 && dev == sb.st_dev && inode == sb.st_ino) {
++ /*
++ * However, it's possible that the mountpoint
++ * path matches, even though it isn't the real
++ * path in the chroot-ed environment, so check
++ * that each component of the mountpoint
++ * is a directory (and not a symlink)
++ */
++ char temp[MNAMELEN];
++ char *cp;
++ int ok = 1;
++
++ strcpy(temp, sfs.f_mntonname);
++ for(;;) {
++ if ((cp = strrchr(temp, '/')) == NULL) {
++ ok = 0;
++ break;
++ }
++ if (cp <= temp)
++ break;
++ *cp = 0;
++ if (lstat(temp, &sb) < 0 || (sb.st_mode & S_IFMT) != S_IFDIR) {
++ ok = 0;
++ break;
++ }
++ }
++ if (ok) {
++ resolved_len = strlcpy(resolved, sfs.f_mntonname, PATH_MAX);
++ continue;
++ }
++ }
++ /* if we fail, use the other methods. */
++ }
+ if (islink) {
if (symlinks++ > MAXSYMLINKS) {
errno = ELOOP;
return (NULL);
-@@ -184,7 +219,30 @@
+@@ -155,6 +260,7 @@
+ if (symlink[0] == '/') {
+ resolved[1] = 0;
+ resolved_len = 1;
++ lastdev = rootdev;
+ } else if (resolved_len > 1) {
+ /* Strip the last path component. */
+ resolved[resolved_len - 1] = '\0';
+@@ -184,7 +290,30 @@
}
}
left_len = strlcpy(left, symlink, sizeof(left));
---- setenv.c.orig Mon Apr 28 16:37:26 2003
-+++ setenv.c Tue May 6 16:55:50 2003
-@@ -40,6 +40,7 @@
+--- setenv.c.orig 2003-05-20 15:23:25.000000000 -0700
++++ setenv.c 2004-11-05 17:15:11.000000000 -0800
+@@ -40,81 +40,137 @@
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
+#include <crt_externs.h>
++#include <errno.h>
char *__findenv(const char *, int *);
++__private_extern__ int __setenv(const char *, const char *, int, int);
-@@ -54,7 +55,7 @@
+-/*
+- * setenv --
+- * Set the value of the environmental variable "name" to be
+- * "value". If rewrite is set, replace any current value.
+- */
+-int
+-setenv(name, value, rewrite)
++#ifndef BUILDING_VARIANT
++__private_extern__ int
++__setenv(name, value, rewrite, copy)
+ const char *name;
const char *value;
- int rewrite;
+- int rewrite;
++ int rewrite, copy;
{
- extern char **environ;
+ char ***environp = _NSGetEnviron();
static char **alloced; /* if allocated space before */
char *c;
- int l_value, offset;
-@@ -73,30 +74,30 @@
+- int l_value, offset;
++ int offset;
+
+- if (*value == '=') /* no `=' in value */
+- ++value;
+- l_value = strlen(value);
+ if ((c = __findenv(name, &offset))) { /* find if already exists */
+ if (!rewrite)
+ return (0);
+- if (strlen(c) >= l_value) { /* old larger; copy over */
+- while ( (*c++ = *value++) );
+- return (0);
+- }
++ /* In UNIX03, we can't overwrite even if the string is long
++ * enough, because the putenv() string is owned by the user
++ * (ie, always malloc() a new string) */
+ } else { /* create new slot */
int cnt;
char **p;
+ (*environp)[cnt + 1] = NULL;
offset = cnt;
}
- for (c = (char *)name; *c && *c != '='; ++c); /* no `=' in name */
+- for (c = (char *)name; *c && *c != '='; ++c); /* no `=' in name */
- if (!(environ[offset] = /* name + `=' + value */
-+ if (!((*environp)[offset] = /* name + `=' + value */
- malloc((size_t)((int)(c - name) + l_value + 2))))
- return (-1);
+- malloc((size_t)((int)(c - name) + l_value + 2))))
+- return (-1);
- for (c = environ[offset]; (*c = *name++) && *c != '='; ++c);
-+ for (c = (*environp)[offset]; (*c = *name++) && *c != '='; ++c);
- for (*c++ = '='; (*c++ = *value++); );
+- for (*c++ = '='; (*c++ = *value++); );
++ /* For non Unix03, or UnixO3 setenv(), we make a copy of the user's
++ * strings. For Unix03 putenv(), we put the string directly in
++ * the environment. */
++ if (copy) {
++ for (c = (char *)name; *c && *c != '='; ++c); /* no `=' in name */
++ if (!((*environp)[offset] = /* name + `=' + value */
++ malloc((size_t)((int)(c - name) + strlen(value) + 2))))
++ return (-1);
++ for (c = (*environp)[offset]; (*c = *name++) && *c != '='; ++c);
++ for (*c++ = '='; (*c++ = *value++); );
++ } else
++ (*environp)[offset] = name;
return (0);
}
-@@ -109,7 +110,7 @@
++#endif /* !BUILD_VARIANT */
++
++/*
++ * setenv --
++ * Set the value of the environmental variable "name" to be
++ * "value". If rewrite is set, replace any current value.
++ */
++int
++setenv(name, value, rewrite)
++ const char *name;
++ const char *value;
++ int rewrite;
++{
++ /* no null ptr or empty str */
++ if(name == NULL || *name == 0) {
++ errno = EINVAL;
++ return (-1);
++ }
++
++#if __DARWIN_UNIX03
++ /* no '=' in name */
++ if (strchr(name, '=')) {
++ errno = EINVAL;
++ return (-1);
++ }
++#endif /* __DARWIN_UNIX03 */
++
++ if (*value == '=') /* no `=' in value */
++ ++value;
++ return (__setenv(name, value, rewrite, 1));
++}
+
+ /*
+ * unsetenv(name) --
+ * Delete environmental variable "name".
+ */
++#if __DARWIN_UNIX03
++int
++#else /* !__DARWIN_UNIX03 */
+ void
++#endif /* __DARWIN_UNIX03 */
unsetenv(name)
const char *name;
{
char **p;
int offset;
++#if __DARWIN_UNIX03
++ /* no null ptr or empty str */
++ if(name == NULL || *name == 0) {
++ errno = EINVAL;
++ return (-1);
++ }
++
++ /* no '=' in name */
++ if (strchr(name, '=')) {
++ errno = EINVAL;
++ return (-1);
++ }
++#else /* !__DARWIN_UNIX03 */
++ /* no null ptr or empty str */
++ if(name == NULL || *name == 0)
++ return;
++#endif /* __DARWIN_UNIX03 */
+ while (__findenv(name, &offset)) /* if set multiple times */
+ for (p = &environ[offset];; ++p)
+ if (!(*p = *(p + 1)))
+ break;
++#if __DARWIN_UNIX03
++ return 0;
++#endif /* __DARWIN_UNIX03 */
+ }
---- strfmon.3.orig Mon Apr 28 16:37:26 2003
-+++ strfmon.3 Sat May 3 01:09:16 2003
-@@ -35,7 +35,7 @@
+--- strfmon.3.orig Fri Mar 11 10:06:33 2005
++++ strfmon.3 Fri Mar 11 10:20:51 2005
+@@ -28,14 +28,18 @@
+ .Dt STRFMON 3
+ .Os
+ .Sh NAME
+-.Nm strfmon
++.Nm strfmon ,
++.Nm strfmon_l
+ .Nd convert monetary value to string
+ .Sh LIBRARY
+ .Lb libc
.Sh SYNOPSIS
.In monetary.h
.Ft ssize_t
-.Fn strfmon "char * restrict s" "size_t maxsize" "const char * restrict format" "..."
+.Fn strfmon "char * s" "size_t maxsize" "const char *format" "..."
++.In xlocale.h
++.Ft ssize_t
++.Fn strfmon_l "char * s" "size_t maxsize" "locale_t loc" "const char *format" "..."
.Sh DESCRIPTION
The
.Fn strfmon
+@@ -47,6 +51,14 @@
+ .Fa maxsize
+ bytes are placed into the array.
+ .Pp
++While the
++.Fn strfmon
++function uses the current locale, the
++.Fn strfmon_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
++.Pp
+ The format string is composed of zero or more directives:
+ ordinary characters (not
+ .Cm % ) ,
+@@ -142,7 +154,8 @@
+ Not enough memory for temporary buffers.
+ .El
+ .Sh SEE ALSO
+-.Xr localeconv 3
++.Xr localeconv 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn strfmon
--- /dev/null
+--- strfmon.c.orig 2003-05-20 15:23:25.000000000 -0700
++++ strfmon.c 2005-02-27 11:52:19.000000000 -0800
+@@ -28,6 +28,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ache Exp $");
+
++#include "xlocale_private.h"
++
+ #include <sys/types.h>
+ #include <ctype.h>
+ #include <errno.h>
+@@ -61,9 +63,9 @@
+ PRINT(*tmps++); \
+ } while (0)
+
+-#define GET_NUMBER(VAR) do { \
++#define GET_NUMBER(VAR,LOC) do { \
+ VAR = 0; \
+- while (isdigit((unsigned char)*fmt)) { \
++ while (isdigit_l((unsigned char)*fmt, (LOC))) { \
+ VAR *= 10; \
+ VAR += *fmt - '0'; \
+ fmt++; \
+@@ -83,15 +85,14 @@
+ groups++; \
+ } while (0)
+
+-static void __setup_vars(int, char *, char *, char *, char **);
+-static int __calc_left_pad(int, char *);
+-static char *__format_grouped_double(double, int *, int, int, int);
+-
+-ssize_t
+-strfmon(char * __restrict s, size_t maxsize, const char * __restrict format,
+- ...)
++static void __setup_vars(int, char *, char *, char *, char **, struct lconv *);
++static int __calc_left_pad(int, char *, struct lconv *);
++static char *__format_grouped_double(double, int *, int, int, int, struct lconv *, locale_t);
++
++static ssize_t
++_strfmon(char * __restrict s, size_t maxsize, locale_t loc,
++ const char * __restrict format, va_list ap)
+ {
+- va_list ap;
+ char *dst; /* output destination pointer */
+ const char *fmt; /* current format poistion pointer */
+ struct lconv *lc; /* pointer to lconv structure */
+@@ -115,9 +116,7 @@
+ char *tmpptr; /* temporary vars */
+ int sverrno;
+
+- va_start(ap, format);
+-
+- lc = localeconv();
++ lc = localeconv_l(loc);
+ dst = s;
+ fmt = format;
+ asciivalue = NULL;
+@@ -181,8 +180,8 @@
+ }
+
+ /* field Width */
+- if (isdigit((unsigned char)*fmt)) {
+- GET_NUMBER(width);
++ if (isdigit_l((unsigned char)*fmt, loc)) {
++ GET_NUMBER(width, loc);
+ /* Do we have enough space to put number with
+ * required width ?
+ */
+@@ -192,16 +191,16 @@
+
+ /* Left precision */
+ if (*fmt == '#') {
+- if (!isdigit((unsigned char)*++fmt))
++ if (!isdigit_l((unsigned char)*++fmt, loc))
+ goto format_error;
+- GET_NUMBER(left_prec);
++ GET_NUMBER(left_prec, loc);
+ }
+
+ /* Right precision */
+ if (*fmt == '.') {
+- if (!isdigit((unsigned char)*++fmt))
++ if (!isdigit_l((unsigned char)*++fmt, loc))
+ goto format_error;
+- GET_NUMBER(right_prec);
++ GET_NUMBER(right_prec, loc);
+ }
+
+ /* Conversion Characters */
+@@ -239,21 +238,21 @@
+ /* fill left_prec with amount of padding chars */
+ if (left_prec >= 0) {
+ pad_size = __calc_left_pad((flags ^ IS_NEGATIVE),
+- currency_symbol) -
+- __calc_left_pad(flags, currency_symbol);
++ currency_symbol, lc) -
++ __calc_left_pad(flags, currency_symbol, lc);
+ if (pad_size < 0)
+ pad_size = 0;
+ }
+
+ asciivalue = __format_grouped_double(value, &flags,
+- left_prec, right_prec, pad_char);
++ left_prec, right_prec, pad_char, lc, loc);
+ if (asciivalue == NULL)
+ goto end_error; /* errno already set */
+ /* to ENOMEM by malloc() */
+
+ /* set some variables for later use */
+ __setup_vars(flags, &cs_precedes, &sep_by_space,
+- &sign_posn, &signstr);
++ &sign_posn, &signstr, lc);
+
+ /*
+ * Description of some LC_MONETARY's values:
+@@ -366,7 +365,6 @@
+ }
+
+ PRINT('\0');
+- va_end(ap);
+ free(asciivalue);
+ free(currency_symbol);
+ return (dst - s - 1); /* return size of put data except trailing '\0' */
+@@ -385,15 +383,12 @@
+ if (currency_symbol != NULL)
+ free(currency_symbol);
+ errno = sverrno;
+- va_end(ap);
+ return (-1);
+ }
+
+ static void
+ __setup_vars(int flags, char *cs_precedes, char *sep_by_space,
+- char *sign_posn, char **signstr) {
+-
+- struct lconv *lc = localeconv();
++ char *sign_posn, char **signstr, struct lconv *lc) {
+
+ if ((flags & IS_NEGATIVE) && (flags & USE_INTL_CURRENCY)) {
+ *cs_precedes = lc->int_n_cs_precedes;
+@@ -429,12 +424,12 @@
+ }
+
+ static int
+-__calc_left_pad(int flags, char *cur_symb) {
++__calc_left_pad(int flags, char *cur_symb, struct lconv *lc) {
+
+ char cs_precedes, sep_by_space, sign_posn, *signstr;
+ int left_chars = 0;
+
+- __setup_vars(flags, &cs_precedes, &sep_by_space, &sign_posn, &signstr);
++ __setup_vars(flags, &cs_precedes, &sep_by_space, &sign_posn, &signstr, lc);
+
+ if (cs_precedes != 0) {
+ left_chars += strlen(cur_symb);
+@@ -480,7 +475,7 @@
+ /* convert double to ASCII */
+ static char *
+ __format_grouped_double(double value, int *flags,
+- int left_prec, int right_prec, int pad_char) {
++ int left_prec, int right_prec, int pad_char, struct lconv *lc, locale_t loc) {
+
+ char *rslt;
+ char *avalue;
+@@ -492,7 +487,6 @@
+
+ int padded;
+
+- struct lconv *lc = localeconv();
+ char *grouping;
+ char decimal_point;
+ char thousands_sep;
+@@ -526,9 +520,9 @@
+ left_prec += get_groups(left_prec, grouping);
+
+ /* convert to string */
+- snprintf(fmt, sizeof(fmt), "%%%d.%df", left_prec + right_prec + 1,
++ snprintf_l(fmt, sizeof(fmt), loc, "%%%d.%df", left_prec + right_prec + 1,
+ right_prec);
+- avalue_size = asprintf(&avalue, fmt, value);
++ avalue_size = asprintf_l(&avalue, loc, fmt, value);
+ if (avalue_size < 0)
+ return (NULL);
+
+@@ -601,3 +595,30 @@
+ free(avalue);
+ return (rslt);
+ }
++
++ssize_t
++strfmon(char * __restrict s, size_t maxsize, const char * __restrict format,
++ ...)
++{
++ ssize_t ret;
++ va_list ap;
++
++ va_start(ap, format);
++ ret = _strfmon(s, maxsize, __current_locale(), format, ap);
++ va_end(ap);
++ return ret;
++}
++
++ssize_t
++strfmon_l(char * __restrict s, size_t maxsize, locale_t loc,
++ const char * __restrict format, ...)
++{
++ ssize_t ret;
++ va_list ap;
++
++ NORMALIZE_LOCALE(loc);
++ va_start(ap, format);
++ ret = _strfmon(s, maxsize, loc, format, ap);
++ va_end(ap);
++ return ret;
++}
--- /dev/null
+--- strhash.c.orig 2004-08-27 15:27:37.000000000 -0700
++++ strhash.c 2004-08-27 15:29:08.000000000 -0700
+@@ -85,6 +85,7 @@
+
+ static int _hash(int size, char *key);
+ static hash_node *list_find(caddr_t key, hash_node *head);
++static int assign_key(char *key, hash_node *node);
+
+
+ /*
+@@ -242,8 +243,6 @@
+ else{
+ if (datum){
+
+- static int assign_key();
+-
+ hash_node *new = (hash_node *)malloc(sizeof(hash_node));
+
+ if (!new || !assign_key(key, new)){
.\" SUCH DAMAGE.
.\"
.\" @(#)strtod.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/stdlib/strtod.3,v 1.18 2003/03/12 20:31:05 das Exp $
+.\" $FreeBSD: src/lib/libc/stdlib/strtod.3,v 1.19 2003/05/22 13:02:28 ru Exp $
.\"
.Dd March 2, 2003
.Dt STRTOD 3
.Fn strtod "const char * restrict nptr" "char ** restrict endptr"
.Ft float
.Fn strtof "const char * restrict nptr" "char ** restrict endptr"
-.Ft long double
+.Ft "long double"
.Fn strtold "const char * restrict nptr" "char ** restrict endptr"
.Sh DESCRIPTION
These conversion
.Vt double ,
.Vt float ,
and
-.Vt long double
+.Vt "long double"
representation, respectively.
.Pp
The expected form of the string is an optional plus (``+'') or minus
The author of this software is
.An David M. Gay .
.Pp
+.Bd -literal
Copyright (c) 1998 by Lucent Technologies
-.br
All Rights Reserved
-.Pp
+
Permission to use, copy, modify, and distribute this software and
its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all
not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.
-.Pp
+
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
+.Ed
--- /dev/null
+--- strtod.3.orig Fri Mar 11 17:24:01 2005
++++ strtod.3 Fri Mar 11 17:25:45 2005
+@@ -100,6 +100,12 @@
+ The decimal point
+ character is defined in the program's locale (category
+ .Dv LC_NUMERIC ) .
++.Pp
++Extended locale versions of these functions are documented in
++.Xr strtod_l 3 .
++See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn strtod ,
+@@ -146,7 +152,8 @@
+ .Xr atol 3 ,
+ .Xr strtol 3 ,
+ .Xr strtoul 3 ,
+-.Xr wcstod 3
++.Xr wcstod 3 ,
++.Xr strtod_l 3
+ .Sh STANDARDS
+ The
+ .Fn strtod
--- /dev/null
+--- strtoimax.c.orig 2003-05-20 15:23:25.000000000 -0700
++++ strtoimax.c 2005-02-23 13:20:23.000000000 -0800
+@@ -37,6 +37,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdlib/strtoimax.c,v 1.9 2003/01/01 18:48:43 schweikh Exp $");
+
++#include "xlocale_private.h"
++
+ #include <ctype.h>
+ #include <errno.h>
+ #include <stdlib.h>
+@@ -49,7 +51,8 @@
+ * alphabets and digits are each contiguous.
+ */
+ intmax_t
+-strtoimax(const char * __restrict nptr, char ** __restrict endptr, int base)
++strtoimax_l(const char * __restrict nptr, char ** __restrict endptr, int base,
++ locale_t loc)
+ {
+ const char *s;
+ uintmax_t acc;
+@@ -57,6 +60,7 @@
+ uintmax_t cutoff;
+ int neg, any, cutlim;
+
++ NORMALIZE_LOCALE(loc);
+ /*
+ * Skip white space and pick up leading +/- sign if any.
+ * If base is 0, allow 0x for hex and 0 for octal, else
+@@ -65,7 +69,7 @@
+ s = nptr;
+ do {
+ c = *s++;
+- } while (isspace((unsigned char)c));
++ } while (isspace_l((unsigned char)c, loc));
+ if (c == '-') {
+ neg = 1;
+ c = *s++;
+@@ -139,3 +143,9 @@
+ *endptr = (char *)(any ? s - 1 : nptr);
+ return (acc);
+ }
++
++intmax_t
++strtoimax(const char * __restrict nptr, char ** __restrict endptr, int base)
++{
++ return strtoimax_l(nptr, endptr, base, __current_locale());
++}
--- /dev/null
+--- strtol.3.orig Fri Mar 11 17:24:07 2005
++++ strtol.3 Fri Mar 11 17:25:18 2005
+@@ -159,6 +159,12 @@
+ is
+ .Ql \e0
+ on return, the entire string was valid.)
++.Pp
++Extended locale versions of these functions are documented in
++.Xr strtol_l 3 .
++See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn strtol ,
+@@ -203,7 +209,8 @@
+ .Xr atol 3 ,
+ .Xr strtod 3 ,
+ .Xr strtoul 3 ,
+-.Xr wcstol 3
++.Xr wcstol 3 ,
++.Xr strtol_l 3
+ .Sh STANDARDS
+ The
+ .Fn strtol
--- /dev/null
+--- strtol.c.orig 2003-05-20 15:23:25.000000000 -0700
++++ strtol.c 2005-02-17 00:43:42.000000000 -0800
+@@ -37,6 +37,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdlib/strtol.c,v 1.17 2002/09/06 11:23:59 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <limits.h>
+ #include <ctype.h>
+ #include <errno.h>
+@@ -50,7 +52,8 @@
+ * alphabets and digits are each contiguous.
+ */
+ long
+-strtol(const char * __restrict nptr, char ** __restrict endptr, int base)
++strtol_l(const char * __restrict nptr, char ** __restrict endptr, int base,
++ locale_t loc)
+ {
+ const char *s;
+ unsigned long acc;
+@@ -58,6 +61,7 @@
+ unsigned long cutoff;
+ int neg, any, cutlim;
+
++ NORMALIZE_LOCALE(loc);
+ /*
+ * Skip white space and pick up leading +/- sign if any.
+ * If base is 0, allow 0x for hex and 0 for octal, else
+@@ -66,7 +70,7 @@
+ s = nptr;
+ do {
+ c = *s++;
+- } while (isspace((unsigned char)c));
++ } while (isspace_l((unsigned char)c, loc));
+ if (c == '-') {
+ neg = 1;
+ c = *s++;
+@@ -139,3 +143,9 @@
+ *endptr = (char *)(any ? s - 1 : nptr);
+ return (acc);
+ }
++
++long
++strtol(const char * __restrict nptr, char ** __restrict endptr, int base)
++{
++ return strtol_l(nptr, endptr, base, __current_locale());
++}
--- /dev/null
+--- strtoll.c.orig 2003-05-20 15:23:25.000000000 -0700
++++ strtoll.c 2005-02-17 00:46:45.000000000 -0800
+@@ -37,6 +37,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdlib/strtoll.c,v 1.19 2002/09/06 11:23:59 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <limits.h>
+ #include <errno.h>
+ #include <ctype.h>
+@@ -49,7 +51,8 @@
+ * alphabets and digits are each contiguous.
+ */
+ long long
+-strtoll(const char * __restrict nptr, char ** __restrict endptr, int base)
++strtoll_l(const char * __restrict nptr, char ** __restrict endptr, int base,
++ locale_t loc)
+ {
+ const char *s;
+ unsigned long long acc;
+@@ -57,6 +60,7 @@
+ unsigned long long cutoff;
+ int neg, any, cutlim;
+
++ NORMALIZE_LOCALE(loc);
+ /*
+ * Skip white space and pick up leading +/- sign if any.
+ * If base is 0, allow 0x for hex and 0 for octal, else
+@@ -65,7 +69,7 @@
+ s = nptr;
+ do {
+ c = *s++;
+- } while (isspace((unsigned char)c));
++ } while (isspace_l((unsigned char)c, loc));
+ if (c == '-') {
+ neg = 1;
+ c = *s++;
+@@ -139,3 +143,9 @@
+ *endptr = (char *)(any ? s - 1 : nptr);
+ return (acc);
+ }
++
++long long
++strtoll(const char * __restrict nptr, char ** __restrict endptr, int base)
++{
++ return strtoll_l(nptr, endptr, base, __current_locale());
++}
--- /dev/null
+--- strtoq.c.orig 2003-05-20 15:23:25.000000000 -0700
++++ strtoq.c 2005-02-23 18:26:32.000000000 -0800
+@@ -37,6 +37,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdlib/strtoq.c,v 1.11 2002/08/15 09:25:04 robert Exp $");
+
++#include "xlocale_private.h"
++
+ #include <sys/types.h>
+
+ #include <stdlib.h>
+@@ -48,5 +50,13 @@
+ strtoq(const char *nptr, char **endptr, int base)
+ {
+
+- return strtoll(nptr, endptr, base);
++ return strtoll_l(nptr, endptr, base, __current_locale());
++}
++
++quad_t
++strtoq_l(const char *nptr, char **endptr, int base, locale_t loc)
++{
++
++ /* no need to call NORMALIZE_LOCALE(loc) because strtoll_l will */
++ return strtoll_l(nptr, endptr, base, loc);
+ }
--- /dev/null
+--- strtoul.3.orig Fri Mar 11 10:46:00 2005
++++ strtoul.3 Fri Mar 11 10:46:30 2005
+@@ -205,7 +205,8 @@
+ .El
+ .Sh SEE ALSO
+ .Xr strtol 3 ,
+-.Xr wcstoul 3
++.Xr wcstoul 3 ,
++.Xr strtol_l 3
+ .Sh STANDARDS
+ The
+ .Fn strtoul
--- /dev/null
+--- strtoul.c.orig 2003-05-20 15:23:25.000000000 -0700
++++ strtoul.c 2005-02-17 12:52:46.000000000 -0800
+@@ -37,6 +37,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdlib/strtoul.c,v 1.16 2002/09/06 11:23:59 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <limits.h>
+ #include <ctype.h>
+ #include <errno.h>
+@@ -49,7 +51,8 @@
+ * alphabets and digits are each contiguous.
+ */
+ unsigned long
+-strtoul(const char * __restrict nptr, char ** __restrict endptr, int base)
++strtoul_l(const char * __restrict nptr, char ** __restrict endptr, int base,
++ locale_t loc)
+ {
+ const char *s;
+ unsigned long acc;
+@@ -57,13 +60,14 @@
+ unsigned long cutoff;
+ int neg, any, cutlim;
+
++ NORMALIZE_LOCALE(loc);
+ /*
+ * See strtol for comments as to the logic used.
+ */
+ s = nptr;
+ do {
+ c = *s++;
+- } while (isspace((unsigned char)c));
++ } while (isspace_l((unsigned char)c, loc));
+ if (c == '-') {
+ neg = 1;
+ c = *s++;
+@@ -117,3 +121,9 @@
+ *endptr = (char *)(any ? s - 1 : nptr);
+ return (acc);
+ }
++
++unsigned long
++strtoul(const char * __restrict nptr, char ** __restrict endptr, int base)
++{
++ return strtoul_l(nptr, endptr, base, __current_locale());
++}
--- /dev/null
+--- strtoull.c.orig 2003-05-20 15:23:25.000000000 -0700
++++ strtoull.c 2005-02-17 00:52:41.000000000 -0800
+@@ -37,6 +37,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdlib/strtoull.c,v 1.18 2002/09/06 11:23:59 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <limits.h>
+ #include <errno.h>
+ #include <ctype.h>
+@@ -49,7 +51,8 @@
+ * alphabets and digits are each contiguous.
+ */
+ unsigned long long
+-strtoull(const char * __restrict nptr, char ** __restrict endptr, int base)
++strtoull_l(const char * __restrict nptr, char ** __restrict endptr, int base,
++ locale_t loc)
+ {
+ const char *s;
+ unsigned long long acc;
+@@ -57,13 +60,14 @@
+ unsigned long long cutoff;
+ int neg, any, cutlim;
+
++ NORMALIZE_LOCALE(loc);
+ /*
+ * See strtoq for comments as to the logic used.
+ */
+ s = nptr;
+ do {
+ c = *s++;
+- } while (isspace((unsigned char)c));
++ } while (isspace_l((unsigned char)c, loc));
+ if (c == '-') {
+ neg = 1;
+ c = *s++;
+@@ -117,3 +121,9 @@
+ *endptr = (char *)(any ? s - 1 : nptr);
+ return (acc);
+ }
++
++unsigned long long
++strtoull(const char * __restrict nptr, char ** __restrict endptr, int base)
++{
++ return strtoull_l(nptr, endptr, base, __current_locale());
++}
--- /dev/null
+--- strtoumax.c.orig 2003-05-20 15:23:25.000000000 -0700
++++ strtoumax.c 2005-02-23 13:24:30.000000000 -0800
+@@ -37,6 +37,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdlib/strtoumax.c,v 1.8 2002/09/06 11:23:59 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <ctype.h>
+ #include <errno.h>
+ #include <stdlib.h>
+@@ -49,7 +51,8 @@
+ * alphabets and digits are each contiguous.
+ */
+ uintmax_t
+-strtoumax(const char * __restrict nptr, char ** __restrict endptr, int base)
++strtoumax_l(const char * __restrict nptr, char ** __restrict endptr, int base,
++ locale_t loc)
+ {
+ const char *s;
+ uintmax_t acc;
+@@ -57,13 +60,14 @@
+ uintmax_t cutoff;
+ int neg, any, cutlim;
+
++ NORMALIZE_LOCALE(loc);
+ /*
+ * See strtoimax for comments as to the logic used.
+ */
+ s = nptr;
+ do {
+ c = *s++;
+- } while (isspace((unsigned char)c));
++ } while (isspace_l((unsigned char)c, loc));
+ if (c == '-') {
+ neg = 1;
+ c = *s++;
+@@ -117,3 +121,9 @@
+ *endptr = (char *)(any ? s - 1 : nptr);
+ return (acc);
+ }
++
++uintmax_t
++strtoumax(const char * __restrict nptr, char ** __restrict endptr, int base)
++{
++ return strtoumax_l(nptr, endptr, base, __current_locale());
++}
--- /dev/null
+--- strtouq.c.orig 2003-05-20 15:23:25.000000000 -0700
++++ strtouq.c 2005-02-23 18:29:05.000000000 -0800
+@@ -37,6 +37,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdlib/strtouq.c,v 1.11 2002/08/15 09:25:04 robert Exp $");
+
++#include "xlocale_private.h"
++
+ #include <sys/types.h>
+
+ #include <stdlib.h>
+@@ -48,5 +50,13 @@
+ strtouq(const char *nptr, char **endptr, int base)
+ {
+
+- return strtoull(nptr, endptr, base);
++ return strtoull_l(nptr, endptr, base, __current_locale());
++}
++
++u_quad_t
++strtouq_l(const char *nptr, char **endptr, int base, locale_t loc)
++{
++
++ /* no need to call NORMALIZE_LOCALE(loc) because strtoull_l will */
++ return strtoull_l(nptr, endptr, base, loc);
+ }
--- /dev/null
+--- system.c.orig 2003-05-20 15:23:25.000000000 -0700
++++ system.c 2004-08-31 12:00:07.000000000 -0700
+@@ -58,8 +58,12 @@
+ struct sigaction ign, intact, quitact;
+ sigset_t newsigblock, oldsigblock;
+
+- if (!command) /* just checking... */
+- return(1);
++ if (!command) { /* just checking... */
++ if (access(_PATH_BSHELL, F_OK) == -1) /* if no sh or no access */
++ return(0);
++ else
++ return(1);
++ }
+
+ /*
+ * Ignore SIGINT and SIGQUIT, block SIGCHLD. Remember to save
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" OpenBSD: tsearch.3,v 1.2 1998/06/21 22:13:49 millert Exp
-.\" $FreeBSD: src/lib/libc/stdlib/tsearch.3,v 1.12 2002/12/19 09:40:24 ru Exp $
+.\" $FreeBSD: src/lib/libc/stdlib/tsearch.3,v 1.13 2004/07/02 23:52:12 ru Exp $
.\"
.Dd June 15, 1997
.Dt TSEARCH 3
and
.Fn twalk
functions manage binary search trees based on algorithms T and D
-from Knuth (6.2.2). The comparison function passed in by
+from Knuth (6.2.2).
+The comparison function passed in by
the user has the same style of return values as
.Xr strcmp 3 .
.Pp
.Fn tfind
except that if no match is found,
.Fa key
-is inserted into the tree and a pointer to it is returned. If
+is inserted into the tree and a pointer to it is returned.
+If
.Fa rootp
points to a NULL value a new binary search tree is created.
.Pp
.include "Makefile.fbsd_begin"
FBSDMISRCS=_Exit_.c abort.c abs.c atexit.c atof.c atoi.c atol.c atoll.c \
bsearch.c div.c exit.c getenv.c getopt.c getopt_long.c getsubopt.c \
- hcreate.c heapsort.c imaxabs.c imaxdiv.c insque.c labs.c \
+ grantpt.c hcreate.c heapsort.c imaxabs.c imaxdiv.c insque.c labs.c \
ldiv.c llabs.c lldiv.c lsearch.c merge.c putenv.c qsort.c qsort_r.c \
radixsort.c rand.c random.c reallocf.c realpath.c remque.c setenv.c \
strfmon.c strhash.c strtoimax.c strtol.c strtoll.c strtoq.c strtoul.c \
twalk.c
FBSDHDRS= atexit.h
.include "Makefile.fbsd_end"
+PRIV_INSTHDRS += ${SYMROOT}/atexit.h
+
+.include "Makefile.obsd_begin"
+OBSDMISRCS=ecvt.c gcvt.c
+.include "Makefile.obsd_end"
+
+UNIX03SRCS+= putenv.c setenv.c
.if ${LIB} == "c"
MAN3+= a64l.3
+MAN3+= strtod_l.3 strtol_l.3
.include "Makefile.fbsd_begin"
FBSDMAN3= abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 bsearch.3 \
- div.3 exit.3 getenv.3 getopt.3 getopt_long.3 getsubopt.3 \
+ div.3 exit.3 getenv.3 getopt.3 getopt_long.3 getsubopt.3 grantpt.3 \
hcreate.3 imaxabs.3 imaxdiv.3 insque.3 labs.3 ldiv.3 llabs.3 lldiv.3 \
lsearch.3 memory.3 qsort.3 radixsort.3 rand.3 random.3 realpath.3 \
strfmon.3 strtod.3 strtol.3 strtoul.3 system.3 tsearch.3
.include "Makefile.fbsd_end"
+.include "Makefile.obsd_begin"
+OBSDMAN3= ecvt.3
+.include "Makefile.obsd_end"
+
MLINKS+=a64l.3 l64a.3
+MLINKS+=atof.3 atof_l.3
+MLINKS+=atoi.3 atoi_l.3
MLINKS+=atol.3 atoll.3
+MLINKS+=atol.3 atol_l.3 atol.3 atoll_l.3
+MLINKS+=ecvt.3 fcvt.3
+MLINKS+=ecvt.3 gcvt.3
MLINKS+=exit.3 _Exit.3
MLINKS+=getenv.3 putenv.3 getenv.3 setenv.3 getenv.3 unsetenv.3
+MLINKS+=grantpt.3 posix_openpt.3 grantpt.3 ptsname.3 grantpt.3 unlockpt.3
MLINKS+=hcreate.3 hdestroy.3 hcreate.3 hsearch.3
MLINKS+=insque.3 remque.3
MLINKS+=lsearch.3 lfind.3
MLINKS+=rand.3 rand_r.3 rand.3 srand.3 rand.3 sranddev.3
MLINKS+=random.3 initstate.3 random.3 setstate.3 random.3 srandom.3 \
random.3 srandomdev.3
+MLINKS+=strfmon.3 strfmon_l.3
MLINKS+=strtod.3 strtof.3 strtod.3 strtold.3
+MLINKS+=strtod_l.3 strtof_l.3 strtod_l.3 strtold_l.3
MLINKS+=strtol.3 strtoll.3 strtol.3 strtoq.3 strtol.3 strtoimax.3
+MLINKS+=strtol_l.3 strtoll_l.3 strtol_l.3 strtoimax_l.3 strtol_l.3 strtoq_l.3 \
+ strtol_l.3 strtoull_l.3 strtol_l.3 strtoumax_l.3 strtol_l.3 strtouq_l.3 \
+ strtol_l.3 strtoul_l.3
MLINKS+=strtoul.3 strtoull.3 strtoul.3 strtouq.3 strtoul.3 strtoumax.3
MLINKS+=tsearch.3 tdelete.3 tsearch.3 tfind.3 tsearch.3 twalk.3
.endif
--- /dev/null
+.\" $OpenBSD: ecvt.3,v 1.7 2004/01/25 14:48:32 jmc Exp $
+.\"
+.\" Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.\" Sponsored in part by the Defense Advanced Research Projects
+.\" Agency (DARPA) and Air Force Research Laboratory, Air Force
+.\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
+.\"
+.Dd December 1, 2002
+.Dt ECVT 3
+.Os
+.Sh NAME
+.Nm ecvt ,
+.Nm fcvt ,
+.Nm gcvt
+.Nd convert double to
+.Tn ASCII
+string
+.Sh SYNOPSIS
+.Fd #include <stdlib.h>
+.Ft char *
+.Fn ecvt "double value" "int ndigit" "int *decpt" "int *sign"
+.Ft char *
+.Fn fcvt "double value" "int ndigit" "int *decpt" "int *sign"
+.Ft char *
+.Fn gcvt "double value" "int ndigit" "char *buf"
+.Sh DESCRIPTION
+.Bf -symbolic
+These functions are provided for compatibility with legacy code.
+New code should use the
+.Xr snprintf 3
+function for improved safety and portability.
+.Ef
+.Pp
+The
+.Fn ecvt ,
+.Fn fcvt
+and
+.Fn gcvt
+functions convert the double precision floating-point number
+.Fa value
+to a NUL-terminated
+.Tn ASCII
+string.
+.Pp
+The
+.Fn ecvt
+function converts
+.Fa value
+to a NUL-terminated string of exactly
+.Fa ndigit
+digits and returns a pointer to that string.
+The result is padded with zeroes from left to right as needed.
+There are no leading zeroes unless
+.Fa value
+itself is 0.
+The least significant digit is rounded in an implementation-dependent manner.
+The position of the decimal point relative to the beginning of the string
+is stored in
+.Fa decpt .
+A negative value indicates that the decimal point is located
+to the left of the returned digits (this occurs when there is no
+whole number component to
+.Fa value ) .
+If
+.Fa value
+is zero, it is unspecified whether the integer pointed to by
+.Fa decpt
+will be 0 or 1.
+The decimal point itself is not included in the returned string.
+If the sign of the result is negative, the integer pointed to by
+.Fa sign
+is non-zero; otherwise, it is 0.
+.Pp
+If the converted value is out of range or is not representable,
+the contents of the returned string are unspecified.
+.Pp
+The
+.Fn fcvt
+function is identical to
+.Fn ecvt
+with the exception that
+.Fa ndigit
+specifies the number of digits after the decimal point (zero-padded as
+needed).
+.Pp
+The
+.Fn gcvt
+function converts
+.Fa value
+to a NUL-terminated string similar to the %g
+.Xr printf 3
+format specifier and stores the result in
+.Fa buf .
+It produces
+.Fa ndigit
+significant digits similar to the %f
+.Xr printf 3
+format specifier where possible.
+If
+.Fa ndigit
+does allow sufficient precision, the result is stored in
+exponential notation similar to the %e
+.Xr printf 3
+format specifier.
+If
+.Fa value
+is less than zero,
+.Fa buf
+will be prefixed with a minus sign.
+A decimal point is included in the returned string if
+.Fa value
+is not a whole number.
+Unlike the
+.Fn ecvt
+and
+.Fn fcvt
+functions,
+.Fa buf
+is not zero-padded.
+.Sh RETURN VALUES
+The
+.Fn ecvt ,
+.Fn fcvt
+and
+.Fn gcvt
+functions return a NUL-terminated string representation of
+.Fa value .
+.Sh WARNINGS
+The
+.Fn ecvt
+and
+.Fn fcvt
+functions return a pointer to internal storage space that will be
+overwritten by subsequent calls to either function.
+.Pp
+The maximum possible precision of the return value is limited by the
+precision of a double and may not be the same on all architectures.
+.Pp
+The
+.Xr snprintf 3
+function is preferred over these functions for new code.
+.Sh SEE ALSO
+.Xr printf 3 ,
+.Xr strtod 3
+.Sh STANDARDS
+The
+.Fn ecvt ,
+.Fn fcvt
+and
+.Fn gcvt
+functions conform to
+.St -p1003.1-2001 .
--- /dev/null
+--- ecvt.3.orig Thu Jul 8 16:06:45 2004
++++ ecvt.3 Thu Jul 8 17:54:49 2004
+@@ -31,9 +31,9 @@
+ .Sh SYNOPSIS
+ .Fd #include <stdlib.h>
+ .Ft char *
+-.Fn ecvt "double value" "int ndigit" "int *decpt" "int *sign"
++.Fn ecvt "double value" "int ndigit" "int * restrict decpt" "int * restrict sign"
+ .Ft char *
+-.Fn fcvt "double value" "int ndigit" "int *decpt" "int *sign"
++.Fn fcvt "double value" "int ndigit" "int * restrict decpt" "int * restrict sign"
+ .Ft char *
+ .Fn gcvt "double value" "int ndigit" "char *buf"
+ .Sh DESCRIPTION
--- /dev/null
+/* $OpenBSD: ecvt.c,v 1.3 2003/06/17 21:56:24 millert Exp $ */
+
+/*
+ * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$OpenBSD: ecvt.c,v 1.3 2003/06/17 21:56:24 millert Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+extern char *__dtoa(double, int, int, int *, int *, char **);
+static char *__cvt(double, int, int *, int *, int, int);
+
+static char *
+__cvt(double value, int ndigit, int *decpt, int *sign, int fmode, int pad)
+{
+ static char *s;
+ char *p, *rve;
+ size_t siz;
+
+ if (ndigit == 0) {
+ *sign = value < 0.0;
+ *decpt = 0;
+ return ("");
+ }
+
+ if (s) {
+ free(s);
+ s = NULL;
+ }
+
+ if (ndigit < 0)
+ siz = -ndigit + 1;
+ else
+ siz = ndigit + 1;
+
+
+ /* __dtoa() doesn't allocate space for 0 so we do it by hand */
+ if (value == 0.0) {
+ *decpt = 1 - fmode; /* 1 for 'e', 0 for 'f' */
+ *sign = 0;
+ if ((rve = s = (char *)malloc(siz)) == NULL)
+ return(NULL);
+ *rve++ = '0';
+ *rve = '\0';
+ } else {
+ p = __dtoa(value, fmode + 2, ndigit, decpt, sign, &rve);
+ if (*decpt == 9999) {
+ /* Nan or Infinity */
+ *decpt = 0;
+ return(p);
+ }
+ /* make a local copy and adjust rve to be in terms of s */
+ if (pad && fmode)
+ siz += *decpt;
+ if ((s = (char *)malloc(siz)) == NULL)
+ return(NULL);
+ (void) strlcpy(s, p, siz);
+ rve = s + (rve - p);
+ }
+
+ /* Add trailing zeros (unless we got NaN or Inf) */
+ if (pad && *decpt != 9999) {
+ siz -= rve - s;
+ while (--siz)
+ *rve++ = '0';
+ *rve = '\0';
+ }
+
+ return(s);
+}
+
+char *
+ecvt(double value, int ndigit, int *decpt, int *sign)
+{
+ return(__cvt(value, ndigit, decpt, sign, 0, 1));
+}
+
+char *
+fcvt(double value, int ndigit, int *decpt, int *sign)
+{
+ return(__cvt(value, ndigit, decpt, sign, 1, 1));
+}
--- /dev/null
+--- ecvt.c.orig Thu Jul 8 16:06:45 2004
++++ ecvt.c Fri Jul 9 12:23:51 2004
+@@ -20,6 +20,7 @@
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ */
+
++#include <sys/cdefs.h>
+ #if defined(LIBC_SCCS) && !defined(lint)
+ static char rcsid[] = "$OpenBSD: ecvt.c,v 1.3 2003/06/17 21:56:24 millert Exp $";
+ #endif /* LIBC_SCCS and not lint */
+@@ -29,10 +30,11 @@
+ #include <string.h>
+
+ extern char *__dtoa(double, int, int, int *, int *, char **);
++extern void __freedtoa(char *); /* special gdtoa free function */
+ static char *__cvt(double, int, int *, int *, int, int);
+
+ static char *
+-__cvt(double value, int ndigit, int *decpt, int *sign, int fmode, int pad)
++__cvt(double value, int ndigit, int * __restrict decpt, int * __restrict sign, int fmode, int pad)
+ {
+ static char *s;
+ char *p, *rve;
+@@ -68,15 +70,20 @@
+ if (*decpt == 9999) {
+ /* Nan or Infinity */
+ *decpt = 0;
+- return(p);
++ rve = (*p == 'N') ? "nan" : "inf";
++ __freedtoa(p);
++ return(rve);
+ }
+ /* make a local copy and adjust rve to be in terms of s */
+ if (pad && fmode)
+ siz += *decpt;
+- if ((s = (char *)malloc(siz)) == NULL)
++ if ((s = (char *)malloc(siz)) == NULL) {
++ __freedtoa(p);
+ return(NULL);
++ }
+ (void) strlcpy(s, p, siz);
+ rve = s + (rve - p);
++ __freedtoa(p);
+ }
+
+ /* Add trailing zeros (unless we got NaN or Inf) */
+@@ -91,13 +98,13 @@
+ }
+
+ char *
+-ecvt(double value, int ndigit, int *decpt, int *sign)
++ecvt(double value, int ndigit, int * __restrict decpt, int * __restrict sign)
+ {
+ return(__cvt(value, ndigit, decpt, sign, 0, 1));
+ }
+
+ char *
+-fcvt(double value, int ndigit, int *decpt, int *sign)
++fcvt(double value, int ndigit, int * __restrict decpt, int * __restrict sign)
+ {
+ return(__cvt(value, ndigit, decpt, sign, 1, 1));
+ }
--- /dev/null
+/* $OpenBSD: gcvt.c,v 1.5 2003/06/17 21:56:24 millert Exp $ */
+
+/*
+ * Copyright (c) 2002, 2003 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$OpenBSD: gcvt.c,v 1.5 2003/06/17 21:56:24 millert Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+extern char *__dtoa(double, int, int, int *, int *, char **);
+
+char *
+gcvt(double value, int ndigit, char *buf)
+{
+ char *digits, *dst, *src;
+ int i, decpt, sign;
+
+ if (ndigit == 0) {
+ buf[0] = '\0';
+ return (buf);
+ }
+
+ digits = __dtoa(value, 2, ndigit, &decpt, &sign, NULL);
+ if (decpt == 9999) {
+ /* Infinity or NaN, assume buffer is at least ndigit long. */
+ strlcpy(buf, digits, ndigit + 1);
+ return (buf);
+ }
+
+ dst = buf;
+ if (sign)
+ *dst++ = '-';
+
+ if (decpt < 0 || decpt > ndigit) {
+ /* exponential format */
+ if (--decpt < 0) {
+ sign = 1;
+ decpt = -decpt;
+ } else
+ sign = 0;
+ for (src = digits; *src != '\0'; )
+ *dst++ = *src++;
+ *dst++ = 'e';
+ if (sign)
+ *dst++ = '-';
+ else
+ *dst++ = '+';
+ if (decpt < 10) {
+ *dst++ = '0';
+ *dst++ = '0' + decpt;
+ *dst = '\0';
+ } else {
+ /* XXX - optimize */
+ for (sign = decpt, i = 0; (sign /= 10) != 0; i++)
+ sign /= 10;
+ while (decpt != 0) {
+ dst[i--] = '0' + decpt % 10;
+ decpt /= 10;
+ }
+ }
+ } else {
+ /* standard format */
+ for (i = 0, src = digits; i < decpt; i++) {
+ if (*src != '\0')
+ *dst++ = *src++;
+ else
+ *dst++ = '0';
+ }
+ if (*src != '\0') {
+ *dst++ = '.'; /* XXX - locale-specific (LC_NUMERIC) */
+ for (i = decpt; digits[i] != '\0'; i++) {
+ *dst++ = digits[i];
+ }
+ }
+ *dst = '\0';
+ }
+ return (buf);
+}
--- /dev/null
+--- gcvt.c.orig Thu Jul 8 16:06:45 2004
++++ gcvt.c Fri Jul 9 12:16:25 2004
+@@ -27,14 +27,17 @@
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
++#include <locale.h>
+
+ extern char *__dtoa(double, int, int, int *, int *, char **);
++extern void __freedtoa(char *);
+
+ char *
+ gcvt(double value, int ndigit, char *buf)
+ {
+ char *digits, *dst, *src;
+ int i, decpt, sign;
++ char *decimal_point = localeconv()->decimal_point;
+
+ if (ndigit == 0) {
+ buf[0] = '\0';
+@@ -43,8 +46,12 @@
+
+ digits = __dtoa(value, 2, ndigit, &decpt, &sign, NULL);
+ if (decpt == 9999) {
+- /* Infinity or NaN, assume buffer is at least ndigit long. */
+- strlcpy(buf, digits, ndigit + 1);
++ /* Infinity or NaN, assume buffer is long enough. */
++ dst = buf;
++ if (sign)
++ *dst++ = '-';
++ strcpy(dst, (*digits == 'N') ? "nan" : "inf");
++ __freedtoa(digits);
+ return (buf);
+ }
+
+@@ -59,7 +66,10 @@
+ decpt = -decpt;
+ } else
+ sign = 0;
+- for (src = digits; *src != '\0'; )
++ src = digits;
++ *dst++ = *src++;
++ dst = stpcpy(dst, decimal_point);
++ while (*src != '\0')
+ *dst++ = *src++;
+ *dst++ = 'e';
+ if (sign)
+@@ -72,8 +82,8 @@
+ *dst = '\0';
+ } else {
+ /* XXX - optimize */
+- for (sign = decpt, i = 0; (sign /= 10) != 0; i++)
+- sign /= 10;
++ for (sign = decpt, i = 0; (sign /= 10) != 0; i++) {}
++ dst[i + 1] = '\0';
+ while (decpt != 0) {
+ dst[i--] = '0' + decpt % 10;
+ decpt /= 10;
+@@ -88,12 +98,15 @@
+ *dst++ = '0';
+ }
+ if (*src != '\0') {
+- *dst++ = '.'; /* XXX - locale-specific (LC_NUMERIC) */
++ if (src == digits) /* need leading zero */
++ *dst++ = '0';
++ dst = stpcpy(dst, decimal_point);
+ for (i = decpt; digits[i] != '\0'; i++) {
+ *dst++ = digits[i];
+ }
+ }
+ *dst = '\0';
+ }
++ __freedtoa(digits);
+ return (buf);
+ }
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+.\" Copyright (c) 1990, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" the American National Standards Committee X3, on Information
+.\" Processing Systems.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" @(#)strtod.3 8.1 (Berkeley) 6/4/93
+.\" $FreeBSD: src/lib/libc/stdlib/strtod.3,v 1.19 2003/05/22 13:02:28 ru Exp $
+.\"
+.Dd March 11, 2005
+.Dt STRTOD_L 3
+.Os
+.Sh NAME
+.Nm strtod_l , strtof_l , strtold_l
+.Nd convert
+.Tn ASCII
+string to floating point
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdlib.h
+.In xlocale.h
+.Ft double
+.Fn strtod_l "const char * restrict nptr" "char ** restrict endptr" "locale_t loc"
+.Ft float
+.Fn strtof_l "const char * restrict nptr" "char ** restrict endptr" "locale_t loc"
+.Ft "long double"
+.Fn strtold_l "const char * restrict nptr" "char ** restrict endptr" "locale_t loc"
+.Sh DESCRIPTION
+The
+.Fn strtod_l ,
+.Fn strtof_l ,
+and
+.Fn strtold_l
+functions are extended locale versions of the
+.Fn strtod ,
+.Fn strtof ,
+and
+.Fn strtold
+functions, respectively.
+Refer to their manual pages for details.
+Also, see
+.Xr xlocale 3 for more information about extended locales.
+.Sh SEE ALSO
+.Xr strtod 3 ,
+.Xr xlocale 3
--- /dev/null
+.\" Copyright (c) 1990, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Chris Torek and the American National Standards Committee X3,
+.\" on Information Processing Systems.
+.\"
+.\" 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.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.\" @(#)strtol.3 8.1 (Berkeley) 6/4/93
+.\" $FreeBSD: src/lib/libc/stdlib/strtol.3,v 1.19 2002/10/10 04:31:57 tjr Exp $
+.\"
+.Dd March 11, 2005
+.Dt STRTOL_L 3
+.Os
+.Sh NAME
+.Nm strtol_l , strtoll_l , strtoimax_l , strtoq_l ,
+.Nm strtoul_l , strtoull_l , strtoumax_l , strtouq_l
+.Nd "convert a string value to a"
+.Vt long , "long long" , intmax_t , quad_t
+.Vt "unsigned long" , "unsigned long long" , uintmax_t ,
+or
+.Vt u_quad_t
+integer
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdlib.h
+.In limits.h
+.In xlocale.h
+.Ft long
+.Fn strtol_l "const char * restrict nptr" "char ** restrict endptr" "int base" "locale_t loc"
+.Ft long long
+.Fn strtoll_l "const char * restrict nptr" "char ** restrict endptr" "int base" "locale_t loc"
+.Ft "unsigned long"
+.Fn strtoul_l "const char * restrict nptr" "char ** restrict endptr" "int base" "locale_t loc"
+.Ft "unsigned long long"
+.Fn strtoull_l "const char * restrict nptr" "char ** restrict endptr" "int base" "locale_t loc"
+.In inttypes.h
+.In xlocale.h
+.Ft intmax_t
+.Fn strtoimax_l "const char * restrict nptr" "char ** restrict endptr" "int base" "locale_t loc"
+.Ft uintmax_t
+.Fn strtoumax_l "const char * restrict nptr" "char ** restrict endptr" "int base" "locale_t loc"
+.In sys/types.h
+.In stdlib.h
+.In limits.h
+.In xlocale.h
+.Ft quad_t
+.Fn strtoq_l "const char *nptr" "char **endptr" "int base" "locale_t loc"
+.Ft u_quad_t
+.Fn strtouq_l "const char *nptr" "char **endptr" "int base" "locale_t loc"
+.Sh DESCRIPTION
+The
+.Fn strtol_l ,
+.Fn strtoll_l ,
+.Fn strtoimax_l ,
+.Fn strtoq_l ,
+.Fn strtoul_l ,
+.Fn strtoull_l ,
+.Fn strtoumax_l ,
+and
+.Fn strtouq_l
+functions are extended locale versions of the
+.Fn strtol ,
+.Fn strtoll ,
+.Fn strtoimax ,
+.Fn strtoq ,
+.Fn strtoul ,
+.Fn strtoull ,
+.Fn strtoumax ,
+and
+.Fn strtouq
+functions, respectively.
+Refer to their manual pages for details.
+Also, see
+.Xr xlocale 3 for more information about extended locales.
+.Sh SEE ALSO
+.Xr strtol 3 ,
+.Xr strtoul 3 ,
+.Xr xlocale 3
/*
** This file is in the public domain, so clarified as of
-** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov).
+** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov).
*/
#include <sys/cdefs.h>
#ifndef lint
#ifndef NOID
-static char elsieid[] __unused = "@(#)asctime.c 7.7";
+static char elsieid[] __unused = "@(#)asctime.c 7.9";
#endif /* !defined NOID */
#endif /* !defined lint */
-__FBSDID("$FreeBSD: src/lib/libc/stdtime/asctime.c,v 1.11 2003/02/16 17:29:11 nectar Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdtime/asctime.c,v 1.12 2004/06/14 10:31:52 stefanf Exp $");
/*LINTLIBRARY*/
#include "tzfile.h"
/*
-** A la X3J11, with core dump avoidance.
+** A la ISO/IEC 9945-1, ANSI/IEEE Std 1003.1, Second Edition, 1996-07-12.
*/
-
-char *
-asctime(timeptr)
-const struct tm * timeptr;
-{
- static char result[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) +
- 3 + 2 + 1 + 1];
- return(asctime_r(timeptr, result));
-}
-
char *
-asctime_r(timeptr, result)
+asctime_r(timeptr, buf)
const struct tm * timeptr;
-char *result;
+char * buf;
{
static const char wday_name[][3] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
- /*
- ** Big enough for something such as
- ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n
- ** (two three-character abbreviations, five strings denoting integers,
- ** three explicit spaces, two explicit colons, a newline,
- ** and a trailing ASCII nul).
- */
const char * wn;
const char * mn;
** "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n"
** Since the .2 in 02.2d is ignored, we drop it.
*/
- (void) sprintf(result, "%.3s %.3s%3d %02d:%02d:%02d %d\n",
+ (void) sprintf(buf, "%.3s %.3s%3d %02d:%02d:%02d %d\n",
wn, mn,
timeptr->tm_mday, timeptr->tm_hour,
timeptr->tm_min, timeptr->tm_sec,
TM_YEAR_BASE + timeptr->tm_year);
- return result;
+ return buf;
+}
+
+/*
+** A la X3J11, with core dump avoidance.
+*/
+
+char *
+asctime(timeptr)
+const struct tm * timeptr;
+{
+ /*
+ ** Big enough for something such as
+ ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n
+ ** (two three-character abbreviations, five strings denoting integers,
+ ** three explicit spaces, two explicit colons, a newline,
+ ** and a trailing ASCII nul).
+ */
+ static char result[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) +
+ 3 + 2 + 1 + 1];
+
+ return asctime_r(timeptr, result);
}
.\" SUCH DAMAGE.
.\"
.\" From: @(#)ctime.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/stdtime/ctime.3,v 1.20 2002/12/19 09:33:34 ru Exp $
+.\" $FreeBSD: src/lib/libc/stdtime/ctime.3,v 1.22 2004/07/02 23:52:12 ru Exp $
.\"
.Dd January 2, 1999
.Dt CTIME 3
expressed in seconds.
.Pp
External declarations as well as the tm structure definition are in the
-.Aq Pa time.h
+.In time.h
include file.
The tm structure includes at least the following fields:
.Bd -literal -offset indent
The C Standard provides no mechanism for a program to modify its current
local timezone setting, and the
.Tn POSIX Ns No \&-standard
-method is not reentrant. (However, thread-safe implementations are provided
+method is not reentrant.
+(However, thread-safe implementations are provided
in the
.Tn POSIX
threaded environment.)
#include <sys/cdefs.h>
#ifndef lint
#ifndef NOID
-static char elsieid[] __unused = "@(#)difftime.c 7.7";
+static char elsieid[] __unused = "@(#)difftime.c 7.9";
#endif /* !defined NOID */
#endif /* !defined lint */
-__FBSDID("$FreeBSD: src/lib/libc/stdtime/difftime.c,v 1.7 2003/02/16 17:29:11 nectar Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdtime/difftime.c,v 1.8 2004/06/14 10:31:52 stefanf Exp $");
/*LINTLIBRARY*/
time_t delta;
time_t hibit;
- if (sizeof(time_t) < sizeof(double))
- return (double) time1 - (double) time0;
- if (sizeof(time_t) < sizeof(long_double))
- return (long_double) time1 - (long_double) time0;
+ {
+ time_t tt;
+ double d;
+ long_double ld;
+
+ if (sizeof tt < sizeof d)
+ return (double) time1 - (double) time0;
+ if (sizeof tt < sizeof ld)
+ return (long_double) time1 - (long_double) time0;
+ }
if (time1 < time0)
return -difftime(time0, time1);
/*
/*
** This file is in the public domain, so clarified as of
-** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov).
+** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov).
*/
#include <sys/cdefs.h>
#ifndef lint
#ifndef NOID
-static char elsieid[] __unused = "@(#)localtime.c 7.57";
+static char elsieid[] __unused = "@(#)localtime.c 7.78";
#endif /* !defined NOID */
#endif /* !defined lint */
-__FBSDID("$FreeBSD: src/lib/libc/stdtime/localtime.c,v 1.36 2003/02/16 17:29:11 nectar Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdtime/localtime.c,v 1.40 2004/08/24 00:15:37 peter Exp $");
/*
** Leap second handling from Bradley White (bww@k.gp.cs.cmu.edu).
static char wildabbr[] = "WILDABBR";
-static const char gmt[] = "GMT";
+/*
+ * In June 2004 it was decided UTC was a more appropriate default time
+ * zone than GMT.
+ */
+
+static const char gmt[] = "UTC";
+
+/*
+** The DST rules to use if TZ has no rules and we can't load TZDEFRULES.
+** We default to US rules as of 1999-08-17.
+** POSIX 1003.1 section 8.1.1 says that the default DST rules are
+** implementation dependent; for historical reasons, US rules are a
+** common default.
+*/
+#ifndef TZDEFRULESTRING
+#define TZDEFRULESTRING ",M4.1.0,M10.5.0"
+#endif /* !defined TZDEFDST */
struct ttinfo { /* time type information */
- long tt_gmtoff; /* GMT offset in seconds */
+ long tt_gmtoff; /* UTC offset in seconds */
int tt_isdst; /* used to set tm_isdst */
int tt_abbrind; /* abbreviation list index */
int tt_ttisstd; /* TRUE if transition is std time */
- int tt_ttisgmt; /* TRUE if transition is GMT */
+ int tt_ttisgmt; /* TRUE if transition is UTC */
};
struct lsinfo { /* leap second information */
void(*funcp) (const time_t *,
long, struct tm*),
long offset, int * okayp);
+static time_t time2sub(struct tm *tmp,
+ void(*funcp) (const time_t *,
+ long, struct tm*),
+ long offset, int * okayp, int do_norm_secs);
static void timesub(const time_t * timep, long offset,
const struct state * sp, struct tm * tmp);
static int tmcomp(const struct tm * atmp,
}
{
struct tzhead * tzhp;
- char buf[sizeof *sp + sizeof *tzhp];
+ union {
+ struct tzhead tzhead;
+ char buf[sizeof *sp + sizeof *tzhp];
+ } u;
int ttisstdcnt;
int ttisgmtcnt;
- i = _read(fid, buf, sizeof buf);
+ i = _read(fid, u.buf, sizeof u.buf);
if (_close(fid) != 0)
return -1;
- p = buf;
- p += (sizeof tzhp->tzh_magic) + (sizeof tzhp->tzh_reserved);
- ttisstdcnt = (int) detzcode(p);
- p += 4;
- ttisgmtcnt = (int) detzcode(p);
- p += 4;
- sp->leapcnt = (int) detzcode(p);
- p += 4;
- sp->timecnt = (int) detzcode(p);
- p += 4;
- sp->typecnt = (int) detzcode(p);
- p += 4;
- sp->charcnt = (int) detzcode(p);
- p += 4;
+ ttisstdcnt = (int) detzcode(u.tzhead.tzh_ttisstdcnt);
+ ttisgmtcnt = (int) detzcode(u.tzhead.tzh_ttisgmtcnt);
+ sp->leapcnt = (int) detzcode(u.tzhead.tzh_leapcnt);
+ sp->timecnt = (int) detzcode(u.tzhead.tzh_timecnt);
+ sp->typecnt = (int) detzcode(u.tzhead.tzh_typecnt);
+ sp->charcnt = (int) detzcode(u.tzhead.tzh_charcnt);
+ p = u.tzhead.tzh_charcnt + sizeof u.tzhead.tzh_charcnt;
if (sp->leapcnt < 0 || sp->leapcnt > TZ_MAX_LEAPS ||
sp->typecnt <= 0 || sp->typecnt > TZ_MAX_TYPES ||
sp->timecnt < 0 || sp->timecnt > TZ_MAX_TIMES ||
(ttisstdcnt != sp->typecnt && ttisstdcnt != 0) ||
(ttisgmtcnt != sp->typecnt && ttisgmtcnt != 0))
return -1;
- if (i - (p - buf) < sp->timecnt * 4 + /* ats */
+ if (i - (p - u.buf) < sp->timecnt * 4 + /* ats */
sp->timecnt + /* types */
sp->typecnt * (4 + 2) + /* ttinfos */
sp->charcnt + /* chars */
}
/*
-** Given the Epoch-relative time of January 1, 00:00:00 GMT, in a year, the
-** year, a rule, and the offset from GMT at the time that rule takes effect,
+** Given the Epoch-relative time of January 1, 00:00:00 UTC, in a year, the
+** year, a rule, and the offset from UTC at the time that rule takes effect,
** calculate the Epoch-relative time that rule takes effect.
*/
}
/*
- ** "value" is the Epoch-relative time of 00:00:00 GMT on the day in
+ ** "value" is the Epoch-relative time of 00:00:00 UTC on the day in
** question. To get the Epoch-relative time of the specified local
** time on that day, add the transition time and the current offset
- ** from GMT.
+ ** from UTC.
*/
return value + rulep->r_time + offset;
}
if (name == NULL)
return -1;
} else dstoffset = stdoffset - SECSPERHOUR;
+ if (*name == '\0' && load_result != 0)
+ name = TZDEFRULESTRING;
if (*name == ',' || *name == ';') {
struct rule start;
struct rule end;
if (*name != '\0')
return -1;
- if (load_result != 0)
- return -1;
/*
** Initial values of theirstdoffset and theirdstoffset.
*/
sp->ttis[1].tt_gmtoff = -dstoffset;
sp->ttis[1].tt_isdst = TRUE;
sp->ttis[1].tt_abbrind = stdlen + 1;
+ sp->typecnt = 2;
}
} else {
dstlen = 0;
sp->charcnt = stdlen + 1;
if (dstlen != 0)
sp->charcnt += dstlen + 1;
- if (sp->charcnt > sizeof sp->chars)
+ if ((size_t) sp->charcnt > sizeof sp->chars)
return -1;
cp = sp->chars;
(void) strncpy(cp, stdname, stdlen);
return;
}
- if (lcl_is_set > 0 && strcmp(lcl_TZname, name) == 0)
+ if (lcl_is_set > 0 && strcmp(lcl_TZname, name) == 0)
return;
- lcl_is_set = (strlen(name) < sizeof(lcl_TZname));
+ lcl_is_set = strlen(name) < sizeof lcl_TZname;
if (lcl_is_set)
(void) strcpy(lcl_TZname, name);
*/
lclptr->leapcnt = 0; /* so, we're off a little */
lclptr->timecnt = 0;
+ lclptr->typecnt = 0;
+ lclptr->ttis[0].tt_isdst = 0;
lclptr->ttis[0].tt_gmtoff = 0;
lclptr->ttis[0].tt_abbrind = 0;
(void) strcpy(lclptr->chars, gmt);
#endif /* defined TM_ZONE */
}
-struct tm *
-localtime_r(timep, p_tm)
-const time_t * const timep;
-struct tm *p_tm;
-{
- _MUTEX_LOCK(&lcl_mutex);
- tzset_basic();
- localsub(timep, 0L, p_tm);
- _MUTEX_UNLOCK(&lcl_mutex);
- return(p_tm);
-}
-
struct tm *
localtime(timep)
const time_t * const timep;
}
}
+/*
+** Re-entrant version of localtime.
+*/
+
+struct tm *
+localtime_r(timep, tm)
+const time_t * const timep;
+struct tm * tm;
+{
+ _MUTEX_LOCK(&lcl_mutex);
+ tzset_basic();
+ localsub(timep, 0L, tm);
+ _MUTEX_UNLOCK(&lcl_mutex);
+ return tm;
+}
+
/*
** gmtsub is to gmtime as localsub is to localtime.
*/
#ifdef TM_ZONE
/*
** Could get fancy here and deliver something such as
- ** "GMT+xxxx" or "GMT-xxxx" if offset is non-zero,
+ ** "UTC+xxxx" or "UTC-xxxx" if offset is non-zero,
** but this is no time for a treasure hunt.
*/
if (offset != 0)
}
}
+/*
+* Re-entrant version of gmtime.
+*/
+
struct tm *
-gmtime_r(const time_t * timep, struct tm * tm)
+gmtime_r(timep, tm)
+const time_t * const timep;
+struct tm * tm;
{
gmtsub(timep, 0L, tm);
- return(tm);
+ return tm;
}
#ifdef STD_INSPIRED
{
/*
** Section 4.12.3.2 of X3.159-1989 requires that
-** The ctime funciton converts the calendar time pointed to by timer
+** The ctime function converts the calendar time pointed to by timer
** to local time in the form of a string. It is equivalent to
** asctime(localtime(timer))
*/
char *
ctime_r(timep, buf)
const time_t * const timep;
-char *buf;
+char * buf;
{
- struct tm tm;
+ struct tm tm;
+
return asctime_r(localtime_r(timep, &tm), buf);
}
}
static time_t
-time2(tmp, funcp, offset, okayp)
+time2sub(tmp, funcp, offset, okayp, do_norm_secs)
struct tm * const tmp;
void (* const funcp)(const time_t*, long, struct tm*);
const long offset;
int * const okayp;
+const int do_norm_secs;
{
const struct state * sp;
int dir;
*okayp = FALSE;
yourtm = *tmp;
+ if (do_norm_secs) {
+ if (normalize_overflow(&yourtm.tm_min, &yourtm.tm_sec,
+ SECSPERMIN))
+ return WRONG;
+ }
if (normalize_overflow(&yourtm.tm_hour, &yourtm.tm_min, MINSPERHOUR))
return WRONG;
if (normalize_overflow(&yourtm.tm_mday, &yourtm.tm_hour, HOURSPERDAY))
}
if (increment_overflow(&yourtm.tm_year, -TM_YEAR_BASE))
return WRONG;
+ /* Don't go below 1900 for POLA */
+ if (yourtm.tm_year < 0)
+ return WRONG;
if (yourtm.tm_sec >= 0 && yourtm.tm_sec < SECSPERMIN)
saved_seconds = 0;
else if (yourtm.tm_year + TM_YEAR_BASE < EPOCH_YEAR) {
** It's okay to guess wrong since the guess
** gets checked.
*/
- /*
- ** The (void *) casts are the benefit of SunOS 3.3 on Sun 2's.
- */
- sp = (const struct state *)
- (((void *) funcp == (void *) localsub) ?
- lclptr : gmtptr);
+ sp = (funcp == localsub) ? lclptr : gmtptr;
#ifdef ALL_STATE
if (sp == NULL)
return WRONG;
return t;
}
+static time_t
+time2(tmp, funcp, offset, okayp)
+struct tm * const tmp;
+void (* const funcp)(const time_t*, long, struct tm*);
+const long offset;
+int * const okayp;
+{
+ time_t t;
+
+ /*
+ ** First try without normalization of seconds
+ ** (in case tm_sec contains a value associated with a leap second).
+ ** If that fails, try with normalization of seconds.
+ */
+ t = time2sub(tmp, funcp, offset, okayp, FALSE);
+ return *okayp ? t : time2sub(tmp, funcp, offset, okayp, TRUE);
+}
+
static time_t
time1(tmp, funcp, offset)
struct tm * const tmp;
time_t t;
const struct state * sp;
int samei, otheri;
+ int sameind, otherind;
+ int i;
+ int nseen;
+ int seen[TZ_MAX_TYPES];
+ int types[TZ_MAX_TYPES];
int okay;
if (tmp->tm_isdst > 1)
** We try to divine the type they started from and adjust to the
** type they need.
*/
- /*
- ** The (void *) casts are the benefit of SunOS 3.3 on Sun 2's.
- */
- sp = (const struct state *) (((void *) funcp == (void *) localsub) ?
- lclptr : gmtptr);
+ sp = (funcp == localsub) ? lclptr : gmtptr;
#ifdef ALL_STATE
if (sp == NULL)
return WRONG;
#endif /* defined ALL_STATE */
- for (samei = sp->typecnt - 1; samei >= 0; --samei) {
+ for (i = 0; i < sp->typecnt; ++i)
+ seen[i] = FALSE;
+ nseen = 0;
+ for (i = sp->timecnt - 1; i >= 0; --i)
+ if (!seen[sp->types[i]]) {
+ seen[sp->types[i]] = TRUE;
+ types[nseen++] = sp->types[i];
+ }
+ for (sameind = 0; sameind < nseen; ++sameind) {
+ samei = types[sameind];
if (sp->ttis[samei].tt_isdst != tmp->tm_isdst)
continue;
- for (otheri = sp->typecnt - 1; otheri >= 0; --otheri) {
+ for (otherind = 0; otherind < nseen; ++otherind) {
+ otheri = types[otherind];
if (sp->ttis[otheri].tt_isdst == tmp->tm_isdst)
continue;
tmp->tm_sec += sp->ttis[otheri].tt_gmtoff -
/*
** IEEE Std 1003.1-1988 (POSIX) legislates that 536457599
-** shall correspond to "Wed Dec 31 23:59:59 GMT 1986", which
+** shall correspond to "Wed Dec 31 23:59:59 UTC 1986", which
** is not the case if we are accounting for leap seconds.
** So, we provide the following conversion routines for use
** when exchanging timestamps with POSIX conforming systems.
---- localtime.c.orig Thu Oct 30 23:10:33 2003
-+++ localtime.c Thu Oct 30 23:25:06 2003
+--- localtime.c.orig 2004-11-01 23:24:08.000000000 -0800
++++ localtime.c 2004-11-05 23:43:55.000000000 -0800
@@ -24,6 +24,18 @@
#include <sys/stat.h>
#include <fcntl.h>
#include "private.h"
#include "un-namespace.h"
-@@ -119,6 +131,16 @@
+@@ -135,6 +147,16 @@
#define DAY_OF_YEAR 1 /* n - day of year */
#define MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d - month, week, day of week */
/*
** Prototypes for static functions.
*/
-@@ -138,6 +160,10 @@
+@@ -154,6 +176,10 @@
static int increment_overflow(int * number, int delta);
static int normalize_overflow(int * tensptr, int * unitsptr,
int base);
static void settzname(void);
static time_t time1(struct tm * tmp,
void(*funcp) (const time_t *,
-@@ -174,8 +200,13 @@
+@@ -194,8 +220,13 @@
#endif /* !defined TZ_STRLEN_MAX */
static char lcl_TZname[TZ_STRLEN_MAX + 1];
static pthread_mutex_t lcl_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t gmt_mutex = PTHREAD_MUTEX_INITIALIZER;
-@@ -203,6 +234,50 @@
- time_t altzone = 0;
+@@ -214,15 +245,62 @@
+
+ static struct tm tm;
+
++#define USG_COMPAT
++#define ALTZONE
+ #ifdef USG_COMPAT
+-time_t timezone = 0;
+ int daylight = 0;
++__private_extern__ void _st_set_timezone(long);
+ #endif /* defined USG_COMPAT */
+
+ #ifdef ALTZONE
+-time_t altzone = 0;
++__private_extern__ long __darwin_altzone = 0;
++#define altzone __darwin_altzone
#endif /* defined ALTZONE */
+#ifdef NOTIFY_TZ
static long
detzcode(codep)
const char * const codep;
-@@ -233,7 +308,7 @@
+@@ -246,14 +324,14 @@
+ tzname[1] = wildabbr;
+ #ifdef USG_COMPAT
+ daylight = 0;
+- timezone = 0;
++ _st_set_timezone(0);
+ #endif /* defined USG_COMPAT */
+ #ifdef ALTZONE
+ altzone = 0;
#endif /* defined ALTZONE */
#ifdef ALL_STATE
if (sp == NULL) {
return;
}
#endif /* defined ALL_STATE */
-@@ -266,6 +341,117 @@
+@@ -266,7 +344,7 @@
+ if (ttisp->tt_isdst)
+ daylight = 1;
+ if (i == 0 || !ttisp->tt_isdst)
+- timezone = -(ttisp->tt_gmtoff);
++ _st_set_timezone(-(ttisp->tt_gmtoff));
+ #endif /* defined USG_COMPAT */
+ #ifdef ALTZONE
+ if (i == 0 || ttisp->tt_isdst)
+@@ -286,6 +364,117 @@
}
}
static int
tzload(name, sp)
const char * name;
-@@ -275,6 +461,9 @@
+@@ -295,6 +484,9 @@
int i;
int fid;
/* XXX The following is from OpenBSD, and I'm not sure it is correct */
if (name != NULL && issetugid() != 0)
if ((name[0] == ':' && name[1] == '/') ||
-@@ -292,7 +481,15 @@
+@@ -312,7 +504,15 @@
** to hold the longest file name string that the implementation
** guarantees can be opened."
*/
if (name[0] == ':')
++name;
-@@ -300,7 +497,11 @@
+@@ -320,7 +520,11 @@
if (!doaccess) {
if ((p = TZDIR) == NULL)
return -1;
return -1;
(void) strcpy(fullname, p);
(void) strcat(fullname, "/");
-@@ -312,6 +513,10 @@
+@@ -332,6 +536,10 @@
doaccess = TRUE;
name = fullname;
}
if (doaccess && access(name, R_OK) != 0)
return -1;
if ((fid = _open(name, OPEN_MODE)) == -1)
-@@ -327,6 +532,9 @@
+@@ -350,6 +558,9 @@
int ttisstdcnt;
int ttisgmtcnt;
+#ifdef NOTIFY_TZ_DEBUG
+ NOTIFY_TZ_PRINTF("tzload: reading %s\n", name);
+#endif /* NOTIFY_TZ_DEBUG */
- i = _read(fid, buf, sizeof buf);
+ i = _read(fid, u.buf, sizeof u.buf);
if (_close(fid) != 0)
return -1;
-@@ -748,6 +956,9 @@
+@@ -764,6 +975,9 @@
}
}
load_result = tzload(TZDEFRULES, sp);
if (load_result != 0)
sp->leapcnt = 0; /* so, we're off a little */
if (*name != '\0') {
-@@ -934,8 +1145,19 @@
+@@ -951,8 +1165,19 @@
static void
tzsetwall_basic(void)
{
lcl_is_set = -1;
#ifdef ALL_STATE
-@@ -949,12 +1171,18 @@
+@@ -966,12 +1191,18 @@
#endif /* defined ALL_STATE */
if (tzload((char *) NULL, lclptr) != 0)
gmtload(lclptr);
_MUTEX_LOCK(&lcl_mutex);
tzsetwall_basic();
_MUTEX_UNLOCK(&lcl_mutex);
-@@ -971,8 +1199,19 @@
+@@ -988,8 +1219,18 @@
return;
}
+ notify_check_tz(&lcl_notify);
+#endif /* NOTIFY_TZ */
+#ifdef NOTIFY_TZ_DEBUG
-+ if (lcl_is_set > 0 && strcmp(lcl_TZname, name) == 0) {
++ if (lcl_is_set > 0 && strcmp(lcl_TZname, name) == 0) {
+ NOTIFY_TZ_PRINTF("tzset_basic matched %s\n", lcl_TZname);
+ return;
+ }
-+ NOTIFY_TZ_PRINTF("tzset_basic didn't matched %s\n", lcl_TZname);
+#else /* ! NOTIFY_TZ_DEBUG */
- if (lcl_is_set > 0 && strcmp(lcl_TZname, name) == 0)
+ if (lcl_is_set > 0 && strcmp(lcl_TZname, name) == 0)
return;
+#endif /* NOTIFY_TZ_DEBUG */
- lcl_is_set = (strlen(name) < sizeof(lcl_TZname));
+ lcl_is_set = strlen(name) < sizeof lcl_TZname;
if (lcl_is_set)
(void) strcpy(lcl_TZname, name);
-@@ -995,15 +1234,25 @@
+@@ -1014,15 +1255,25 @@
lclptr->ttis[0].tt_gmtoff = 0;
lclptr->ttis[0].tt_abbrind = 0;
(void) strcpy(lclptr->chars, gmt);
_MUTEX_LOCK(&lcl_mutex);
tzset_basic();
_MUTEX_UNLOCK(&lcl_mutex);
-@@ -1030,6 +1279,9 @@
+@@ -1049,6 +1300,9 @@
int i;
const time_t t = *timep;
sp = lclptr;
#ifdef ALL_STATE
if (sp == NULL) {
-@@ -1087,7 +1339,7 @@
+@@ -1094,7 +1348,7 @@
if (__isthreaded != 0) {
_pthread_mutex_lock(&localtime_mutex);
if (_pthread_key_create(&localtime_key, free) < 0) {
_pthread_mutex_unlock(&localtime_mutex);
return(NULL);
-@@ -1123,14 +1375,30 @@
+@@ -1146,14 +1400,30 @@
const long offset;
struct tm * const tmp;
{
}
_MUTEX_UNLOCK(&gmt_mutex);
timesub(timep, offset, gmtptr, tmp);
-@@ -1145,7 +1413,7 @@
+@@ -1168,7 +1438,7 @@
else {
#ifdef ALL_STATE
if (gmtptr == NULL)
else tmp->TM_ZONE = gmtptr->chars;
#endif /* defined ALL_STATE */
#ifndef ALL_STATE
-@@ -1165,7 +1433,7 @@
+@@ -1188,7 +1458,7 @@
if (__isthreaded != 0) {
_pthread_mutex_lock(&gmtime_mutex);
#ifndef PRIVATE_H
#define PRIVATE_H
+
/*
** This file is in the public domain, so clarified as of
-** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov).
+** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov).
**
-** $FreeBSD: src/lib/libc/stdtime/private.h,v 1.9 2002/05/28 16:59:40 alfred Exp $
+** $FreeBSD: src/lib/libc/stdtime/private.h,v 1.10 2004/06/14 10:31:52 stefanf Exp $
*/
/* Stuff moved from Makefile.inc to reduce clutter */
#ifndef lint
#ifndef NOID
/*
-static char privatehid[] = "@(#)private.h 7.43";
+static char privatehid[] = "@(#)private.h 7.53";
*/
#endif /* !defined NOID */
#endif /* !defined lint */
#define HAVE_GETTEXT 0
#endif /* !defined HAVE_GETTEXT */
+#ifndef HAVE_INCOMPATIBLE_CTIME_R
+#define HAVE_INCOMPATIBLE_CTIME_R 0
+#endif /* !defined INCOMPATIBLE_CTIME_R */
+
#ifndef HAVE_SETTIMEOFDAY
#define HAVE_SETTIMEOFDAY 3
#endif /* !defined HAVE_SETTIMEOFDAY */
#ifndef HAVE_STRERROR
-#define HAVE_STRERROR 0
+#define HAVE_STRERROR 1
#endif /* !defined HAVE_STRERROR */
+#ifndef HAVE_SYMLINK
+#define HAVE_SYMLINK 1
+#endif /* !defined HAVE_SYMLINK */
+
+#ifndef HAVE_SYS_STAT_H
+#define HAVE_SYS_STAT_H 1
+#endif /* !defined HAVE_SYS_STAT_H */
+
+#ifndef HAVE_SYS_WAIT_H
+#define HAVE_SYS_WAIT_H 1
+#endif /* !defined HAVE_SYS_WAIT_H */
+
#ifndef HAVE_UNISTD_H
#define HAVE_UNISTD_H 1
#endif /* !defined HAVE_UNISTD_H */
#define LOCALE_HOME "/usr/lib/locale"
#endif /* !defined LOCALE_HOME */
+#if HAVE_INCOMPATIBLE_CTIME_R
+#define asctime_r _incompatible_asctime_r
+#define ctime_r _incompatible_ctime_r
+#endif /* HAVE_INCOMPATIBLE_CTIME_R */
+
/*
** Nested includes
*/
#include "libintl.h"
#endif /* HAVE_GETTEXT - 0 */
+#if HAVE_SYS_WAIT_H - 0
+#include <sys/wait.h> /* for WIFEXITED and WEXITSTATUS */
+#endif /* HAVE_SYS_WAIT_H - 0 */
+
+#ifndef WIFEXITED
+#define WIFEXITED(status) (((status) & 0xff) == 0)
+#endif /* !defined WIFEXITED */
+#ifndef WEXITSTATUS
+#define WEXITSTATUS(status) (((status) >> 8) & 0xff)
+#endif /* !defined WEXITSTATUS */
+
#if HAVE_UNISTD_H - 0
#include "unistd.h" /* for F_OK and R_OK */
#endif /* HAVE_UNISTD_H - 0 */
#endif /* !defined FILENAME_MAX */
+/*
+** Private function declarations.
+*/
+char * icalloc(int nelem, int elsize);
+char * icatalloc(char * old, const char * new);
+char * icpyalloc(const char * string);
+char * imalloc(int n);
+void * irealloc(void * pointer, int size);
+void icfree(char * pointer);
+void ifree(char * pointer);
+char * scheck(const char *string, const char *format);
+
+
/*
** Finally, some convenience items.
*/
#define TZ_DOMAIN "tz"
#endif /* !defined TZ_DOMAIN */
+#if HAVE_INCOMPATIBLE_CTIME_R
+#undef asctime_r
+#undef ctime_r
+char *asctime_r(struct tm const *, char *);
+char *ctime_r(time_t const *, char *);
+#endif /* HAVE_INCOMPATIBLE_CTIME_R */
+
/*
-** UNIX was a registered trademark of UNIX System Laboratories in 1993.
+** UNIX was a registered trademark of The Open Group in 2003.
*/
#endif /* !defined PRIVATE_H */
.\" SUCH DAMAGE.
.\"
.\" @(#)strftime.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/stdtime/strftime.3,v 1.33 2003/01/04 09:47:40 tjr Exp $
+.\" $FreeBSD: src/lib/libc/stdtime/strftime.3,v 1.34 2004/07/02 23:52:12 ru Exp $
.\"
.Dd January 4, 2003
.Dt STRFTIME 3
as a decimal number (1-7).
.It Cm \&%V
is replaced by the week number of the year (Monday as the first day of
-the week) as a decimal number (01-53). If the week containing January
+the week) as a decimal number (01-53).
+If the week containing January
1 has four or more days in the new year, then it is week 1; otherwise
it is the last week of the previous year, and the next week is week 1.
.It Cm %v
--- /dev/null
+--- strftime.3.orig Fri Mar 11 07:33:40 2005
++++ strftime.3 Fri Mar 11 07:43:03 2005
+@@ -40,7 +40,8 @@
+ .Dt STRFTIME 3
+ .Os
+ .Sh NAME
+-.Nm strftime
++.Nm strftime ,
++.Nm strftime_l
+ .Nd format date and time
+ .Sh LIBRARY
+ .Lb libc
+@@ -53,6 +54,15 @@
+ .Fa "const char * restrict format"
+ .Fa "const struct tm * restrict timeptr"
+ .Fc
++.In xlocale.h
++.Ft size_t
++.Fo strftime_l
++.Fa "char * restrict buf"
++.Fa "size_t maxsize"
++.Fa "const char * restrict format"
++.Fa "const struct tm * restrict timeptr"
++.Fa "locale_t loc"
++.Fc
+ .Sh DESCRIPTION
+ The
+ .Fn strftime
+@@ -83,6 +93,14 @@
+ terminating NUL.
+ Otherwise, zero is returned and the buffer contents are indeterminate.
+ .Pp
++While the
++.Fn strftime
++function uses the current locale, the
++.Fn strftime_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
++.Pp
+ The conversion specifications are copied to the buffer after expansion
+ as follows:-
+ .Bl -tag -width "xxxx"
+@@ -226,7 +244,8 @@
+ .Xr ctime 3 ,
+ .Xr printf 3 ,
+ .Xr strptime 3 ,
+-.Xr wcsftime 3
++.Xr wcsftime 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn strftime
#ifndef lint
#ifndef NOID
-static const char elsieid[] = "@(#)strftime.c 7.38";
+static const char elsieid[] = "@(#)strftime.c 7.64";
/*
** Based on the UCB version with the ID appearing below.
** This is ANSIish only when "multibyte character == plain character".
static const char sccsid[] = "@(#)strftime.c 5.4 (Berkeley) 3/14/89";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdtime/strftime.c,v 1.38 2002/09/06 11:24:03 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdtime/strftime.c,v 1.40 2004/06/14 10:31:52 stefanf Exp $");
#include "tzfile.h"
#include <fcntl.h>
static char * _add(const char *, char *, const char *);
static char * _conv(int, const char *, char *, const char *);
-static char * _fmt(const char *, const struct tm *, char *, const char *);
+static char * _fmt(const char *, const struct tm *, char *, const char *, int *);
size_t strftime(char * __restrict, size_t, const char * __restrict,
const struct tm * __restrict);
extern char * tzname[];
+#ifndef YEAR_2000_NAME
+#define YEAR_2000_NAME "CHECK_STRFTIME_FORMATS_FOR_TWO_DIGIT_YEARS"
+#endif /* !defined YEAR_2000_NAME */
+
+
+#define IN_NONE 0
+#define IN_SOME 1
+#define IN_THIS 2
+#define IN_ALL 3
+
size_t
strftime(char * __restrict s, size_t maxsize, const char * __restrict format,
const struct tm * __restrict t)
{
- char *p;
+ char * p;
+ int warn;
tzset();
- p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize);
+ warn = IN_NONE;
+ p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn);
+#ifndef NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU
+ if (warn != IN_NONE && getenv(YEAR_2000_NAME) != NULL) {
+ (void) fprintf(stderr, "\n");
+ if (format == NULL)
+ (void) fprintf(stderr, "NULL strftime format ");
+ else (void) fprintf(stderr, "strftime format \"%s\" ",
+ format);
+ (void) fprintf(stderr, "yields only two digits of years in ");
+ if (warn == IN_SOME)
+ (void) fprintf(stderr, "some locales");
+ else if (warn == IN_THIS)
+ (void) fprintf(stderr, "the current locale");
+ else (void) fprintf(stderr, "all locales");
+ (void) fprintf(stderr, "\n");
+ }
+#endif /* !defined NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU */
if (p == s + maxsize)
return 0;
*p = '\0';
}
static char *
-_fmt(format, t, pt, ptlim)
- const char *format;
- const struct tm *const t;
- char *pt;
- const char *const ptlim;
+_fmt(format, t, pt, ptlim, warnp)
+const char * format;
+const struct tm * const t;
+char * pt;
+const char * const ptlim;
+int * warnp;
{
int Ealternative, Oalternative;
struct lc_time_T *tptr = __get_current_time_locale();
--format;
break;
case 'A':
- pt = _add((t->tm_wday < 0 || t->tm_wday > 6) ?
+ pt = _add((t->tm_wday < 0 ||
+ t->tm_wday >= DAYSPERWEEK) ?
"?" : tptr->weekday[t->tm_wday],
pt, ptlim);
continue;
case 'a':
- pt = _add((t->tm_wday < 0 || t->tm_wday > 6) ?
+ pt = _add((t->tm_wday < 0 ||
+ t->tm_wday >= DAYSPERWEEK) ?
"?" : tptr->wday[t->tm_wday],
pt, ptlim);
continue;
case 'B':
- pt = _add((t->tm_mon < 0 || t->tm_mon > 11) ?
+ pt = _add((t->tm_mon < 0 ||
+ t->tm_mon >= MONSPERYEAR) ?
"?" : (Oalternative ? tptr->alt_month :
tptr->month)[t->tm_mon],
pt, ptlim);
continue;
case 'b':
case 'h':
- pt = _add((t->tm_mon < 0 || t->tm_mon > 11) ?
+ pt = _add((t->tm_mon < 0 ||
+ t->tm_mon >= MONSPERYEAR) ?
"?" : tptr->mon[t->tm_mon],
pt, ptlim);
continue;
** _fmt("%a %b %e %X %Y", t);
** ...whereas now POSIX 1003.2 calls for
** something completely different.
- ** (ado, 5/24/93)
+ ** (ado, 1993-05-24)
*/
pt = _conv((t->tm_year + TM_YEAR_BASE) / 100,
"%02d", pt, ptlim);
continue;
case 'c':
- pt = _fmt(tptr->c_fmt, t, pt, ptlim);
+ {
+ int warn2 = IN_SOME;
+
+ pt = _fmt(tptr->c_fmt, t, pt, ptlim, warnp);
+ if (warn2 == IN_ALL)
+ warn2 = IN_THIS;
+ if (warn2 > *warnp)
+ *warnp = warn2;
+ }
continue;
case 'D':
- pt = _fmt("%m/%d/%y", t, pt, ptlim);
+ pt = _fmt("%m/%d/%y", t, pt, ptlim, warnp);
continue;
case 'd':
pt = _conv(t->tm_mday, "%02d", pt, ptlim);
goto label;
case 'O':
/*
- ** POSIX locale extensions, a la
- ** Arnold Robbins' strftime version 3.0.
+ ** C99 locale modifiers.
** The sequences
- ** %Ec %EC %Ex %EX %Ey %EY
+ ** %Ec %EC %Ex %EX %Ey %EY
** %Od %oe %OH %OI %Om %OM
** %OS %Ou %OU %OV %Ow %OW %Oy
** are supposed to provide alternate
** representations.
- ** (ado, 5/24/93)
**
- ** FreeBSD extensions
- ** %OB %Ef %EF
+ ** FreeBSD extension
+ ** %OB
*/
if (Ealternative || Oalternative)
break;
pt = _conv(t->tm_mday, "%2d", pt, ptlim);
continue;
case 'F':
- pt = _fmt("%Y-%m-%d", t, pt, ptlim);
+ pt = _fmt("%Y-%m-%d", t, pt, ptlim, warnp);
continue;
case 'H':
pt = _conv(t->tm_hour, "%02d", pt, ptlim);
** match SunOS 4.1.1 and Arnold Robbins'
** strftime version 3.0. That is, "%k" and
** "%l" have been swapped.
- ** (ado, 5/24/93)
+ ** (ado, 1993-05-24)
*/
pt = _conv(t->tm_hour, "%2d", pt, ptlim);
continue;
** match SunOS 4.1.1 and Arnold Robbin's
** strftime version 3.0. That is, "%k" and
** "%l" have been swapped.
- ** (ado, 5/24/93)
+ ** (ado, 1993-05-24)
*/
pt = _conv((t->tm_hour % 12) ?
(t->tm_hour % 12) : 12,
pt = _add("\n", pt, ptlim);
continue;
case 'p':
- pt = _add((t->tm_hour >= 12) ?
+ pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ?
tptr->pm :
tptr->am,
pt, ptlim);
continue;
case 'R':
- pt = _fmt("%H:%M", t, pt, ptlim);
+ pt = _fmt("%H:%M", t, pt, ptlim, warnp);
continue;
case 'r':
- pt = _fmt(tptr->ampm_fmt, t, pt, ptlim);
+ pt = _fmt(tptr->ampm_fmt, t, pt, ptlim,
+ warnp);
continue;
case 'S':
pt = _conv(t->tm_sec, "%02d", pt, ptlim);
}
continue;
case 'T':
- pt = _fmt("%H:%M:%S", t, pt, ptlim);
+ pt = _fmt("%H:%M:%S", t, pt, ptlim, warnp);
continue;
case 't':
pt = _add("\t", pt, ptlim);
continue;
case 'U':
- pt = _conv((t->tm_yday + 7 - t->tm_wday) / 7,
+ pt = _conv((t->tm_yday + DAYSPERWEEK -
+ t->tm_wday) / DAYSPERWEEK,
"%02d", pt, ptlim);
continue;
case 'u':
** From Arnold Robbins' strftime version 3.0:
** "ISO 8601: Weekday as a decimal number
** [1 (Monday) - 7]"
- ** (ado, 5/24/93)
+ ** (ado, 1993-05-24)
*/
- pt = _conv((t->tm_wday == 0) ? 7 : t->tm_wday,
+ pt = _conv((t->tm_wday == 0) ?
+ DAYSPERWEEK : t->tm_wday,
"%d", pt, ptlim);
continue;
case 'V': /* ISO 8601 week number */
pt = _conv(w, "%02d",
pt, ptlim);
else if (*format == 'g') {
+ *warnp = IN_ALL;
pt = _conv(year % 100, "%02d",
pt, ptlim);
} else pt = _conv(year, "%04d",
/*
** From Arnold Robbins' strftime version 3.0:
** "date as dd-bbb-YYYY"
- ** (ado, 5/24/93)
+ ** (ado, 1993-05-24)
*/
- pt = _fmt("%e-%b-%Y", t, pt, ptlim);
+ pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp);
continue;
case 'W':
- pt = _conv((t->tm_yday + 7 -
+ pt = _conv((t->tm_yday + DAYSPERWEEK -
(t->tm_wday ?
- (t->tm_wday - 1) : 6)) / 7,
+ (t->tm_wday - 1) :
+ (DAYSPERWEEK - 1))) / DAYSPERWEEK,
"%02d", pt, ptlim);
continue;
case 'w':
pt = _conv(t->tm_wday, "%d", pt, ptlim);
continue;
case 'X':
- pt = _fmt(tptr->X_fmt, t, pt, ptlim);
+ pt = _fmt(tptr->X_fmt, t, pt, ptlim, warnp);
continue;
case 'x':
- pt = _fmt(tptr->x_fmt, t, pt, ptlim);
+ {
+ int warn2 = IN_SOME;
+
+ pt = _fmt(tptr->x_fmt, t, pt, ptlim, &warn2);
+ if (warn2 == IN_ALL)
+ warn2 = IN_THIS;
+ if (warn2 > *warnp)
+ *warnp = warn2;
+ }
continue;
case 'y':
+ *warnp = IN_ALL;
pt = _conv((t->tm_year + TM_YEAR_BASE) % 100,
"%02d", pt, ptlim);
continue;
pt, ptlim);
continue;
case 'Z':
- if (t->tm_zone != NULL)
- pt = _add(t->tm_zone, pt, ptlim);
+#ifdef TM_ZONE
+ if (t->TM_ZONE != NULL)
+ pt = _add(t->TM_ZONE, pt, ptlim);
else
- if (t->tm_isdst == 0 || t->tm_isdst == 1) {
- pt = _add(tzname[t->tm_isdst],
+#endif /* defined TM_ZONE */
+ if (t->tm_isdst >= 0)
+ pt = _add(tzname[t->tm_isdst != 0],
pt, ptlim);
- } else pt = _add("?", pt, ptlim);
+ /*
+ ** C99 says that %Z must be replaced by the
+ ** empty string if the time zone is not
+ ** determinable.
+ */
continue;
case 'z':
{
- long absoff;
- if (t->tm_gmtoff >= 0) {
- absoff = t->tm_gmtoff;
- pt = _add("+", pt, ptlim);
- } else {
- absoff = -t->tm_gmtoff;
- pt = _add("-", pt, ptlim);
- }
- pt = _conv(absoff / 3600, "%02d",
- pt, ptlim);
- pt = _conv((absoff % 3600) / 60, "%02d",
- pt, ptlim);
- };
+ int diff;
+ char const * sign;
+
+ if (t->tm_isdst < 0)
+ continue;
+#ifdef TM_GMTOFF
+ diff = t->TM_GMTOFF;
+#else /* !defined TM_GMTOFF */
+ /*
+ ** C99 says that the UTC offset must
+ ** be computed by looking only at
+ ** tm_isdst. This requirement is
+ ** incorrect, since it means the code
+ ** must rely on magic (in this case
+ ** altzone and timezone), and the
+ ** magic might not have the correct
+ ** offset. Doing things correctly is
+ ** tricky and requires disobeying C99;
+ ** see GNU C strftime for details.
+ ** For now, punt and conform to the
+ ** standard, even though it's incorrect.
+ **
+ ** C99 says that %z must be replaced by the
+ ** empty string if the time zone is not
+ ** determinable, so output nothing if the
+ ** appropriate variables are not available.
+ */
+ if (t->tm_isdst == 0)
+#ifdef USG_COMPAT
+ diff = -timezone;
+#else /* !defined USG_COMPAT */
+ continue;
+#endif /* !defined USG_COMPAT */
+ else
+#ifdef ALTZONE
+ diff = -altzone;
+#else /* !defined ALTZONE */
+ continue;
+#endif /* !defined ALTZONE */
+#endif /* !defined TM_GMTOFF */
+ if (diff < 0) {
+ sign = "-";
+ diff = -diff;
+ } else sign = "+";
+ pt = _add(sign, pt, ptlim);
+ diff /= 60;
+ pt = _conv((diff/60)*100 + diff%60,
+ "%04d", pt, ptlim);
+ }
continue;
case '+':
- pt = _fmt(tptr->date_fmt, t, pt, ptlim);
+ pt = _fmt(tptr->date_fmt, t, pt, ptlim,
+ warnp);
continue;
case '%':
/*
- * X311J/88-090 (4.12.3.5): if conversion char is
- * undefined, behavior is undefined. Print out the
- * character itself as printf(3) also does.
- */
+ ** X311J/88-090 (4.12.3.5): if conversion char is
+ ** undefined, behavior is undefined. Print out the
+ ** character itself as printf(3) also does.
+ */
default:
break;
}
static char *
_conv(n, format, pt, ptlim)
- const int n;
- const char *const format;
- char *const pt;
- const char *const ptlim;
+const int n;
+const char * const format;
+char * const pt;
+const char * const ptlim;
{
char buf[INT_STRLEN_MAXIMUM(int) + 1];
static char *
_add(str, pt, ptlim)
- const char *str;
- char *pt;
- const char *const ptlim;
+const char * str;
+char * pt;
+const char * const ptlim;
{
while (pt < ptlim && (*pt = *str++) != '\0')
++pt;
--- /dev/null
+--- strftime.c.orig 2004-11-25 11:38:45.000000000 -0800
++++ strftime.c 2005-02-27 16:07:41.000000000 -0800
+@@ -25,6 +25,8 @@
+ #endif /* !defined NOID */
+ #endif /* !defined lint */
+
++#include "xlocale_private.h"
++
+ #include "namespace.h"
+ #include "private.h"
+
+@@ -35,19 +37,26 @@
+ __FBSDID("$FreeBSD: src/lib/libc/stdtime/strftime.c,v 1.40 2004/06/14 10:31:52 stefanf Exp $");
+
+ #include "tzfile.h"
++#include <time.h>
+ #include <fcntl.h>
+ #include <sys/stat.h>
+ #include "un-namespace.h"
+ #include "timelocal.h"
+
++#if !BUILDING_VARIANT
+ static char * _add(const char *, char *, const char *);
+-static char * _conv(int, const char *, char *, const char *);
+-static char * _fmt(const char *, const struct tm *, char *, const char *, int *);
++static char * _conv(int, const char *, char *, const char *, locale_t);
++#endif /* !BUILDING_VARIANT */
++#define _fmt _st_fmt
++__private_extern__ char *_fmt(const char *, const struct tm *, char *, const char *, int *, struct lc_time_T *, locale_t);
+
+ size_t strftime(char * __restrict, size_t, const char * __restrict,
+ const struct tm * __restrict);
+
+ extern char * tzname[];
++__private_extern__ long __darwin_altzone; /* DST timezone offset */
++#define altzone __darwin_altzone
++__private_extern__ long _st_get_timezone(void);
+
+ #ifndef YEAR_2000_NAME
+ #define YEAR_2000_NAME "CHECK_STRFTIME_FORMATS_FOR_TWO_DIGIT_YEARS"
+@@ -60,29 +69,40 @@
+ #define IN_ALL 3
+
+ size_t
+-strftime(char * __restrict s, size_t maxsize, const char * __restrict format,
+- const struct tm * __restrict t)
++strftime_l(char * __restrict s, size_t maxsize, const char * __restrict format,
++ const struct tm * __restrict t, locale_t loc)
+ {
+ char * p;
+ int warn;
++#if __DARWIN_UNIX03
++ struct tm t2;
++#endif /* __DARWIN_UNIX03 */
+
++ NORMALIZE_LOCALE(loc);
+ tzset();
+ warn = IN_NONE;
+- p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn);
++#if __DARWIN_UNIX03
++ if (t->tm_isdst >= 0) {
++ t2 = *t;
++ t2.tm_gmtoff = t->tm_isdst ? -__darwin_altzone : -_st_get_timezone();
++ t = &t2;
++ }
++#endif /* __DARWIN_UNIX03 */
++ p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn, __get_current_time_locale(loc), loc);
+ #ifndef NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU
+ if (warn != IN_NONE && getenv(YEAR_2000_NAME) != NULL) {
+- (void) fprintf(stderr, "\n");
++ (void) fputs("\n", stderr);
+ if (format == NULL)
+- (void) fprintf(stderr, "NULL strftime format ");
+- else (void) fprintf(stderr, "strftime format \"%s\" ",
++ (void) fputs("NULL strftime format ", stderr);
++ else (void) fprintf_l(stderr, loc, "strftime format \"%s\" ",
+ format);
+- (void) fprintf(stderr, "yields only two digits of years in ");
++ (void) fputs("yields only two digits of years in ", stderr);
+ if (warn == IN_SOME)
+- (void) fprintf(stderr, "some locales");
++ (void) fputs("some locales", stderr);
+ else if (warn == IN_THIS)
+- (void) fprintf(stderr, "the current locale");
+- else (void) fprintf(stderr, "all locales");
+- (void) fprintf(stderr, "\n");
++ (void) fputs("the current locale", stderr);
++ else (void) fputs("all locales", stderr);
++ (void) fputs("\n", stderr);
+ }
+ #endif /* !defined NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU */
+ if (p == s + maxsize)
+@@ -91,16 +111,25 @@
+ return p - s;
+ }
+
+-static char *
+-_fmt(format, t, pt, ptlim, warnp)
++size_t
++strftime(char * __restrict s, size_t maxsize, const char * __restrict format,
++ const struct tm * __restrict t)
++{
++ return strftime_l(s, maxsize, format, t, __current_locale());
++}
++
++#ifndef BUILDING_VARIANT
++__private_extern__ char *
++_fmt(format, t, pt, ptlim, warnp, tptr, loc)
+ const char * format;
+ const struct tm * const t;
+ char * pt;
+ const char * const ptlim;
+ int * warnp;
++struct lc_time_T * tptr;
++locale_t loc;
+ {
+ int Ealternative, Oalternative;
+- struct lc_time_T *tptr = __get_current_time_locale();
+
+ for ( ; *format; ++format) {
+ if (*format == '%') {
+@@ -146,13 +175,13 @@
+ ** (ado, 1993-05-24)
+ */
+ pt = _conv((t->tm_year + TM_YEAR_BASE) / 100,
+- "%02d", pt, ptlim);
++ "%02d", pt, ptlim, loc);
+ continue;
+ case 'c':
+ {
+ int warn2 = IN_SOME;
+
+- pt = _fmt(tptr->c_fmt, t, pt, ptlim, warnp);
++ pt = _fmt(tptr->c_fmt, t, pt, ptlim, warnp, tptr, loc);
+ if (warn2 == IN_ALL)
+ warn2 = IN_THIS;
+ if (warn2 > *warnp)
+@@ -160,10 +189,10 @@
+ }
+ continue;
+ case 'D':
+- pt = _fmt("%m/%d/%y", t, pt, ptlim, warnp);
++ pt = _fmt("%m/%d/%y", t, pt, ptlim, warnp, tptr, loc);
+ continue;
+ case 'd':
+- pt = _conv(t->tm_mday, "%02d", pt, ptlim);
++ pt = _conv(t->tm_mday, "%02d", pt, ptlim, loc);
+ continue;
+ case 'E':
+ if (Ealternative || Oalternative)
+@@ -188,21 +217,21 @@
+ Oalternative++;
+ goto label;
+ case 'e':
+- pt = _conv(t->tm_mday, "%2d", pt, ptlim);
++ pt = _conv(t->tm_mday, "%2d", pt, ptlim, loc);
+ continue;
+ case 'F':
+- pt = _fmt("%Y-%m-%d", t, pt, ptlim, warnp);
++ pt = _fmt("%Y-%m-%d", t, pt, ptlim, warnp, tptr, loc);
+ continue;
+ case 'H':
+- pt = _conv(t->tm_hour, "%02d", pt, ptlim);
++ pt = _conv(t->tm_hour, "%02d", pt, ptlim, loc);
+ continue;
+ case 'I':
+ pt = _conv((t->tm_hour % 12) ?
+ (t->tm_hour % 12) : 12,
+- "%02d", pt, ptlim);
++ "%02d", pt, ptlim, loc);
+ continue;
+ case 'j':
+- pt = _conv(t->tm_yday + 1, "%03d", pt, ptlim);
++ pt = _conv(t->tm_yday + 1, "%03d", pt, ptlim, loc);
+ continue;
+ case 'k':
+ /*
+@@ -215,7 +244,7 @@
+ ** "%l" have been swapped.
+ ** (ado, 1993-05-24)
+ */
+- pt = _conv(t->tm_hour, "%2d", pt, ptlim);
++ pt = _conv(t->tm_hour, "%2d", pt, ptlim, loc);
+ continue;
+ #ifdef KITCHEN_SINK
+ case 'K':
+@@ -237,13 +266,13 @@
+ */
+ pt = _conv((t->tm_hour % 12) ?
+ (t->tm_hour % 12) : 12,
+- "%2d", pt, ptlim);
++ "%2d", pt, ptlim, loc);
+ continue;
+ case 'M':
+- pt = _conv(t->tm_min, "%02d", pt, ptlim);
++ pt = _conv(t->tm_min, "%02d", pt, ptlim, loc);
+ continue;
+ case 'm':
+- pt = _conv(t->tm_mon + 1, "%02d", pt, ptlim);
++ pt = _conv(t->tm_mon + 1, "%02d", pt, ptlim, loc);
+ continue;
+ case 'n':
+ pt = _add("\n", pt, ptlim);
+@@ -255,14 +284,14 @@
+ pt, ptlim);
+ continue;
+ case 'R':
+- pt = _fmt("%H:%M", t, pt, ptlim, warnp);
++ pt = _fmt("%H:%M", t, pt, ptlim, warnp, tptr, loc);
+ continue;
+ case 'r':
+ pt = _fmt(tptr->ampm_fmt, t, pt, ptlim,
+- warnp);
++ warnp, tptr, loc);
+ continue;
+ case 'S':
+- pt = _conv(t->tm_sec, "%02d", pt, ptlim);
++ pt = _conv(t->tm_sec, "%02d", pt, ptlim, loc);
+ continue;
+ case 's':
+ {
+@@ -274,15 +303,15 @@
+ tm = *t;
+ mkt = mktime(&tm);
+ if (TYPE_SIGNED(time_t))
+- (void) sprintf(buf, "%ld",
++ (void) sprintf_l(buf, loc, "%ld",
+ (long) mkt);
+- else (void) sprintf(buf, "%lu",
++ else (void) sprintf_l(buf, loc, "%lu",
+ (unsigned long) mkt);
+ pt = _add(buf, pt, ptlim);
+ }
+ continue;
+ case 'T':
+- pt = _fmt("%H:%M:%S", t, pt, ptlim, warnp);
++ pt = _fmt("%H:%M:%S", t, pt, ptlim, warnp, tptr, loc);
+ continue;
+ case 't':
+ pt = _add("\t", pt, ptlim);
+@@ -290,7 +319,7 @@
+ case 'U':
+ pt = _conv((t->tm_yday + DAYSPERWEEK -
+ t->tm_wday) / DAYSPERWEEK,
+- "%02d", pt, ptlim);
++ "%02d", pt, ptlim, loc);
+ continue;
+ case 'u':
+ /*
+@@ -301,7 +330,7 @@
+ */
+ pt = _conv((t->tm_wday == 0) ?
+ DAYSPERWEEK : t->tm_wday,
+- "%d", pt, ptlim);
++ "%d", pt, ptlim, loc);
+ continue;
+ case 'V': /* ISO 8601 week number */
+ case 'G': /* ISO 8601 year (four digits) */
+@@ -380,13 +409,13 @@
+ #endif /* defined XPG4_1994_04_09 */
+ if (*format == 'V')
+ pt = _conv(w, "%02d",
+- pt, ptlim);
++ pt, ptlim, loc);
+ else if (*format == 'g') {
+ *warnp = IN_ALL;
+ pt = _conv(year % 100, "%02d",
+- pt, ptlim);
++ pt, ptlim, loc);
+ } else pt = _conv(year, "%04d",
+- pt, ptlim);
++ pt, ptlim, loc);
+ }
+ continue;
+ case 'v':
+@@ -395,26 +424,26 @@
+ ** "date as dd-bbb-YYYY"
+ ** (ado, 1993-05-24)
+ */
+- pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp);
++ pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp, tptr, loc);
+ continue;
+ case 'W':
+ pt = _conv((t->tm_yday + DAYSPERWEEK -
+ (t->tm_wday ?
+ (t->tm_wday - 1) :
+ (DAYSPERWEEK - 1))) / DAYSPERWEEK,
+- "%02d", pt, ptlim);
++ "%02d", pt, ptlim, loc);
+ continue;
+ case 'w':
+- pt = _conv(t->tm_wday, "%d", pt, ptlim);
++ pt = _conv(t->tm_wday, "%d", pt, ptlim, loc);
+ continue;
+ case 'X':
+- pt = _fmt(tptr->X_fmt, t, pt, ptlim, warnp);
++ pt = _fmt(tptr->X_fmt, t, pt, ptlim, warnp, tptr, loc);
+ continue;
+ case 'x':
+ {
+ int warn2 = IN_SOME;
+
+- pt = _fmt(tptr->x_fmt, t, pt, ptlim, &warn2);
++ pt = _fmt(tptr->x_fmt, t, pt, ptlim, &warn2, tptr, loc);
+ if (warn2 == IN_ALL)
+ warn2 = IN_THIS;
+ if (warn2 > *warnp)
+@@ -424,11 +453,11 @@
+ case 'y':
+ *warnp = IN_ALL;
+ pt = _conv((t->tm_year + TM_YEAR_BASE) % 100,
+- "%02d", pt, ptlim);
++ "%02d", pt, ptlim, loc);
+ continue;
+ case 'Y':
+ pt = _conv(t->tm_year + TM_YEAR_BASE, "%04d",
+- pt, ptlim);
++ pt, ptlim, loc);
+ continue;
+ case 'Z':
+ #ifdef TM_ZONE
+@@ -476,7 +505,7 @@
+ */
+ if (t->tm_isdst == 0)
+ #ifdef USG_COMPAT
+- diff = -timezone;
++ diff = -_st_get_timezone();
+ #else /* !defined USG_COMPAT */
+ continue;
+ #endif /* !defined USG_COMPAT */
+@@ -494,12 +523,12 @@
+ pt = _add(sign, pt, ptlim);
+ diff /= 60;
+ pt = _conv((diff/60)*100 + diff%60,
+- "%04d", pt, ptlim);
++ "%04d", pt, ptlim, loc);
+ }
+ continue;
+ case '+':
+ pt = _fmt(tptr->date_fmt, t, pt, ptlim,
+- warnp);
++ warnp, tptr, loc);
+ continue;
+ case '%':
+ /*
+@@ -519,15 +548,16 @@
+ }
+
+ static char *
+-_conv(n, format, pt, ptlim)
++_conv(n, format, pt, ptlim, loc)
+ const int n;
+ const char * const format;
+ char * const pt;
+ const char * const ptlim;
++locale_t loc;
+ {
+ char buf[INT_STRLEN_MAXIMUM(int) + 1];
+
+- (void) sprintf(buf, format, n);
++ (void) sprintf_l(buf, loc, format, n);
+ return _add(buf, pt, ptlim);
+ }
+
+@@ -541,3 +571,4 @@
+ ++pt;
+ return pt;
+ }
++#endif /* !BUILDING_VARIANT */
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/lib/libc/stdtime/strptime.3,v 1.22 2003/01/04 09:50:04 tjr Exp $
+.\" $FreeBSD: src/lib/libc/stdtime/strptime.3,v 1.23 2004/07/02 23:52:12 ru Exp $
.\" "
.Dd January 4, 2003
.Dt STRPTIME 3
format specifier only accepts time zone abbreviations of the local time zone,
or the value "GMT".
This limitation is because of ambiguity due to of the over loading of time
-zone abbreviations. One such example is
+zone abbreviations.
+One such example is
.Fa EST
which is both Eastern Standard Time and Eastern Australia Summer Time.
.Pp
--- /dev/null
+--- strptime.3.orig Fri Mar 11 07:33:44 2005
++++ strptime.3 Fri Mar 11 07:40:29 2005
+@@ -29,7 +29,8 @@
+ .Dt STRPTIME 3
+ .Os
+ .Sh NAME
+-.Nm strptime
++.Nm strptime ,
++.Nm strptime_l
+ .Nd parse date and time string
+ .Sh LIBRARY
+ .Lb libc
+@@ -41,6 +42,14 @@
+ .Fa "const char * restrict format"
+ .Fa "struct tm * restrict timeptr"
+ .Fc
++.In xlocale.h
++.Ft char *
++.Fo strptime_l
++.Fa "const char * restrict buf"
++.Fa "const char * restrict format"
++.Fa "struct tm * restrict timeptr"
++.Fa "locale_t loc"
++.Fc
+ .Sh DESCRIPTION
+ The
+ .Fn strptime
+@@ -94,6 +103,14 @@
+ .Fa timeptr
+ structure with today's date before passing it to
+ .Fn strptime .
++.Pp
++While the
++.Fn strptime
++function uses the current locale, the
++.Fn strptime_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ Upon successful completion,
+ .Fn strptime
+@@ -107,7 +124,8 @@
+ .Sh SEE ALSO
+ .Xr date 1 ,
+ .Xr scanf 3 ,
+-.Xr strftime 3
++.Xr strftime 3 ,
++.Xr xlocale 3
+ .Sh AUTHORS
+ The
+ .Fn strptime
static char sccsid[] __unused = "@(#)strptime.c 0.1 (Powerdog) 94/03/27";
#endif /* !defined NOID */
#endif /* not lint */
-__FBSDID("$FreeBSD: src/lib/libc/stdtime/strptime.c,v 1.34 2003/04/30 10:25:57 mtm Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdtime/strptime.c,v 1.35 2003/11/17 04:19:15 nectar Exp $");
#include "namespace.h"
#include <time.h>
#include <ctype.h>
-#include <limits.h>
+#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
case 's':
{
char *cp;
+ int sverrno;
+ long n;
time_t t;
- t = strtol(buf, &cp, 10);
- if (t == LONG_MAX)
+ sverrno = errno;
+ errno = 0;
+ n = strtol(buf, &cp, 10);
+ if (errno == ERANGE || (long)(t = n) != n) {
+ errno = sverrno;
return 0;
+ }
+ errno = sverrno;
buf = cp;
gmtime_r(&t, tm);
*GMTp = 1;
--- /dev/null
+--- strptime.c.orig 2004-11-25 11:38:45.000000000 -0800
++++ strptime.c 2005-02-24 01:09:32.000000000 -0800
+@@ -61,6 +61,8 @@
+ #endif /* not lint */
+ __FBSDID("$FreeBSD: src/lib/libc/stdtime/strptime.c,v 1.35 2003/11/17 04:19:15 nectar Exp $");
+
++#include "xlocale_private.h"
++
+ #include "namespace.h"
+ #include <time.h>
+ #include <ctype.h>
+@@ -72,19 +74,19 @@
+ #include "libc_private.h"
+ #include "timelocal.h"
+
+-static char * _strptime(const char *, const char *, struct tm *, int *);
++static char * _strptime(const char *, const char *, struct tm *, int *, locale_t);
+
+ #define asizeof(a) (sizeof (a) / sizeof ((a)[0]))
+
+ static char *
+-_strptime(const char *buf, const char *fmt, struct tm *tm, int *GMTp)
++_strptime(const char *buf, const char *fmt, struct tm *tm, int *GMTp, locale_t loc)
+ {
+ char c;
+ const char *ptr;
+ int i,
+ len;
+ int Ealternative, Oalternative;
+- struct lc_time_T *tptr = __get_current_time_locale();
++ struct lc_time_T *tptr = __get_current_time_locale(loc);
+
+ ptr = fmt;
+ while (*ptr != 0) {
+@@ -94,8 +96,8 @@
+ c = *ptr++;
+
+ if (c != '%') {
+- if (isspace((unsigned char)c))
+- while (*buf != 0 && isspace((unsigned char)*buf))
++ if (isspace_l((unsigned char)c, loc))
++ while (*buf != 0 && isspace_l((unsigned char)*buf, loc))
+ buf++;
+ else if (c != *buf++)
+ return 0;
+@@ -114,18 +116,18 @@
+ break;
+
+ case '+':
+- buf = _strptime(buf, tptr->date_fmt, tm, GMTp);
++ buf = _strptime(buf, tptr->date_fmt, tm, GMTp, loc);
+ if (buf == 0)
+ return 0;
+ break;
+
+ case 'C':
+- if (!isdigit((unsigned char)*buf))
++ if (!isdigit_l((unsigned char)*buf, loc))
+ return 0;
+
+ /* XXX This will break for 3-digit centuries. */
+ len = 2;
+- for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
++ for (i = 0; len && *buf != 0 && isdigit_l((unsigned char)*buf, loc); buf++) {
+ i *= 10;
+ i += *buf - '0';
+ len--;
+@@ -137,13 +139,13 @@
+ break;
+
+ case 'c':
+- buf = _strptime(buf, tptr->c_fmt, tm, GMTp);
++ buf = _strptime(buf, tptr->c_fmt, tm, GMTp, loc);
+ if (buf == 0)
+ return 0;
+ break;
+
+ case 'D':
+- buf = _strptime(buf, "%m/%d/%y", tm, GMTp);
++ buf = _strptime(buf, "%m/%d/%y", tm, GMTp, loc);
+ if (buf == 0)
+ return 0;
+ break;
+@@ -161,47 +163,47 @@
+ goto label;
+
+ case 'F':
+- buf = _strptime(buf, "%Y-%m-%d", tm, GMTp);
++ buf = _strptime(buf, "%Y-%m-%d", tm, GMTp, loc);
+ if (buf == 0)
+ return 0;
+ break;
+
+ case 'R':
+- buf = _strptime(buf, "%H:%M", tm, GMTp);
++ buf = _strptime(buf, "%H:%M", tm, GMTp, loc);
+ if (buf == 0)
+ return 0;
+ break;
+
+ case 'r':
+- buf = _strptime(buf, tptr->ampm_fmt, tm, GMTp);
++ buf = _strptime(buf, tptr->ampm_fmt, tm, GMTp, loc);
+ if (buf == 0)
+ return 0;
+ break;
+
+ case 'T':
+- buf = _strptime(buf, "%H:%M:%S", tm, GMTp);
++ buf = _strptime(buf, "%H:%M:%S", tm, GMTp, loc);
+ if (buf == 0)
+ return 0;
+ break;
+
+ case 'X':
+- buf = _strptime(buf, tptr->X_fmt, tm, GMTp);
++ buf = _strptime(buf, tptr->X_fmt, tm, GMTp, loc);
+ if (buf == 0)
+ return 0;
+ break;
+
+ case 'x':
+- buf = _strptime(buf, tptr->x_fmt, tm, GMTp);
++ buf = _strptime(buf, tptr->x_fmt, tm, GMTp, loc);
+ if (buf == 0)
+ return 0;
+ break;
+
+ case 'j':
+- if (!isdigit((unsigned char)*buf))
++ if (!isdigit_l((unsigned char)*buf, loc))
+ return 0;
+
+ len = 3;
+- for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
++ for (i = 0; len && *buf != 0 && isdigit_l((unsigned char)*buf, loc); buf++) {
+ i *= 10;
+ i += *buf - '0';
+ len--;
+@@ -214,14 +216,14 @@
+
+ case 'M':
+ case 'S':
+- if (*buf == 0 || isspace((unsigned char)*buf))
++ if (*buf == 0 || isspace_l((unsigned char)*buf, loc))
+ break;
+
+- if (!isdigit((unsigned char)*buf))
++ if (!isdigit_l((unsigned char)*buf, loc))
+ return 0;
+
+ len = 2;
+- for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
++ for (i = 0; len && *buf != 0 && isdigit_l((unsigned char)*buf, loc); buf++) {
+ i *= 10;
+ i += *buf - '0';
+ len--;
+@@ -237,8 +239,8 @@
+ tm->tm_sec = i;
+ }
+
+- if (*buf != 0 && isspace((unsigned char)*buf))
+- while (*ptr != 0 && !isspace((unsigned char)*ptr))
++ if (*buf != 0 && isspace_l((unsigned char)*buf, loc))
++ while (*ptr != 0 && !isspace_l((unsigned char)*ptr, loc))
+ ptr++;
+ break;
+
+@@ -254,11 +256,11 @@
+ * XXX The %l specifier may gobble one too many
+ * digits if used incorrectly.
+ */
+- if (!isdigit((unsigned char)*buf))
++ if (!isdigit_l((unsigned char)*buf, loc))
+ return 0;
+
+ len = 2;
+- for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
++ for (i = 0; len && *buf != 0 && isdigit_l((unsigned char)*buf, loc); buf++) {
+ i *= 10;
+ i += *buf - '0';
+ len--;
+@@ -271,8 +273,8 @@
+
+ tm->tm_hour = i;
+
+- if (*buf != 0 && isspace((unsigned char)*buf))
+- while (*ptr != 0 && !isspace((unsigned char)*ptr))
++ if (*buf != 0 && isspace_l((unsigned char)*buf, loc))
++ while (*ptr != 0 && !isspace_l((unsigned char)*ptr, loc))
+ ptr++;
+ break;
+
+@@ -282,7 +284,7 @@
+ * specifiers.
+ */
+ len = strlen(tptr->am);
+- if (strncasecmp(buf, tptr->am, len) == 0) {
++ if (strncasecmp_l(buf, tptr->am, len, loc) == 0) {
+ if (tm->tm_hour > 12)
+ return 0;
+ if (tm->tm_hour == 12)
+@@ -292,7 +294,7 @@
+ }
+
+ len = strlen(tptr->pm);
+- if (strncasecmp(buf, tptr->pm, len) == 0) {
++ if (strncasecmp_l(buf, tptr->pm, len, loc) == 0) {
+ if (tm->tm_hour > 12)
+ return 0;
+ if (tm->tm_hour != 12)
+@@ -307,12 +309,12 @@
+ case 'a':
+ for (i = 0; i < asizeof(tptr->weekday); i++) {
+ len = strlen(tptr->weekday[i]);
+- if (strncasecmp(buf, tptr->weekday[i],
+- len) == 0)
++ if (strncasecmp_l(buf, tptr->weekday[i],
++ len, loc) == 0)
+ break;
+ len = strlen(tptr->wday[i]);
+- if (strncasecmp(buf, tptr->wday[i],
+- len) == 0)
++ if (strncasecmp_l(buf, tptr->wday[i],
++ len, loc) == 0)
+ break;
+ }
+ if (i == asizeof(tptr->weekday))
+@@ -330,11 +332,11 @@
+ * point to calculate a real value, so just check the
+ * range for now.
+ */
+- if (!isdigit((unsigned char)*buf))
++ if (!isdigit_l((unsigned char)*buf, loc))
+ return 0;
+
+ len = 2;
+- for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
++ for (i = 0; len && *buf != 0 && isdigit_l((unsigned char)*buf, loc); buf++) {
+ i *= 10;
+ i += *buf - '0';
+ len--;
+@@ -342,13 +344,13 @@
+ if (i > 53)
+ return 0;
+
+- if (*buf != 0 && isspace((unsigned char)*buf))
+- while (*ptr != 0 && !isspace((unsigned char)*ptr))
++ if (*buf != 0 && isspace_l((unsigned char)*buf, loc))
++ while (*ptr != 0 && !isspace_l((unsigned char)*ptr, loc))
+ ptr++;
+ break;
+
+ case 'w':
+- if (!isdigit((unsigned char)*buf))
++ if (!isdigit_l((unsigned char)*buf, loc))
+ return 0;
+
+ i = *buf - '0';
+@@ -357,8 +359,8 @@
+
+ tm->tm_wday = i;
+
+- if (*buf != 0 && isspace((unsigned char)*buf))
+- while (*ptr != 0 && !isspace((unsigned char)*ptr))
++ if (*buf != 0 && isspace_l((unsigned char)*buf, loc))
++ while (*ptr != 0 && !isspace_l((unsigned char)*ptr, loc))
+ ptr++;
+ break;
+
+@@ -372,11 +374,11 @@
+ * XXX The %e specifier may gobble one too many
+ * digits if used incorrectly.
+ */
+- if (!isdigit((unsigned char)*buf))
++ if (!isdigit_l((unsigned char)*buf, loc))
+ return 0;
+
+ len = 2;
+- for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
++ for (i = 0; len && *buf != 0 && isdigit_l((unsigned char)*buf, loc); buf++) {
+ i *= 10;
+ i += *buf - '0';
+ len--;
+@@ -386,8 +388,8 @@
+
+ tm->tm_mday = i;
+
+- if (*buf != 0 && isspace((unsigned char)*buf))
+- while (*ptr != 0 && !isspace((unsigned char)*ptr))
++ if (*buf != 0 && isspace_l((unsigned char)*buf, loc))
++ while (*ptr != 0 && !isspace_l((unsigned char)*ptr, loc))
+ ptr++;
+ break;
+
+@@ -398,19 +400,19 @@
+ if (Oalternative) {
+ if (c == 'B') {
+ len = strlen(tptr->alt_month[i]);
+- if (strncasecmp(buf,
++ if (strncasecmp_l(buf,
+ tptr->alt_month[i],
+- len) == 0)
++ len, loc) == 0)
+ break;
+ }
+ } else {
+ len = strlen(tptr->month[i]);
+- if (strncasecmp(buf, tptr->month[i],
+- len) == 0)
++ if (strncasecmp_l(buf, tptr->month[i],
++ len, loc) == 0)
+ break;
+ len = strlen(tptr->mon[i]);
+- if (strncasecmp(buf, tptr->mon[i],
+- len) == 0)
++ if (strncasecmp_l(buf, tptr->mon[i],
++ len, loc) == 0)
+ break;
+ }
+ }
+@@ -422,11 +424,11 @@
+ break;
+
+ case 'm':
+- if (!isdigit((unsigned char)*buf))
++ if (!isdigit_l((unsigned char)*buf, loc))
+ return 0;
+
+ len = 2;
+- for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
++ for (i = 0; len && *buf != 0 && isdigit_l((unsigned char)*buf, loc); buf++) {
+ i *= 10;
+ i += *buf - '0';
+ len--;
+@@ -436,8 +438,8 @@
+
+ tm->tm_mon = i - 1;
+
+- if (*buf != 0 && isspace((unsigned char)*buf))
+- while (*ptr != 0 && !isspace((unsigned char)*ptr))
++ if (*buf != 0 && isspace_l((unsigned char)*buf, loc))
++ while (*ptr != 0 && !isspace_l((unsigned char)*ptr, loc))
+ ptr++;
+ break;
+
+@@ -450,7 +452,7 @@
+
+ sverrno = errno;
+ errno = 0;
+- n = strtol(buf, &cp, 10);
++ n = strtol_l(buf, &cp, 10, loc);
+ if (errno == ERANGE || (long)(t = n) != n) {
+ errno = sverrno;
+ return 0;
+@@ -464,14 +466,14 @@
+
+ case 'Y':
+ case 'y':
+- if (*buf == 0 || isspace((unsigned char)*buf))
++ if (*buf == 0 || isspace_l((unsigned char)*buf, loc))
+ break;
+
+- if (!isdigit((unsigned char)*buf))
++ if (!isdigit_l((unsigned char)*buf, loc))
+ return 0;
+
+ len = (c == 'Y') ? 4 : 2;
+- for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
++ for (i = 0; len && *buf != 0 && isdigit_l((unsigned char)*buf, loc); buf++) {
+ i *= 10;
+ i += *buf - '0';
+ len--;
+@@ -485,8 +487,8 @@
+
+ tm->tm_year = i;
+
+- if (*buf != 0 && isspace((unsigned char)*buf))
+- while (*ptr != 0 && !isspace((unsigned char)*ptr))
++ if (*buf != 0 && isspace_l((unsigned char)*buf, loc))
++ while (*ptr != 0 && !isspace_l((unsigned char)*ptr, loc))
+ ptr++;
+ break;
+
+@@ -495,7 +497,7 @@
+ const char *cp;
+ char *zonestr;
+
+- for (cp = buf; *cp && isupper((unsigned char)*cp); ++cp) {/*empty*/}
++ for (cp = buf; *cp && isupper_l((unsigned char)*cp, loc); ++cp) {/*empty*/}
+ if (cp - buf) {
+ zonestr = alloca(cp - buf + 1);
+ strncpy(zonestr, buf, cp - buf);
+@@ -528,7 +530,25 @@
+ int gmt;
+
+ gmt = 0;
+- ret = _strptime(buf, fmt, tm, &gmt);
++ ret = _strptime(buf, fmt, tm, &gmt, __current_locale());
++ if (ret && gmt) {
++ time_t t = timegm(tm);
++ localtime_r(&t, tm);
++ }
++
++ return (ret);
++}
++
++char *
++strptime_l(const char * __restrict buf, const char * __restrict fmt,
++ struct tm * __restrict tm, locale_t loc)
++{
++ char *ret;
++ int gmt;
++
++ NORMALIZE_LOCALE(loc);
++ gmt = 0;
++ ret = _strptime(buf, fmt, tm, &gmt, loc);
+ if (ret && gmt) {
+ time_t t = timegm(tm);
+ localtime_r(&t, tm);
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdtime/timelocal.c,v 1.24 2002/08/07 16:49:20 ache Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdtime/timelocal.c,v 1.25 2003/06/13 00:14:07 jkh Exp $");
#include <stddef.h>
__time_load_locale(const char *name)
{
return (__part_load_locale(name, &_time_using_locale,
- time_locale_buf, "LC_TIME",
+ &time_locale_buf, "LC_TIME",
LCTIME_SIZE, LCTIME_SIZE,
(const char **)&_time_locale));
}
---- timelocal.c.orig Tue May 20 15:23:48 2003
-+++ timelocal.c Wed Jun 11 17:08:39 2003
-@@ -111,7 +111,7 @@
- __time_load_locale(const char *name)
+--- timelocal.c.orig 2004-11-25 11:38:45.000000000 -0800
++++ timelocal.c 2005-02-17 10:08:04.000000000 -0800
+@@ -28,15 +28,14 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/stdtime/timelocal.c,v 1.25 2003/06/13 00:14:07 jkh Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stddef.h>
++#include <string.h>
+
+ #include "ldpart.h"
+ #include "timelocal.h"
+
+-static struct lc_time_T _time_locale;
+-static int _time_using_locale;
+-static char *time_locale_buf;
+-
+ #define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *))
+
+ static const struct lc_time_T _C_time_locale = {
+@@ -99,19 +98,57 @@
+ "%I:%M:%S %p"
+ };
+
+-struct lc_time_T *
+-__get_current_time_locale(void)
++__private_extern__ struct lc_time_T *
++__get_current_time_locale(locale_t loc)
{
- return (__part_load_locale(name, &_time_using_locale,
-- time_locale_buf, "LC_TIME",
-+ &time_locale_buf, "LC_TIME",
+- return (_time_using_locale
+- ? &_time_locale
++ return (loc->_time_using_locale
++ ? &loc->__lc_time->_time_locale
+ : (struct lc_time_T *)&_C_time_locale);
+ }
+
+-int
+-__time_load_locale(const char *name)
++__private_extern__ int
++__time_load_locale(const char *name, locale_t loc)
+ {
+- return (__part_load_locale(name, &_time_using_locale,
+- &time_locale_buf, "LC_TIME",
++ int ret;
++ struct __xlocale_st_time *xp;
++ static struct __xlocale_st_time *cache = NULL;
++
++ /* 'name' must be already checked. */
++ if (strcmp(name, "C") == 0 || strcmp(name, "POSIX") == 0) {
++ loc->_time_using_locale = 0;
++ XL_RELEASE(loc->__lc_time);
++ loc->__lc_time = NULL;
++ return (_LDP_CACHE);
++ }
++
++ /*
++ * If the locale name is the same as our cache, use the cache.
++ */
++ if (cache && cache->_time_locale_buf && strcmp(name, cache->_time_locale_buf) == 0) {
++ loc->_time_using_locale = 1;
++ XL_RELEASE(loc->__lc_time);
++ loc->__lc_time = cache;
++ XL_RETAIN(loc->__lc_time);
++ return (_LDP_CACHE);
++ }
++ if ((xp = (struct __xlocale_st_time *)malloc(sizeof(*xp))) == NULL)
++ return _LDP_ERROR;
++ xp->__refcount = 1;
++ xp->__free_extra = (__free_extra_t)__ldpart_free_extra;
++ xp->_time_locale_buf = NULL;
++
++ ret = __part_load_locale(name, &loc->_time_using_locale,
++ &xp->_time_locale_buf, "LC_TIME",
LCTIME_SIZE, LCTIME_SIZE,
- (const char **)&_time_locale));
+- (const char **)&_time_locale));
++ (const char **)&xp->_time_locale);
++ if (ret == _LDP_LOADED) {
++ XL_RELEASE(loc->__lc_time);
++ loc->__lc_time = xp;
++ XL_RELEASE(cache);
++ cache = xp;
++ XL_RETAIN(cache);
++ } else if (ret == _LDP_ERROR)
++ free(xp);
++
++ return (ret);
}
--- /dev/null
+--- timelocal.h.orig 2003-05-20 15:23:48.000000000 -0700
++++ timelocal.h 2005-02-19 14:49:09.000000000 -0800
+@@ -29,6 +29,8 @@
+ #ifndef _TIMELOCAL_H_
+ #define _TIMELOCAL_H_
+
++#include <xlocale.h>
++
+ /*
+ * Private header file for the strftime and strptime localization
+ * stuff.
+@@ -49,7 +51,7 @@
+ const char *ampm_fmt;
+ };
+
+-struct lc_time_T *__get_current_time_locale(void);
+-int __time_load_locale(const char *);
++struct lc_time_T *__get_current_time_locale(locale_t);
++int __time_load_locale(const char *, locale_t);
+
+ #endif /* !_TIMELOCAL_H_ */
CFLAGS-localtime-fbsd.c += -DNOTIFY_TZ
-MISRCS += getdate.c
+UNIX03SRCS += strftime.c
+
+MISRCS += getdate.c timezone_unix03.c
.include "Makefile.fbsd_begin"
FBSDMISRCS= asctime.c difftime.c ftime.c localtime.c \
strftime.c strptime.c timelocal.c time32.c
FBSDHDRS= private.h timelocal.h tzfile.h
.include "Makefile.fbsd_end"
+INSTHDRS_AUTOPATCH += tzfile.h
.if ${LIB} == "c"
.include "Makefile.fbsd_begin"
ctime.3 ctime_r.3 ctime.3 localtime_r.3 ctime.3 gmtime_r.3 \
ctime.3 asctime_r.3
MLINKS+=time2posix.3 posix2time.3
+MLINKS+=strftime.3 strftime_l.3
+MLINKS+=strptime.3 strptime_l.3
.endif
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#undef __DARWIN_UNIX03
+#define __DARWIN_UNIX03 1
+#include <time.h>
+
+long timezone = 0;
+
+__private_extern__ long
+_st_get_timezone(void)
+{
+ return timezone;
+}
+
+__private_extern__ void
+_st_set_timezone(long tz)
+{
+ timezone = tz;
+}
.\" SUCH DAMAGE.
.\"
.\" @(#)bcmp.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/string/bcmp.3,v 1.9 2002/08/30 21:07:40 robert Exp $
+.\" $FreeBSD: src/lib/libc/string/bcmp.3,v 1.10 2003/09/08 19:57:15 ru Exp $
.\"
.Dd June 4, 1993
.Dt BCMP 3
function first appeared in
.Bx 4.2 .
Its prototype existed previously in
-.Aq Pa string.h
+.In string.h
before it was moved to
-.Aq Pa strings.h
+.In strings.h
for
.St -p1003.1-2001
compliance.
.\" SUCH DAMAGE.
.\"
.\" @(#)bcopy.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/string/bcopy.3,v 1.8 2002/09/01 21:53:46 robert Exp $
+.\" $FreeBSD: src/lib/libc/string/bcopy.3,v 1.9 2003/09/08 19:57:15 ru Exp $
.\"
.Dd June 4, 1993
.Dt BCOPY 3
function appeared in
.Bx 4.2 .
Its prototype existed previously in
-.Aq Pa string.h
+.In string.h
before it was moved to
-.Aq Pa strings.h
+.In strings.h
for
.St -p1003.1-2001
compliance.
.\" SUCH DAMAGE.
.\"
.\" @(#)bzero.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/string/bzero.3,v 1.8 2002/09/01 21:53:46 robert Exp $
+.\" $FreeBSD: src/lib/libc/string/bzero.3,v 1.9 2003/09/08 19:57:15 ru Exp $
.\"
.Dd June 4, 1993
.Dt BZERO 3
appeared in
.Bx 4.3 .
Its prototype existed previously in
-.Aq Pa string.h
+.In string.h
before it was moved to
-.Aq Pa strings.h
+.In strings.h
for
.St -p1003.1-2001
compliance.
.\" SUCH DAMAGE.
.\"
.\" @(#)ffs.3 8.2 (Berkeley) 4/19/94
-.\" $FreeBSD: src/lib/libc/string/ffs.3,v 1.6 2002/08/30 19:08:53 robert Exp $
+.\" $FreeBSD: src/lib/libc/string/ffs.3,v 1.9 2004/06/30 20:09:09 ru Exp $
.\"
-.Dd April 19, 1994
+.Dd January 13, 2004
.Dt FFS 3
.Os
.Sh NAME
-.Nm ffs
-.Nd find first bit set in a bit string
+.Nm ffs ,
+.Nm ffsl ,
+.Nm fls ,
+.Nm flsl
+.Nd find first or last bit set in a bit string
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In strings.h
.Ft int
.Fn ffs "int value"
+.Ft int
+.Fn ffsl "long value"
+.Ft int
+.Fn fls "int value"
+.Ft int
+.Fn flsl "long value"
.Sh DESCRIPTION
The
.Fn ffs
-function finds the first bit set in
+and
+.Fn ffsl
+functions find the first bit set in
.Fa value
-and returns the index of that bit.
+and return the index of that bit.
+.Pp
+The
+.Fn fls
+and
+.Fn flsl
+functions find the last bit set in
+.Fa value
+and return the index of that bit.
+.Pp
Bits are numbered starting from 1, starting at the right-most
-bit.
-A return value of 0 means that the argument was zero.
+(least significant) bit.
+A return value of zero from any of these functions means that the
+argument was zero.
.Sh SEE ALSO
.Xr bitstring 3
.Sh HISTORY
function appeared in
.Bx 4.3 .
Its prototype existed previously in
-.Aq Pa string.h
+.In string.h
before it was moved to
-.Aq Pa strings.h
+.In strings.h
for
.St -p1003.1-2001
compliance.
+.Pp
+The
+.Fn ffsl ,
+.Fn fls
+and
+.Fn flsl
+functions appeared in
+.Fx 5.3 .
static char sccsid[] = "@(#)ffs.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/string/ffs.c,v 1.5 2002/08/30 19:08:53 robert Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/string/ffs.c,v 1.7 2004/01/14 07:46:36 des Exp $");
#include <strings.h>
/*
- * ffs -- vax ffs instruction
+ * Find First Set bit
*/
int
ffs(int mask)
if (mask == 0)
return(0);
for (bit = 1; !(mask & 1); bit++)
- mask >>= 1;
- return(bit);
+ mask = (unsigned int)mask >> 1;
+ return (bit);
}
.\" SUCH DAMAGE.
.\"
.\" @(#)index.3 8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/string/index.3,v 1.8 2002/12/18 13:33:03 ru Exp $
+.\" $FreeBSD: src/lib/libc/string/index.3,v 1.11 2003/09/08 19:57:15 ru Exp $
.\"
.Dd June 4, 1993
.Dt INDEX 3
.Os
.Sh NAME
-.Nm index
+.Nm index , rindex
.Nd locate character in string
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In strings.h
-.Ft char *
+.Ft "char *"
.Fn index "const char *s" "int c"
+.Ft "char *"
+.Fn rindex "const char *s" "int c"
.Sh DESCRIPTION
The
.Fn index
function
-locates the first character matching
+locates the first occurrence of
.Fa c
(converted to a
.Vt char )
-in the null-terminated string
+in the string pointed to by
.Fa s .
-.Sh RETURN VALUES
-A pointer to the character is returned if it is found; otherwise
-.Dv NULL
-is returned.
-If
+The terminating null character is considered part of the string;
+therefore if
.Fa c
-is '\e0',
+is
+.Ql \e0 ,
+the functions locate the terminating
+.Ql \e0 .
+.Pp
+The
+.Fn rindex
+function is identical to
+.Fn index ,
+except it locates the last occurrence of
+.Fa c .
+.Sh RETURN VALUES
+The functions
.Fn index
-locates the terminating '\e0'.
+and
+.Fn rindex
+return a pointer to the located character, or
+.Dv NULL
+if the character does not appear in the string.
.Sh SEE ALSO
.Xr memchr 3 ,
-.Xr rindex 3 ,
.Xr strchr 3 ,
.Xr strcspn 3 ,
.Xr strpbrk 3 ,
.Xr strstr 3 ,
.Xr strtok 3
.Sh HISTORY
-A
+The
.Fn index
-function appeared in
+and
+.Fn rindex
+functions appeared in
.At v6 .
-Its prototype existed previously in
-.Aq Pa string.h
-before it was moved to
-.Aq Pa strings.h
+Their prototypes existed previously in
+.In string.h
+before they were moved to
+.In strings.h
for
.St -p1003.1-2001
compliance.
static char sccsid[] = "@(#)index.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/string/index.c,v 1.5 2002/08/30 19:42:07 robert Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/string/index.c,v 1.7 2003/12/18 07:44:53 jkh Exp $");
#include <stddef.h>
#endif
(const char *p, int ch)
{
+ char c;
+
+ c = ch;
for (;; ++p) {
- if (*p == ch)
+ if (*p == c)
return ((char *)p);
if (*p == '\0')
return (NULL);
+++ /dev/null
---- index.c.orig Tue May 20 15:23:54 2003
-+++ index.c Tue Dec 16 00:58:24 2003
-@@ -52,8 +52,9 @@
- #endif
- (const char *p, int ch)
- {
-+ char c = ch;
- for (;; ++p) {
-- if (*p == ch)
-+ if (*p == c)
- return ((char *)p);
- if (*p == '\0')
- return (NULL);
static char sccsid[] = "@(#)rindex.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/string/rindex.c,v 1.5 2002/08/30 19:42:07 robert Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/string/rindex.c,v 1.7 2003/12/18 07:44:53 jkh Exp $");
#include <stddef.h>
(const char *p, int ch)
{
char *save;
+ char c;
+ c = ch;
for (save = NULL;; ++p) {
- if (*p == ch)
+ if (*p == c)
save = (char *)p;
if (*p == '\0')
return (save);
+++ /dev/null
---- rindex.c.orig Tue May 20 15:23:54 2003
-+++ rindex.c Tue Dec 16 00:58:56 2003
-@@ -53,9 +53,10 @@
- (const char *p, int ch)
- {
- char *save;
-+ char c = ch;
-
- for (save = NULL;; ++p) {
-- if (*p == ch)
-+ if (*p == c)
- save = (char *)p;
- if (*p == '\0')
- return (save);
.\" SUCH DAMAGE.
.\"
.\" @(#)strcasecmp.3 8.1 (Berkeley) 6/9/93
-.\" $FreeBSD: src/lib/libc/string/strcasecmp.3,v 1.10 2002/08/30 15:40:01 robert Exp $
+.\" $FreeBSD: src/lib/libc/string/strcasecmp.3,v 1.11 2003/09/08 19:57:15 ru Exp $
.\"
.Dd June 9, 1993
.Dt STRCASECMP 3
functions first appeared in
.Bx 4.4 .
Their prototypes existed previously in
-.Aq Pa string.h
+.In string.h
before they were moved to
-.Aq Pa strings.h
+.In strings.h
for
.St -p1003.1-2001
compliance.
--- /dev/null
+--- strcasecmp.3.orig Fri Mar 11 08:37:27 2005
++++ strcasecmp.3 Fri Mar 11 08:38:54 2005
+@@ -39,7 +39,9 @@
+ .Os
+ .Sh NAME
+ .Nm strcasecmp ,
+-.Nm strncasecmp
++.Nm strncasecmp ,
++.Nm strcasecmp_l ,
++.Nm strncasecmp_l
+ .Nd compare strings, ignoring case
+ .Sh LIBRARY
+ .Lb libc
+@@ -49,6 +51,11 @@
+ .Fn strcasecmp "const char *s1" "const char *s2"
+ .Ft int
+ .Fn strncasecmp "const char *s1" "const char *s2" "size_t len"
++.In xlocale.h
++.Ft int
++.Fn strcasecmp_l "const char *s1" "const char *s2" "locale_t loc"
++.Ft int
++.Fn strncasecmp_l "const char *s1" "const char *s2" "size_t len" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn strcasecmp
+@@ -65,6 +72,18 @@
+ compares at most
+ .Fa len
+ characters.
++.Pp
++While the
++.Fn strcasecmp
++and
++.Fn strncasecmp
++functions use the current locale, the
++.Fn strcasecmp_l
++and
++.Fn strncasecmp_l
++functions may be passed locales directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn strcasecmp
+@@ -87,7 +106,8 @@
+ .Xr strcmp 3 ,
+ .Xr strcoll 3 ,
+ .Xr strxfrm 3 ,
+-.Xr tolower 3
++.Xr tolower 3 ,
++.Xr xlocale 3
+ .Sh HISTORY
+ The
+ .Fn strcasecmp
--- /dev/null
+--- strcasecmp.c.orig 2003-05-20 15:23:54.000000000 -0700
++++ strcasecmp.c 2005-02-18 18:46:40.000000000 -0800
+@@ -37,41 +37,62 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/string/strcasecmp.c,v 1.6 2002/08/30 15:40:01 robert Exp $");
+
++#include "xlocale_private.h"
++
+ #include <strings.h>
+ #include <ctype.h>
+
+ typedef unsigned char u_char;
+
+ int
+-strcasecmp(s1, s2)
++strcasecmp_l(s1, s2, loc)
+ const char *s1, *s2;
++ locale_t loc;
+ {
+ const u_char
+ *us1 = (const u_char *)s1,
+ *us2 = (const u_char *)s2;
+
+- while (tolower(*us1) == tolower(*us2++))
++ NORMALIZE_LOCALE(loc);
++ while (tolower_l(*us1, loc) == tolower_l(*us2++, loc))
+ if (*us1++ == '\0')
+ return (0);
+- return (tolower(*us1) - tolower(*--us2));
++ return (tolower_l(*us1, loc) - tolower_l(*--us2, loc));
+ }
+
+ int
+-strncasecmp(s1, s2, n)
++strcasecmp(s1, s2)
++ const char *s1, *s2;
++{
++ return strcasecmp_l(s1, s2, __current_locale());
++}
++
++int
++strncasecmp_l(s1, s2, n, loc)
+ const char *s1, *s2;
+ size_t n;
++ locale_t loc;
+ {
++ NORMALIZE_LOCALE(loc);
+ if (n != 0) {
+ const u_char
+ *us1 = (const u_char *)s1,
+ *us2 = (const u_char *)s2;
+
+ do {
+- if (tolower(*us1) != tolower(*us2++))
+- return (tolower(*us1) - tolower(*--us2));
++ if (tolower_l(*us1, loc) != tolower_l(*us2++, loc))
++ return (tolower_l(*us1, loc) - tolower_l(*--us2, loc));
+ if (*us1++ == '\0')
+ break;
+ } while (--n != 0);
+ }
+ return (0);
+ }
++
++int
++strncasecmp(s1, s2, n)
++ const char *s1, *s2;
++ size_t n;
++{
++ return strncasecmp_l(s1, s2, n, __current_locale());
++}
--- /dev/null
+--- strcasestr.c.orig 2003-05-20 15:23:54.000000000 -0700
++++ strcasestr.c 2005-02-18 18:48:55.000000000 -0800
+@@ -37,6 +37,8 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/string/strcasestr.c,v 1.3 2002/03/21 18:44:54 obrien Exp $");
+
++#include "xlocale_private.h"
++
+ #include <ctype.h>
+ #include <string.h>
+
+@@ -44,22 +46,31 @@
+ * Find the first occurrence of find in s, ignore case.
+ */
+ char *
+-strcasestr(s, find)
++strcasestr_l(s, find, loc)
+ const char *s, *find;
++ locale_t loc;
+ {
+ char c, sc;
+ size_t len;
+
++ NORMALIZE_LOCALE(loc);
+ if ((c = *find++) != 0) {
+- c = tolower((unsigned char)c);
++ c = tolower_l((unsigned char)c, loc);
+ len = strlen(find);
+ do {
+ do {
+ if ((sc = *s++) == 0)
+ return (NULL);
+- } while ((char)tolower((unsigned char)sc) != c);
+- } while (strncasecmp(s, find, len) != 0);
++ } while ((char)tolower_l((unsigned char)sc, loc) != c);
++ } while (strncasecmp_l(s, find, len, loc) != 0);
+ s--;
+ }
+ return ((char *)s);
+ }
++
++char *
++strcasestr(s, find)
++ const char *s, *find;
++{
++ return strcasestr_l(s, find, __current_locale());
++}
.\" SUCH DAMAGE.
.\"
.\" @(#)strchr.3 8.2 (Berkeley) 4/19/94
-.\" $FreeBSD: src/lib/libc/string/strchr.3,v 1.9 2002/12/18 13:33:03 ru Exp $
+.\" $FreeBSD: src/lib/libc/string/strchr.3,v 1.11 2003/09/04 20:36:54 simon Exp $
.\"
.Dd April 19, 1994
.Dt STRCHR 3
.Os
.Sh NAME
-.Nm strchr
+.Nm strchr , strrchr
.Nd locate character in string
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In string.h
-.Ft char *
+.Ft "char *"
.Fn strchr "const char *s" "int c"
+.Ft "char *"
+.Fn strrchr "const char *s" "int c"
.Sh DESCRIPTION
The
.Fn strchr
function locates the first occurrence of
.Fa c
+(converted to a
+.Vt char )
in the string pointed to by
.Fa s .
-The terminating
-.Dv NUL
-character is considered part of the string.
-If
+The terminating null character is considered part of the string;
+therefore if
.Fa c
is
.Ql \e0 ,
-.Fn strchr
-locates the terminating
+the functions locate the terminating
.Ql \e0 .
+.Pp
+The
+.Fn strrchr
+function is identical to
+.Fn strchr
+except it locates the last occurrence of
+.Fa c .
.Sh RETURN VALUES
-The function
+The functions
.Fn strchr
-returns a pointer to the located character, or
+and
+.Fn strrchr
+return a pointer to the located character, or
.Dv NULL
if the character does not appear in the string.
.Sh SEE ALSO
.Xr memchr 3 ,
.Xr strcspn 3 ,
.Xr strpbrk 3 ,
-.Xr strrchr 3 ,
.Xr strsep 3 ,
.Xr strspn 3 ,
.Xr strstr 3 ,
.Xr strtok 3
.Sh STANDARDS
-The
+The functions
.Fn strchr
-function
-conforms to
+and
+.Fn strrchr
+conform to
.St -isoC .
--- /dev/null
+--- strcoll.3.orig Fri Mar 11 08:36:09 2005
++++ strcoll.3 Fri Mar 11 09:43:41 2005
+@@ -40,7 +40,8 @@
+ .Dt STRCOLL 3
+ .Os
+ .Sh NAME
+-.Nm strcoll
++.Nm strcoll ,
++.Nm strcoll_l
+ .Nd compare strings according to current collation
+ .Sh LIBRARY
+ .Lb libc
+@@ -48,6 +49,9 @@
+ .In string.h
+ .Ft int
+ .Fn strcoll "const char *s1" "const char *s2"
++.In xlocale.h
++.Ft int
++.Fn strcoll_l "const char *s1" "const char *s2" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn strcoll
+@@ -63,11 +67,20 @@
+ .Fa s1
+ is greater than, equal to, or less than
+ .Fa s2 .
++.Pp
++While the
++.Fn strcoll
++function uses the current locale, the
++.Fn strcoll_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh SEE ALSO
+ .Xr setlocale 3 ,
+ .Xr strcmp 3 ,
+ .Xr strxfrm 3 ,
+-.Xr wcscoll 3
++.Xr wcscoll 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn strcoll
--- /dev/null
+--- strcoll.c.orig 2003-05-20 15:23:54.000000000 -0700
++++ strcoll.c 2005-02-17 10:37:14.000000000 -0800
+@@ -28,26 +28,30 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/string/strcoll.c,v 1.13 2001/11/07 19:55:16 obrien Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdlib.h>
+ #include <string.h>
+ #include "collate.h"
+
+ int
+-strcoll(s, s2)
++strcoll_l(s, s2, loc)
+ const char *s, *s2;
++ locale_t loc;
+ {
+ int len, len2, prim, prim2, sec, sec2, ret, ret2;
+ const char *t, *t2;
+ char *tt, *tt2;
+
+- if (__collate_load_error)
++ NORMALIZE_LOCALE(loc);
++ if (loc->__collate_load_error)
+ return strcmp(s, s2);
+
+ len = len2 = 1;
+ ret = ret2 = 0;
+- if (__collate_substitute_nontrivial) {
+- t = tt = __collate_substitute(s);
+- t2 = tt2 = __collate_substitute(s2);
++ if (loc->__collate_substitute_nontrivial) {
++ t = tt = (char *)__collate_substitute_l((unsigned char *)s, loc);
++ t2 = tt2 = (char *)__collate_substitute_l((unsigned char *)s2, loc);
+ } else {
+ tt = tt2 = NULL;
+ t = s;
+@@ -56,11 +60,11 @@
+ while(*t && *t2) {
+ prim = prim2 = 0;
+ while(*t && !prim) {
+- __collate_lookup(t, &len, &prim, &sec);
++ __collate_lookup_l((unsigned char *)t, &len, &prim, &sec, loc);
+ t += len;
+ }
+ while(*t2 && !prim2) {
+- __collate_lookup(t2, &len2, &prim2, &sec2);
++ __collate_lookup_l((unsigned char *)t2, &len2, &prim2, &sec2, loc);
+ t2 += len2;
+ }
+ if(!prim || !prim2)
+@@ -73,9 +77,9 @@
+ ret2 = sec - sec2;
+ }
+ if(!*t && *t2)
+- ret = -(int)((u_char)*t2);
++ ret = -(int)((unsigned char)*t2);
+ else if(*t && !*t2)
+- ret = (u_char)*t;
++ ret = (unsigned char)*t;
+ else if(!*t && !*t2)
+ ret = ret2;
+ end:
+@@ -84,3 +88,10 @@
+
+ return ret;
+ }
++
++int
++strcoll(s, s2)
++ const char *s, *s2;
++{
++ return strcoll_l(s, s2, __current_locale());
++}
.\" SUCH DAMAGE.
.\"
.\" @(#)strerror.3 8.1 (Berkeley) 6/9/93
-.\" $FreeBSD: src/lib/libc/string/strerror.3,v 1.22 2002/12/19 10:24:52 tjr Exp $
+.\" $FreeBSD: src/lib/libc/string/strerror.3,v 1.23 2004/10/12 14:52:52 keramida Exp $
.\"
-.Dd December 19, 2002
+.Dd October 12, 2004
.Dt STRERROR 3
.Os
.Sh NAME
.Pq Dq Li ":\ " ;
otherwise, only the error message string is printed.
.Pp
-If
-.Fa errnum
-is not a recognized error number,
-.Fn strerror
-returns an error message string containing
+If the error number is not recognized, these functions return an error message
+string containing
.Dq Li "Unknown error:\ "
-followed by the error number in decimal, while
+followed by the error number in decimal.
+The
+.Fn strerror
+and
.Fn strerror_r
-leaves
-.Fa strerrbuf
-unchanged and returns
-.Er EINVAL .
+functions return
+.Er EINVAL
+as a warning.
Error numbers recognized by this implementation fall in
the range 0 <
.Fa errnum
static char sccsid[] = "@(#)strerror.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/string/strerror.c,v 1.11 2003/01/03 16:44:42 mike Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/string/strerror.c,v 1.13 2003/05/01 19:03:14 nectar Exp $");
#include <errno.h>
#include <stdio.h>
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $");
+static char *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/string/strlcat.c,v 1.7 2002/03/21 18:44:54 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/string/strlcat.c,v 1.10 2004/10/16 06:32:43 obrien Exp $");
#include <sys/types.h>
#include <string.h>
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/lib/libc/string/strlcpy.3,v 1.12 2002/12/18 12:45:11 ru Exp $
+.\" $FreeBSD: src/lib/libc/string/strlcpy.3,v 1.13 2004/07/02 23:52:13 ru Exp $
.\"
.Dd June 22, 1998
.Dt STRLCPY 3
.Fn strlcpy
and
.Fn strlcat
-functions copy and concatenate strings respectively. They are designed
+functions copy and concatenate strings respectively.
+They are designed
to be safer, more consistent, and less error prone replacements for
.Xr strncpy 3
and
and
.Fn strlcat
functions return the total length of the string they tried to
-create. For
+create.
+For
.Fn strlcpy
that means the length of
.Fa src .
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $");
+static char *rcsid = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/string/strlcpy.c,v 1.5 2002/03/21 18:44:54 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/string/strlcpy.c,v 1.8 2004/10/14 21:31:42 stefanf Exp $");
#include <sys/types.h>
#include <string.h>
.\" SUCH DAMAGE.
.\"
.\" @(#)strmode.3 8.3 (Berkeley) 7/28/94
-.\" $FreeBSD: src/lib/libc/string/strmode.3,v 1.8 2001/10/01 16:09:00 ru Exp $
+.\" $FreeBSD: src/lib/libc/string/strmode.3,v 1.9 2003/07/01 15:28:05 maxim Exp $
.\"
.Dd July 28, 1994
.Dt STRMODE 3
The last character is a plus sign ``+'' if any there are any alternate
or additional access control methods associated with the inode, otherwise
it will be a space.
-.Sh RETURN VALUES
-The
-.Fn strmode
-function
-always returns 0.
.Sh SEE ALSO
.Xr chmod 1 ,
.Xr find 1 ,
.\" SUCH DAMAGE.
.\"
.\" @(#)strsep.3 8.1 (Berkeley) 6/9/93
-.\" $FreeBSD: src/lib/libc/string/strsep.3,v 1.13 2002/11/29 15:57:49 ru Exp $
+.\" $FreeBSD: src/lib/libc/string/strsep.3,v 1.14 2004/07/02 23:52:13 ru Exp $
.\"
.Dd June 9, 1993
.Dt STRSEP 3
.Fn strtok
function should be preferred for portability reasons (it conforms to
.St -isoC )
-it is unable to handle empty fields, i.e. detect fields delimited by
+it is unable to handle empty fields, i.e., detect fields delimited by
two adjacent delimiter characters, or to be used for more than a single
string at a time.
The
--- /dev/null
+--- strstr.3.orig Fri Mar 11 08:33:31 2005
++++ strstr.3 Fri Mar 11 08:35:28 2005
+@@ -41,7 +41,7 @@
+ .Dt STRSTR 3
+ .Os
+ .Sh NAME
+-.Nm strstr , strcasestr , strnstr
++.Nm strstr , strcasestr , strnstr , strcasestr_l
+ .Nd locate a substring in a string
+ .Sh LIBRARY
+ .Lb libc
+@@ -53,6 +53,9 @@
+ .Fn strcasestr "const char *big" "const char *little"
+ .Ft char *
+ .Fn strnstr "const char *big" "const char *little" "size_t len"
++.In xlocale.h
++.Ft char *
++.Fn strcasestr_l "const char *big" "const char *little" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn strstr
+@@ -86,6 +89,14 @@
+ function is a
+ .Fx
+ specific API, it should only be used when portability is not a concern.
++.Pp
++While the
++.Fn strcasestr
++function uses the current locale, the
++.Fn strcasestr_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ If
+ .Fa little
+@@ -138,7 +149,8 @@
+ .Xr strrchr 3 ,
+ .Xr strsep 3 ,
+ .Xr strspn 3 ,
+-.Xr strtok 3
++.Xr strtok 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn strstr
--- /dev/null
+--- strxfrm.3.orig Fri Mar 11 08:32:37 2005
++++ strxfrm.3 Fri Mar 11 09:46:23 2005
+@@ -40,7 +40,8 @@
+ .Dt STRXFRM 3
+ .Os
+ .Sh NAME
+-.Nm strxfrm
++.Nm strxfrm ,
++.Nm strxfrm_l
+ .Nd transform a string under locale
+ .Sh LIBRARY
+ .Lb libc
+@@ -48,6 +49,9 @@
+ .In string.h
+ .Ft size_t
+ .Fn strxfrm "char * restrict dst" "const char * restrict src" "size_t n"
++.In xlocale.h
++.Ft size_t
++.Fn strxfrm_l "char * restrict dst" "const char * restrict src" "size_t n" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn strxfrm
+@@ -77,6 +81,14 @@
+ is equal to comparing
+ two original strings with
+ .Fn strcoll .
++.Pp
++While the
++.Fn strxfrm
++function uses the current locale, the
++.Fn strxfrm_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ Upon successful completion,
+ .Fn strxfrm
+@@ -91,7 +103,8 @@
+ .Xr setlocale 3 ,
+ .Xr strcmp 3 ,
+ .Xr strcoll 3 ,
+-.Xr wcsxfrm 3
++.Xr wcsxfrm 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn strxfrm
--- /dev/null
+--- strxfrm.c.orig 2003-05-20 15:23:55.000000000 -0700
++++ strxfrm.c 2005-02-17 15:06:28.000000000 -0800
+@@ -28,24 +28,28 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/string/strxfrm.c,v 1.15 2002/09/06 11:24:06 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdlib.h>
+ #include <string.h>
+ #include "collate.h"
+
+ size_t
+-strxfrm(char * __restrict dest, const char * __restrict src, size_t len)
++strxfrm_l(char * __restrict dest, const char * __restrict src, size_t len,
++ locale_t loc)
+ {
+ int prim, sec, l;
+ size_t slen;
+ char *s, *ss;
+
++ NORMALIZE_LOCALE(loc);
+ if (!*src) {
+ if (len > 0)
+ *dest = '\0';
+ return 0;
+ }
+
+- if (__collate_load_error) {
++ if (loc->__collate_load_error) {
+ slen = strlen(src);
+ if (len > 0) {
+ if (slen < len)
+@@ -60,10 +64,10 @@
+
+ slen = 0;
+ prim = sec = 0;
+- ss = s = __collate_substitute(src);
++ ss = s = (char *)__collate_substitute_l((unsigned char *)src, loc);
+ while (*s) {
+ while (*s && !prim) {
+- __collate_lookup(s, &l, &prim, &sec);
++ __collate_lookup_l((unsigned char *)s, &l, &prim, &sec, loc);
+ s += l;
+ }
+ if (prim) {
+@@ -81,3 +85,9 @@
+
+ return slen;
+ }
++
++size_t
++strxfrm(char * __restrict dest, const char * __restrict src, size_t len)
++{
++ return strxfrm_l(dest, src, len, __current_locale());
++}
--- /dev/null
+--- swab.c.orig 2004-08-03 14:33:13.000000000 -0700
++++ swab.c 2004-08-03 15:05:03.000000000 -0700
+@@ -43,12 +43,14 @@
+ #include <string.h>
+
+ void
+-swab(const void * __restrict from, void * __restrict to, size_t len)
++swab(const void * __restrict from, void * __restrict to, ssize_t len)
+ {
+ unsigned long temp;
+ int n;
+ char *fp, *tp;
+
++ if (len <= 0)
++ return;
+ n = len >> 1;
+ fp = (char *)from;
+ tp = (char *)to;
--- /dev/null
+--- wcscoll.3.orig Fri Mar 11 08:27:51 2005
++++ wcscoll.3 Fri Mar 11 08:29:43 2005
+@@ -41,7 +41,8 @@
+ .Dt WCSCOLL 3
+ .Os
+ .Sh NAME
+-.Nm wcscoll
++.Nm wcscoll ,
++.Nm wcscoll_l
+ .Nd compare wide strings according to current collation
+ .Sh LIBRARY
+ .Lb libc
+@@ -49,6 +50,9 @@
+ .In wchar.h
+ .Ft int
+ .Fn wcscoll "const wchar_t *s1" "const wchar_t *s2"
++.In xlocale.h
++.Ft int
++.Fn wcscoll_l "const wchar_t *s1" "const wchar_t *s2" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn wcscoll
+@@ -63,6 +67,14 @@
+ .Fn wcscoll
+ is equivalent to
+ .Fn wcscmp .
++.Pp
++While the
++.Fn wcscoll
++function uses the current locale, the
++.Fn wcscoll_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn wcscoll
+@@ -95,7 +107,8 @@
+ .Xr setlocale 3 ,
+ .Xr strcoll 3 ,
+ .Xr wcscmp 3 ,
+-.Xr wcsxfrm 3
++.Xr wcsxfrm 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn wcscoll
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/string/wcscoll.c,v 1.1 2002/10/04 03:18:26 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/string/wcscoll.c,v 1.3 2004/04/07 09:47:56 tjr Exp $");
#include <errno.h>
#include <stdlib.h>
static char *
__mbsdup(const wchar_t *ws)
{
- mbstate_t state;
+ static const mbstate_t initial;
+ mbstate_t st;
const wchar_t *wcp;
size_t len;
char *mbs;
- memset(&state, 0, sizeof(state));
wcp = ws;
- if ((len = wcsrtombs(NULL, &wcp, 0, &state)) == (size_t)-1)
+ st = initial;
+ if ((len = wcsrtombs(NULL, &wcp, 0, &st)) == (size_t)-1)
return (NULL);
if ((mbs = malloc(len + 1)) == NULL)
return (NULL);
- memset(&state, 0, sizeof(state));
- wcsrtombs(mbs, &ws, len + 1, &state);
+ st = initial;
+ wcsrtombs(mbs, &ws, len + 1, &st);
return (mbs);
}
--- /dev/null
+--- wcscoll.c.orig 2004-11-25 11:38:47.000000000 -0800
++++ wcscoll.c 2005-02-18 18:17:11.000000000 -0800
+@@ -27,13 +27,15 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/string/wcscoll.c,v 1.3 2004/04/07 09:47:56 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <errno.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include <wchar.h>
+ #include "collate.h"
+
+-static char *__mbsdup(const wchar_t *);
++static char *__mbsdup(const wchar_t *, locale_t);
+
+ /*
+ * Placeholder implementation of wcscoll(). Attempts to use the single-byte
+@@ -41,12 +43,13 @@
+ * with extended character sets.
+ */
+ int
+-wcscoll(const wchar_t *ws1, const wchar_t *ws2)
++wcscoll_l(const wchar_t *ws1, const wchar_t *ws2, locale_t loc)
+ {
+ char *mbs1, *mbs2;
+ int diff, sverrno;
+
+- if (__collate_load_error || MB_CUR_MAX > 1)
++ NORMALIZE_LOCALE(loc);
++ if (loc->__collate_load_error || MB_CUR_MAX_L(loc) > 1)
+ /*
+ * Locale has no special collating order, could not be
+ * loaded, or has an extended character set; do a fast binary
+@@ -54,7 +57,7 @@
+ */
+ return (wcscmp(ws1, ws2));
+
+- if ((mbs1 = __mbsdup(ws1)) == NULL || (mbs2 = __mbsdup(ws2)) == NULL) {
++ if ((mbs1 = __mbsdup(ws1, loc)) == NULL || (mbs2 = __mbsdup(ws2, loc)) == NULL) {
+ /*
+ * Out of memory or illegal wide chars; fall back to wcscmp()
+ * but leave errno indicating the error. Callers that don't
+@@ -67,7 +70,7 @@
+ return (wcscmp(ws1, ws2));
+ }
+
+- diff = strcoll(mbs1, mbs2);
++ diff = strcoll_l(mbs1, mbs2, loc);
+ sverrno = errno;
+ free(mbs1);
+ free(mbs2);
+@@ -76,8 +79,14 @@
+ return (diff);
+ }
+
++int
++wcscoll(const wchar_t *ws1, const wchar_t *ws2)
++{
++ return wcscoll_l(ws1, ws2, __current_locale());
++}
++
+ static char *
+-__mbsdup(const wchar_t *ws)
++__mbsdup(const wchar_t *ws, locale_t loc)
+ {
+ static const mbstate_t initial;
+ mbstate_t st;
+@@ -87,12 +96,12 @@
+
+ wcp = ws;
+ st = initial;
+- if ((len = wcsrtombs(NULL, &wcp, 0, &st)) == (size_t)-1)
++ if ((len = wcsrtombs_l(NULL, &wcp, 0, &st, loc)) == (size_t)-1)
+ return (NULL);
+ if ((mbs = malloc(len + 1)) == NULL)
+ return (NULL);
+ st = initial;
+- wcsrtombs(mbs, &ws, len + 1, &st);
++ wcsrtombs_l(mbs, &ws, len + 1, &st, loc);
+
+ return (mbs);
+ }
--- /dev/null
+--- wcswidth.3.orig Fri Mar 11 08:30:37 2005
++++ wcswidth.3 Fri Mar 11 08:31:35 2005
+@@ -28,7 +28,8 @@
+ .Dt WCSWIDTH 3
+ .Os
+ .Sh NAME
+-.Nm wcswidth
++.Nm wcswidth ,
++.Nm wcswidth_l
+ .Nd "number of column positions in wide-character string"
+ .Sh LIBRARY
+ .Lb libc
+@@ -36,6 +37,9 @@
+ .In wchar.h
+ .Ft int
+ .Fn wcswidth "const wchar_t *pwcs" "size_t n"
++.In xlocale.h
++.Ft int
++.Fn wcswidth_l "const wchar_t *pwcs" "size_t n" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn wcswidth
+@@ -44,6 +48,14 @@
+ characters of
+ .Fa pwcs ,
+ or until a null wide character (L'\e0') is encountered.
++.Pp
++While the
++.Fn wcswidth
++function uses the current locale, the
++.Fn wcswidth_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ The
+ .Fn wcswidth
+@@ -54,7 +66,8 @@
+ otherwise it returns the number of column positions occupied.
+ .Sh SEE ALSO
+ .Xr iswprint 3 ,
+-.Xr wcwidth 3
++.Xr wcwidth 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn wcswidth
--- /dev/null
+--- wcswidth.c.orig 2003-05-20 15:23:56.000000000 -0700
++++ wcswidth.c 2005-02-25 00:12:43.000000000 -0800
+@@ -42,20 +42,30 @@
+ #include <sys/cdefs.h>
+ __FBSDID("$FreeBSD: src/lib/libc/string/wcswidth.c,v 1.6 2002/08/20 02:06:28 ache Exp $");
+
++#include "xlocale_private.h"
++
+ #include <wchar.h>
+
+ int
+-wcswidth(const wchar_t *pwcs, size_t n)
++wcswidth_l(const wchar_t *pwcs, size_t n, locale_t loc)
+ {
+ wchar_t wc;
+ int len, l;
+
++ NORMALIZE_LOCALE(loc);
+ len = 0;
+ while (n-- > 0 && (wc = *pwcs++) != L'\0') {
+- if ((l = wcwidth(wc)) < 0)
++ if ((l = wcwidth_l(wc, loc)) < 0)
+ return (-1);
+ len += l;
+ }
+ return (len);
+ }
+
++
++int
++wcswidth(const wchar_t *pwcs, size_t n)
++{
++ return wcswidth_l(pwcs, n, __current_locale());
++}
++
--- /dev/null
+--- wcsxfrm.3.orig Fri Mar 11 08:31:43 2005
++++ wcsxfrm.3 Fri Mar 11 09:44:27 2005
+@@ -41,7 +41,8 @@
+ .Dt WCSXFRM 3
+ .Os
+ .Sh NAME
+-.Nm wcsxfrm
++.Nm wcsxfrm ,
++.Nm wcsxfrm_l
+ .Nd transform a wide string under locale
+ .Sh LIBRARY
+ .Lb libc
+@@ -49,6 +50,9 @@
+ .In wchar.h
+ .Ft size_t
+ .Fn wcsxfrm "wchar_t * restrict dst" "const wchar_t * restrict src" "size_t n"
++.In xlocale.h
++.Ft size_t
++.Fn wcsxfrm_l "wchar_t * restrict dst" "const wchar_t * restrict src" "size_t n" "locale_t loc"
+ .Sh DESCRIPTION
+ The
+ .Fn wcsxfrm
+@@ -80,6 +84,14 @@
+ is equivalent to comparing
+ two original strings with
+ .Fn wcscoll .
++.Pp
++While the
++.Fn wcsxfrm
++function uses the current locale, the
++.Fn wcsxfrm_l
++function may be passed a locale directly. See
++.Xr xlocale 3
++for more information.
+ .Sh RETURN VALUES
+ Upon successful completion,
+ .Fn wcsxfrm
+@@ -94,7 +106,8 @@
+ .Xr setlocale 3 ,
+ .Xr strxfrm 3 ,
+ .Xr wcscmp 3 ,
+-.Xr wcscoll 3
++.Xr wcscoll 3 ,
++.Xr xlocale 3
+ .Sh STANDARDS
+ The
+ .Fn wcsxfrm
#if 0
__FBSDID("FreeBSD: src/lib/libc/string/strxfrm.c,v 1.15 2002/09/06 11:24:06 tjr Exp ");
#endif
-__FBSDID("$FreeBSD: src/lib/libc/string/wcsxfrm.c,v 1.1 2002/10/04 03:18:26 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/string/wcsxfrm.c,v 1.3 2004/04/07 09:47:56 tjr Exp $");
#include <stdlib.h>
#include <string.h>
static char *
__mbsdup(const wchar_t *ws)
{
- mbstate_t state;
+ static const mbstate_t initial;
+ mbstate_t st;
const wchar_t *wcp;
size_t len;
char *mbs;
- memset(&state, 0, sizeof(state));
wcp = ws;
- if ((len = wcsrtombs(NULL, &wcp, 0, &state)) == (size_t)-1)
+ st = initial;
+ if ((len = wcsrtombs(NULL, &wcp, 0, &st)) == (size_t)-1)
return (NULL);
if ((mbs = malloc(len + 1)) == NULL)
return (NULL);
- memset(&state, 0, sizeof(state));
- wcsrtombs(mbs, &ws, len + 1, &state);
+ st = initial;
+ wcsrtombs(mbs, &ws, len + 1, &st);
return (mbs);
}
--- /dev/null
+--- wcsxfrm.c.orig Thu Nov 25 11:38:47 2004
++++ wcsxfrm.c Fri Feb 18 15:01:58 2005
+@@ -31,31 +31,35 @@
+ #endif
+ __FBSDID("$FreeBSD: src/lib/libc/string/wcsxfrm.c,v 1.3 2004/04/07 09:47:56 tjr Exp $");
+
++#include "xlocale_private.h"
++
+ #include <stdlib.h>
+ #include <string.h>
+ #include <wchar.h>
+ #include "collate.h"
+
+-static char *__mbsdup(const wchar_t *);
++static char *__mbsdup(const wchar_t *, locale_t);
+
+ /*
+ * Placeholder wcsxfrm() implementation. See wcscoll.c for a description of
+ * the logic used.
+ */
+ size_t
+-wcsxfrm(wchar_t * __restrict dest, const wchar_t * __restrict src, size_t len)
++wcsxfrm_l(wchar_t * __restrict dest, const wchar_t * __restrict src, size_t len,
++ locale_t loc)
+ {
+ int prim, sec, l;
+ size_t slen;
+ char *mbsrc, *s, *ss;
+
++ NORMALIZE_LOCALE(loc);
+ if (*src == L'\0') {
+ if (len != 0)
+ *dest = L'\0';
+ return (0);
+ }
+
+- if (__collate_load_error || MB_CUR_MAX > 1) {
++ if (loc->__collate_load_error || MB_CUR_MAX_L(loc) > 1) {
+ slen = wcslen(src);
+ if (len > 0) {
+ if (slen < len)
+@@ -68,13 +72,13 @@
+ return (slen);
+ }
+
+- mbsrc = __mbsdup(src);
++ mbsrc = __mbsdup(src, loc);
+ slen = 0;
+ prim = sec = 0;
+- ss = s = __collate_substitute(mbsrc);
++ ss = s = (char *)__collate_substitute_l((unsigned char *)mbsrc, loc);
+ while (*s != '\0') {
+ while (*s != '\0' && prim == 0) {
+- __collate_lookup(s, &l, &prim, &sec);
++ __collate_lookup_l((unsigned char *)s, &l, &prim, &sec, loc);
+ s += l;
+ }
+ if (prim != 0) {
+@@ -94,8 +98,14 @@
+ return (slen);
+ }
+
++size_t
++wcsxfrm(wchar_t * __restrict dest, const wchar_t * __restrict src, size_t len)
++{
++ return wcsxfrm_l(dest, src, len, __current_locale());
++}
++
+ static char *
+-__mbsdup(const wchar_t *ws)
++__mbsdup(const wchar_t *ws, locale_t loc)
+ {
+ static const mbstate_t initial;
+ mbstate_t st;
+@@ -105,12 +115,12 @@
+
+ wcp = ws;
+ st = initial;
+- if ((len = wcsrtombs(NULL, &wcp, 0, &st)) == (size_t)-1)
++ if ((len = wcsrtombs_l(NULL, &wcp, 0, &st, loc)) == (size_t)-1)
+ return (NULL);
+ if ((mbs = malloc(len + 1)) == NULL)
+ return (NULL);
+ st = initial;
+- wcsrtombs(mbs, &ws, len + 1, &st);
++ wcsrtombs_l(mbs, &ws, len + 1, &st, loc);
+
+ return (mbs);
+ }
.include "Makefile.fbsd_end"
MLINKS+=strcasecmp.3 strncasecmp.3
+MLINKS+=strcasecmp.3 strcasecmp_l.3
+MLINKS+=strcasecmp.3 strncasecmp_l.3
MLINKS+=strcat.3 strncat.3
MLINKS+=strcmp.3 strncmp.3
+MLINKS+=strcoll.3 strcoll_l.3
MLINKS+=strcpy.3 stpcpy.3
MLINKS+=strcpy.3 strncpy.3
MLINKS+=strerror.3 perror.3 strerror.3 sys_errlist.3 strerror.3 sys_nerr.3
MLINKS+=strtok.3 strtok_r.3
MLINKS+=strstr.3 strcasestr.3
MLINKS+=strstr.3 strnstr.3
+MLINKS+=strstr.3 strcasestr_l.3
+MLINKS+=strxfrm.3 strxfrm_l.3
+MLINKS+=wcscoll.3 wcscoll_l.3
+MLINKS+=wcswidth.3 wcswidth_l.3
+MLINKS+=wcsxfrm.3 wcsxfrm_l.3
MLINKS+=wmemchr.3 wmemcmp.3 wmemchr.3 wmemcpy.3 \
wmemchr.3 wmemmove.3 wmemchr.3 wmemset.3 \
wmemchr.3 wcscat.3 wmemchr.3 wcschr.3 \
--- /dev/null
+g/^\/\/Begin-Libc$/.,/^\/\/End-Libc$/d
+w
# Sources common to both syscall interfaces:
# 3375657: patches for sem_open() sem_unlink() shm_open() shm_unlink()
-MISRCS+= errno.c gettimeofday.c sigcatch.c sigsuspend.c getdtablesize.c \
+MISRCS+= errno.c gettimeofday.c sigcatch.c sigsuspend.c \
sigaction.c sigtramp.c crt_externs.c \
- sem_open.c sem_unlink.c shm_open.c shm_unlink.c fix-3375657.c
+ sem_open.c sem_unlink.c shm_open.c shm_unlink.c fix-3375657.c \
+ accessx_np.c chmodx_np.c getsgroups_np.c \
+ getwgroups_np.c openx_np.c mmap.c \
+ pthread_getuid_np.c pthread_setuid_np.c setsgroups_np.c \
+ setwgroups_np.c statx_np.c umaskx_np.c \
+ semctl.c shmctl.c msgctl.c \
+ mprotect.c msync.c munmap.c other_libc_init.c
.for _src in sem_open.c sem_unlink.c shm_open.c shm_unlink.c fix-3375657.c
CFLAGS-${_src} += -D__APPLE_PR3375657_HACK__
.endfor
+UNIX03SRCS += mmap.c mprotect.c msgctl.c msync.c munmap.c semctl.c shmctl.c
+
# Add machine dependent asm sources:
SRCS+=${MDASM}
sem_unlink.2 sem_wait.2 shm_open.2 shm_unlink.2 \
sigwait.2 getdtablesize.2 setreuid.2 setregid.2 \
nanosleep.2
-MAN3+= atomic.3 atomicqueue.3 barrier.3 spinlock.3
+MAN3+= atomic.3 barrier.3 spinlock.3
MLINKS+= atomic.3 OSAtomicAdd32.3
MLINKS+= atomic.3 OSAtomicIncrement32.3
MLINKS+= atomic.3 OSAtomicDecrement32.3
MLINKS+= atomic.3 OSAtomicCompareAndSwap64.3
MLINKS+= atomic.3 OSAtomicTestAndSet.3
MLINKS+= atomic.3 OSAtomicTestAndClear.3
-MLINKS+= atomicqueue.3 OSAtomicDequeue.3
-MLINKS+= atomicqueue.3 OSAtomicEnqueue.3
MLINKS+= barrier.3 OSMemoryBarrier.3
MLINKS+= spinlock.3 OSSpinLockTry.3
MLINKS+= spinlock.3 OSSpinLockLock.3
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <sys/syscall.h>
+#include <unistd.h>
+
+int
+accessx_np(const struct accessx_descriptor *entries, size_t desc_size, int *results, uid_t uid)
+{
+ return syscall(SYS_access_extended, entries, desc_size, results, uid);
+}
.Os Darwin
.Sh NAME
.Nm OSAtomicAdd32 ,
+.Nm OSAtomicAdd32Barrier ,
.Nm OSAtomicIncrement32 ,
+.Nm OSAtomicIncrement32Barrier ,
.Nm OSAtomicDecrement32 ,
+.Nm OSAtomicDecrement32Barrier ,
.Nm OSAtomicOr32 ,
+.Nm OSAtomicOr32Barrier ,
.Nm OSAtomicAnd32 ,
+.Nm OSAtomicAnd32Barrier ,
.Nm OSAtomicXor32 ,
+.Nm OSAtomicXor32Barrier ,
.Nm OSAtomicAdd64 ,
+.Nm OSAtomicAdd64Barrier ,
.Nm OSAtomicIncrement64 ,
+.Nm OSAtomicIncrement64Barrier ,
.Nm OSAtomicDecrement64 ,
+.Nm OSAtomicDecrement64Barrier ,
.Nm OSAtomicCompareAndSwap32 ,
+.Nm OSAtomicCompareAndSwap32Barrier ,
.Nm OSAtomicCompareAndSwap64 ,
+.Nm OSAtomicCompareAndSwap64Barrier ,
.Nm OSAtomicTestAndSet ,
-.Nm OSAtomicTestAndClear
+.Nm OSAtomicTestAndSetBarrier ,
+.Nm OSAtomicTestAndClear ,
+.Nm OSAtomicTestAndClearBarrier
.Nd atomic add, increment, decrement, or, and, xor, compare and swap, test and set, and test and clear
.Sh LIBRARY
.Lb libc
.Ft int32_t
.Fn OSAtomicAdd32 "int32_t theAmount, int32_t *theValue"
.Ft int32_t
+.Fn OSAtomicAdd32Barrier "int32_t theAmount, int32_t *theValue"
+.Ft int32_t
.Fn OSAtomicIncrement32 "int32_t *theValue"
.Ft int32_t
+.Fn OSAtomicIncrement32Barrier "int32_t *theValue"
+.Ft int32_t
.Fn OSAtomicDecrement32 "int32_t *theValue"
.Ft int32_t
+.Fn OSAtomicDecrement32Barrier "int32_t *theValue"
+.Ft int32_t
.Fn OSAtomicOr32 "uint32_t theMask, uint32_t *theValue"
.Ft int32_t
+.Fn OSAtomicOr32Barrier "uint32_t theMask, uint32_t *theValue"
+.Ft int32_t
.Fn OSAtomicAnd32 "uint32_t theMask, uint32_t *theValue"
.Ft int32_t
+.Fn OSAtomicAnd32Barrier "uint32_t theMask, uint32_t *theValue"
+.Ft int32_t
.Fn OSAtomicXor32 "uint32_t theMask, uint32_t *theValue"
+.Ft int32_t
+.Fn OSAtomicXor32Barrier "uint32_t theMask, uint32_t *theValue"
.Ft int64_t
.Fn OSAtomicAdd64 "int64_t theAmount, int64_t *theValue"
.Ft int64_t
+.Fn OSAtomicAdd64Barrier "int64_t theAmount, int64_t *theValue"
+.Ft int64_t
.Fn OSAtomicIncrement64 "int64_t *theValue"
.Ft int64_t
+.Fn OSAtomicIncrement64Barrier "int64_t *theValue"
+.Ft int64_t
.Fn OSAtomicDecrement64 "int64_t *theValue"
+.Ft int64_t
+.Fn OSAtomicDecrement64Barrier "int64_t *theValue"
.Ft bool
.Fn OSAtomicCompareAndSwap32 "int32_t oldValue" "int32_t newValue" "int32_t *theValue"
.Ft bool
+.Fn OSAtomicCompareAndSwap32Barrier "int32_t oldValue" "int32_t newValue" "int32_t *theValue"
+.Ft bool
.Fn OSAtomicCompareAndSwap64 "int64_t oldValue" "int64_t newValue" "int64_t *theValue"
.Ft bool
+.Fn OSAtomicCompareAndSwap64Barrier "int64_t oldValue" "int64_t newValue" "int64_t *theValue"
+.Ft bool
.Fn OSAtomicTestAndSet "uint32_t n, void *theAddress"
.Ft bool
+.Fn OSAtomicTestAndSetBarrier "uint32_t n, void *theAddress"
+.Ft bool
.Fn OSAtomicTestAndClear "uint32_t n, void *theAddress"
+.Ft bool
+.Fn OSAtomicTestAndClearBarrier "uint32_t n, void *theAddress"
.Sh DESCRIPTION
-These functions are thread and multiprocessor safe, but do not incorporate memory barriers
-and thus cannot be used by themselves to synchronize shared memory other than the memory
-being operated on (ie,
-.Fa theValue
-and
-.Fa theAddress
-). The logical (and, or, xor) and bit test operations are layered on top of the
+These functions are thread and multiprocessor safe. For each function, there
+is a version that does and anoother that does not incorporate a memory barrier.
+Barriers strictly order memory access on a weakly-ordered
+architecture such as PPC. All loads and stores executed in sequential program
+order before the barrier will complete before any load or store executed after
+the barrier. On a uniprocessor, the barrier operation is typically a nop.
+On a multiprocessor, the barrier can be quite expensive.
+.Pp
+Most code will want to use the barrier functions to insure that memory shared
+between threads is properly synchronized. For example, if you want to initialize
+a shared data structure and then atomically increment a variable to indicate
+that the initialization is complete, then you MUST use OSAtomicIncrement32Barrier()
+to ensure that the stores to your data structure complete before the atomic add.
+Likewise, the consumer of that data structure MUST use OSAtomicDecrement32Barrier(),
+in order to ensure that their loads of the structure are not executed before
+the atomic decrement. On the other hand,
+if you are simply incrementing a global counter, then it is safe and potentially much
+faster to use OSAtomicIncrement32(). If you are unsure which version to use, prefer
+the barrier variants as they are safer.
+.Pp
+The logical (and, or, xor) and bit test operations are layered on top of the
.Fn OSAtomicCompareAndSwap
-primitives. The memory address
+primitives.
+.Pp
+The memory address
.Fa theValue
must be naturally aligned, ie 32-bit aligned for 32-bit operations and 64-bit
-aligned for 64-bit operations. The 64-bit operations are only implemented for
+aligned for 64-bit operations.
+.Pp
+The 64-bit operations are only implemented for
64-bit processes.
.Pp
.Fn OSAtomicCompareAndSwap32
+++ /dev/null
-.Dd May 26, 2004
-.Dt ATOMICQUEUE 3
-.Os Darwin
-.Sh NAME
-.Nm OSAtomicEnqueue ,
-.Nm OSAtomicDequeue
-.Nd atomic enqueue and dequeue on a singly linked list
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In libkern/OSAtomic.h
-.Ft void
-.Fn OSAtomicEnqueue "void ** inList, void * inNewLink, size_t inOffset"
-.Ft void *
-.Fn OSAtomicDequeue "void ** inList, size_t inOffset"
-.Sh DESCRIPTION
-.Fn OSAtomicEnqueue
-and
-.Fn OSAtomicDequeue
-operate on zero-terminated singly-linked lists of structures whose
-link field need not be the first element.
-They are thread safe and incorporate memory barriers as required to
-synchronize access to the shared memory. The list is last in, first out.
-.Pp
-If thread safety is not a requirement, then the queue(3) package is more
-flexible and possibly more efficient.
-.Pp
-.Fa inList
-is the pointer to the head of the list. It is not a structure, and should be
-initialized to
-.Dv NIL .
-.Fa inOffset
-is the offset within the structure of the link field.
-.Fa inNewLink
-is a pointer to the structure to be queued on the list:
-.Bd -literal -offset indent
-typedef struct node {
- long data1;
- struct node *link;
- int data2;
-} node;
-
-node *head = NIL;
-node n1, n2;
-node *p;
-
-/* put n1 on the list */
-OSAtomicEnqueue( (void**) &head, &n1, offsetof(node,link));
-
-/* then put n2 on the list */
-OSAtomicEnqueue( (void**) &head, &n2, offsetof(node,link));
-
-/* dequeue n2 (ie, the node most recently added) */
-p = OSAtomicDequeue( (void**) &head, offsetof(node,link));
-.Ed
-.Sh RETURN VALUES
-.Fn OSAtomicDequeue
-returns a pointer to the node removed from the list, or
-.Dv NIL
-if the list is empty.
-.Sh SEE ALSO
-.Xr atomic 3 ,
-.Xr spinlock 3 ,
-.Xr barrier 3 ,
-.Xr queue 3
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <sys/acl.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <uuid/uuid.h>
+
+#if 1 /* for turdfile code only */
+#include <string.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <stdlib.h>
+#endif
+
+static int chmodx_syscall(void *obj, uid_t fsowner, gid_t fsgrp, int mode, struct kauth_filesec *fsacl);
+static int fchmodx_syscall(void *obj, uid_t fsowner, gid_t fsgrp, int mode, struct kauth_filesec *fsacl);
+
+static int chmodx1(void *obj,
+ int (* chmod_syscall)(void *obj, uid_t fsowner, gid_t fsgrp, int mode,
+ struct kauth_filesec *fsacl),
+ filesec_t fsec);
+
+/*
+ * Chmod interfaces.
+ */
+int
+chmodx_np(const char *path, filesec_t fsec)
+{
+ return(chmodx1((void *)&path, chmodx_syscall, fsec));
+}
+
+int
+fchmodx_np(int fd, filesec_t fsec)
+{
+ return(chmodx1((void *)&fd, fchmodx_syscall, fsec));
+}
+
+/*
+ * Chmod syscalls.
+ */
+static int
+chmodx_syscall(void *obj, uid_t fsowner, gid_t fsgrp, int mode, struct kauth_filesec *fsacl)
+{
+ char *path = *(char **)obj;
+
+ return(syscall(SYS_chmod_extended, path, fsowner, fsgrp, mode, fsacl));
+}
+
+static int
+fchmodx_syscall(void *obj, uid_t fsowner, gid_t fsgrp, int mode, struct kauth_filesec *fsacl)
+{
+ int fd = *(int *)obj;
+ return(syscall(SYS_fchmod_extended, fd, fsowner, fsgrp, mode, fsacl));
+}
+
+/*
+ * Chmod internals.
+ */
+
+static int
+chmodx1(void *obj,
+ int (chmod_syscall)(void *obj, uid_t fsowner, gid_t fsgrp, int mode, struct kauth_filesec *fsacl),
+ filesec_t fsec)
+{
+ uid_t fsowner = KAUTH_UID_NONE;
+ gid_t fsgrp = KAUTH_GID_NONE;
+ mode_t fsec_mode;
+ int fsmode = -1;
+ size_t size = 0;
+ int fsacl_used = 0;
+ int delete_acl = 0;
+ struct kauth_filesec *fsacl = NULL;
+ struct kauth_filesec static_filesec;
+
+ if (fsec == NULL) {
+ errno = EINVAL;
+ return(-1);
+ }
+
+ /* regular properties */
+ if ((filesec_get_property(fsec, FILESEC_OWNER, &fsowner) != 0) && (errno != ENOENT))
+ return(-1);
+ if ((filesec_get_property(fsec, FILESEC_GROUP, &fsgrp) != 0) && (errno != ENOENT))
+ return(-1);
+ if ((filesec_get_property(fsec, FILESEC_MODE, &fsec_mode)) != 0) {
+ if (errno != ENOENT)
+ return(-1);
+ } else {
+ /* cast up */
+ fsmode = fsec_mode;
+ }
+
+ /*
+ * We can set any or all of the ACL and UUIDs, but the two are transported in one
+ * structure. If we have an ACL, we'll use its allocated structure, otherwise we
+ * need our own.
+ */
+ if (((filesec_get_property(fsec, FILESEC_ACL_RAW, &fsacl) != 0) ||
+ (filesec_get_property(fsec, FILESEC_ACL_ALLOCSIZE, &size) != 0)) &&
+ (errno != ENOENT))
+ return(-1);
+ /* caller wants to delete ACL, must remember this */
+ if (fsacl == _FILESEC_REMOVE_ACL) {
+ delete_acl = 1;
+ fsacl = 0;
+ }
+
+ /* no ACL, use local filesec */
+ if (fsacl == NULL) {
+ bzero(&static_filesec, sizeof(static_filesec));
+ fsacl = &static_filesec;
+ fsacl->fsec_magic = KAUTH_FILESEC_MAGIC;
+ fsacl->fsec_entrycount = KAUTH_FILESEC_NOACL;
+ } else {
+ fsacl_used = 1;
+ }
+
+ /* grab the owner and group UUID if present */
+ if (filesec_get_property(fsec, FILESEC_UUID, &fsacl->fsec_owner) != 0) {
+ if (errno != ENOENT)
+ return(-1);
+ bzero(&fsacl->fsec_owner, sizeof(fsacl->fsec_owner));
+ } else {
+ fsacl_used = 1;
+ }
+ if (filesec_get_property(fsec, FILESEC_GRPUUID, &fsacl->fsec_group) != 0) {
+ if (errno != ENOENT)
+ return(-1);
+ bzero(&fsacl->fsec_group, sizeof(fsacl->fsec_group));
+ } else {
+ fsacl_used = 1;
+ }
+
+ /* after all this, if we didn't find anything that needs it, don't pass it in */
+ if (!fsacl_used) {
+ /*
+ * If the caller was trying to remove the ACL, and there are no UUIDs,
+ * we can tell the kernel to completely nuke the whole datastructure.
+ */
+ if (delete_acl) {
+ fsacl = _FILESEC_REMOVE_ACL;
+ } else {
+ fsacl = NULL;
+ }
+ }
+
+ return(chmod_syscall(obj, fsowner, fsgrp, fsmode, fsacl));
+}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <fcntl.h>
+#include <stdarg.h>
+
+int __fcntl(int, int, void *);
+/*
+ * Stub function to account for the differences in the size of the third
+ * argument when int and void * are different sizes.
+ */
+int
+fcntl(int fd, int cmd, ...)
+{
+ va_list ap;
+ void *arg;
+
+ va_start(ap, cmd);
+ switch(cmd) {
+ case F_GETLK:
+ case F_SETLK:
+ case F_SETLKW:
+ case F_PREALLOCATE:
+ case F_RDADVISE:
+ case F_READBOOTSTRAP:
+ case F_WRITEBOOTSTRAP:
+ case F_LOG2PHYS:
+ arg = va_arg(ap, void *);
+ break;
+ default:
+ arg = (void *)((unsigned long)va_arg(ap, int));
+ break;
+ }
+ va_end(ap);
+ return (__fcntl(fd, cmd, arg));
+}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
+++ /dev/null
-/*
- * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-#include <unistd.h>
-
-int getdtablesize() {
- return sysconf(_SC_OPEN_MAX);
-}
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <sys/syscall.h>
+#include <unistd.h>
+
+int
+getsgroups_np(int *uuidsetlen, uuid_t uuidset)
+{
+ return syscall(SYS_getsgroups, uuidsetlen, uuidset);
+}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <sys/syscall.h>
+#include <unistd.h>
+
+int
+getwgroups_np(int *uuidsetlen, uuid_t uuidset)
+{
+ return syscall(SYS_getwgroups, uuidsetlen, uuidset);
+}
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <sys/ioctl.h>
+#include <stdarg.h>
+
+int __ioctl(int, unsigned long, void *);
+/*
+ * Stub function to account for the third argument being void *
+ */
+int
+ioctl(int d, unsigned long request, ...)
+{
+ va_list ap;
+ void *arg;
+
+ va_start(ap, request);
+ arg = va_arg(ap, void *);
+ va_end(ap);
+ return (__ioctl(d, request, arg));
+}
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <sys/mman.h>
+#include <sys/syscall.h>
+#include <mach/vm_param.h>
+#include <errno.h>
+
+void *__mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off);
+
+/*
+ * mmap stub, with preemptory failures due to extra parameter checking
+ * mandated for conformance.
+ */
+void *
+mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off)
+{
+#if __DARWIN_UNIX03
+ /*
+ * Preemptory failures:
+ *
+ * o off is not a multiple of the page size
+ * o flags does not contain either MAP_PRIVATE or MAP_SHARED
+ * o len is zero
+ */
+ extern void cthread_set_errno_self(int);
+ if ((off & PAGE_MASK) ||
+ (((flags & MAP_PRIVATE) != MAP_PRIVATE) &&
+ ((flags & MAP_SHARED) != MAP_SHARED)) ||
+ (len == 0)) {
+ cthread_set_errno_self(EINVAL);
+ return(MAP_FAILED);
+ }
+#endif /* __DARWIN_UNIX03 */
+
+ return(__mmap(addr, len, prot, flags, fildes, off));
+}
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/syscall.h>
+
+/*
+ * Stub function to account for the differences in standard compliance
+ * while maintaining binary backward compatibility.
+ */
+int
+mprotect(void *addr, size_t len, int prot)
+{
+#if __DARWIN_UNIX03
+ return syscall(SYS_mprotect, addr, len, prot);
+#else /* !__DARWIN_UNIX03 */
+ void *aligned_addr;
+ int page_mask;
+ size_t offset;
+ int rv;
+
+ /*
+ * Page-align "addr" since the system now requires it
+ * for standards compliance.
+ * Update "len" to reflect the alignment.
+ */
+ page_mask = getpagesize() - 1;
+ offset = ((uintptr_t) addr) & page_mask;
+ aligned_addr = (void *) (((uintptr_t) addr) & ~page_mask);
+ len += offset;
+ rv = syscall(SYS_mprotect, aligned_addr, len, prot);
+ if (rv == -1 && errno == ENOMEM) {
+ /*
+ * Standards now require that we return ENOMEM if there was
+ * a hole in the address range. Panther and earlier used
+ * to return an EINVAL error, so honor backwards compatibility.
+ */
+ errno = EINVAL;
+ }
+ return rv;
+#endif /* !__DARWIN_UNIX03 */
+}
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <unistd.h>
+#include <stdarg.h>
+#include <sys/msg.h>
+#include <sys/syscall.h>
+
+/*
+ * Stub function to account for the differences in the ipc_perm structure,
+ * while maintaining binary backward compatibility.
+ */
+int
+msgctl(int msqid, int cmd, struct msqid_ds *ds)
+{
+#ifdef __DARWIN_UNIX03
+ return syscall(SYS_msgctl, msqid, cmd, ds);
+#else /* !__DARWIN_UNIX03 */
+ struct __msqid_ds_old *ds_old = ds;
+ struct __msqid_ds_new ds2;
+ struct __msqid_ds_new *ds_new = &ds2;
+ int rv;
+
+#define _UP_CVT(x) ds_new-> x = ds_old-> x
+#define _DN_CVT(x) ds_old-> x = ds_new-> x
+
+ if (cmd == IPC_SET) {
+ /* convert before call */
+ _UP_CVT(msg_perm.uid);
+ _UP_CVT(msg_perm.gid);
+ _UP_CVT(msg_perm.cuid);
+ _UP_CVT(msg_perm.cgid);
+ _UP_CVT(msg_perm.mode);
+ ds_new->msg_perm._seq = ds_old->msg_perm.seq;
+ ds_new->msg_perm._key = ds_old->msg_perm.key;
+ _UP_CVT(msg_first);
+ _UP_CVT(msg_last);
+ _UP_CVT(msg_cbytes);
+ _UP_CVT(msg_qnum);
+ _UP_CVT(msg_qbytes);
+ _UP_CVT(msg_lspid);
+ _UP_CVT(msg_lrpid);
+ _UP_CVT(msg_stime);
+ _UP_CVT(msg_pad1); /* binary compatibility */
+ _UP_CVT(msg_rtime);
+ _UP_CVT(msg_pad2); /* binary compatibility */
+ _UP_CVT(msg_ctime);
+ _UP_CVT(msg_pad3); /* binary compatibility */
+ _UP_CVT(msg_pad4[0]); /* binary compatibility */
+ _UP_CVT(msg_pad4[1]); /* binary compatibility */
+ _UP_CVT(msg_pad4[2]); /* binary compatibility */
+ _UP_CVT(msg_pad4[3]); /* binary compatibility */
+ }
+
+ rv = syscall(SYS_msgctl, msqid, semnum, cmd, ds_new);
+
+ if (cmd == IPC_STAT) {
+ /* convert after call */
+ _DN_CVT(msg_perm.uid); /* warning! precision loss! */
+ _DN_CVT(msg_perm.gid); /* warning! precision loss! */
+ _DN_CVT(msg_perm.cuid); /* warning! precision loss! */
+ _DN_CVT(msg_perm.cgid); /* warning! precision loss! */
+ _DN_CVT(msg_perm.mode);
+ ds_new->msg_perm.seq = ds_old->msg_perm._seq;
+ ds_new->msg_perm.key = ds_old->msg_perm._key;
+ _DN_CVT(msg_first);
+ _DN_CVT(msg_last);
+ _DN_CVT(msg_cbytes);
+ _DN_CVT(msg_qnum);
+ _DN_CVT(msg_qbytes);
+ _DN_CVT(msg_lspid);
+ _DN_CVT(msg_lrpid);
+ _DN_CVT(msg_stime);
+ _DN_CVT(msg_pad1); /* binary compatibility */
+ _DN_CVT(msg_rtime);
+ _DN_CVT(msg_pad2); /* binary compatibility */
+ _DN_CVT(msg_ctime);
+ _DN_CVT(msg_pad3); /* binary compatibility */
+ _DN_CVT(msg_pad4[0]); /* binary compatibility */
+ _DN_CVT(msg_pad4[1]); /* binary compatibility */
+ _DN_CVT(msg_pad4[2]); /* binary compatibility */
+ _DN_CVT(msg_pad4[3]); /* binary compatibility */
+ }
+
+ return (rv);
+#endif /* !__DARWIN_UNIX03 */
+}
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/syscall.h>
+
+/*
+ * Stub function to account for the differences in standard compliance
+ * while maintaining binary backward compatibility.
+ */
+int
+msync(void *addr, size_t len, int flags)
+{
+#if __DARWIN_UNIX03
+ return syscall(SYS_msync, addr, len, flags);
+#else /* !__DARWIN_UNIX03 */
+ int page_mask;
+ size_t offset;
+ int rv;
+
+ /*
+ * Page-align "addr" since the system now requires it
+ * for standards compliance.
+ * Update "len" to reflect the alignment.
+ */
+ page_mask = getpagesize() - 1;
+ offset = ((uintptr_t) addr) & page_mask;
+ addr = (void *) (((uintptr_t) addr) & ~page_mask);
+ len += offset;
+ rv = syscall(SYS_msync, addr, len, flags);
+ return rv;
+#endif /* !__DARWIN_UNIX03 */
+}
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/syscall.h>
+
+/*
+ * Stub function to account for the differences in standard compliance
+ * while maintaining binary backward compatibility.
+ */
+int
+munmap(void *addr, size_t len)
+{
+#if __DARWIN_UNIX03
+ return syscall(SYS_munmap, addr, len);
+#else /* !__DARWIN_UNIX03 */
+ int page_mask;
+ size_t offset;
+ int rv;
+
+ if (len == 0) {
+ /*
+ * Standard compliance now requires the system to return EINVAL
+ * for munmap(addr, 0). Return success now to maintain
+ * backwards compatibility.
+ */
+ return 0;
+ }
+ /*
+ * Page-align "addr" since the system now requires it
+ * for standards compliance.
+ * Update "len" to reflect the adjustment and still cover the same area.
+ */
+ page_mask = getpagesize() - 1;
+ offset = ((uintptr_t) addr) & page_mask;
+ addr = (void *) (((uintptr_t) addr) & ~page_mask);
+ len += offset;
+ rv = syscall(SYS_munmap, addr, len);
+ return rv;
+#endif /* !__DARWIN_UNIX03 */
+}
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <sys/types.h>
+#include <sys/acl.h>
+#include <errno.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+
+static int
+_mkfilex_np(int opcode, const char *path, int flags, filesec_t fsec)
+{
+ uid_t owner = KAUTH_UID_NONE;
+ gid_t group = KAUTH_GID_NONE;
+ mode_t mode = 0;
+ size_t size = 0;
+ int fsacl_used = 0;
+ struct kauth_filesec *fsacl = NULL;
+ struct kauth_filesec static_filesec;
+
+ /* handle extended security data */
+ if (fsec != NULL) {
+ /* fetch basic parameters */
+ if ((filesec_get_property(fsec, FILESEC_OWNER, &owner) != 0) && (errno != ENOENT))
+ return(-1);
+ if ((filesec_get_property(fsec, FILESEC_GROUP, &group) != 0) && (errno != ENOENT))
+ return(-1);
+ if ((filesec_get_property(fsec, FILESEC_MODE, &mode) != 0) && (errno != ENOENT))
+ return(-1);
+
+ /* try to fetch the ACL */
+ if (((filesec_get_property(fsec, FILESEC_ACL_RAW, &fsacl) != 0) ||
+ (filesec_get_property(fsec, FILESEC_ACL_ALLOCSIZE, &size) != 0)) &&
+ (errno != ENOENT))
+ return(-1);
+
+ /* only valid for chmod */
+ if (fsacl == _FILESEC_REMOVE_ACL) {
+ errno = EINVAL;
+ return(-1);
+ }
+
+ /* no ACL, use local filesec */
+ if (fsacl == NULL) {
+ bzero(&static_filesec, sizeof(static_filesec));
+ fsacl = &static_filesec;
+ fsacl->fsec_magic = KAUTH_FILESEC_MAGIC;
+ fsacl->fsec_entrycount = KAUTH_FILESEC_NOACL;
+ } else {
+ fsacl_used = 1;
+ }
+
+ /* grab the owner and group UUID if present */
+ if (filesec_get_property(fsec, FILESEC_UUID, &fsacl->fsec_owner) != 0) {
+ if (errno != ENOENT)
+ return(-1);
+ bzero(&fsacl->fsec_owner, sizeof(fsacl->fsec_owner));
+ } else {
+ fsacl_used = 1;
+ }
+ if (filesec_get_property(fsec, FILESEC_GRPUUID, &fsacl->fsec_group) != 0) {
+ if (errno != ENOENT)
+ return(-1);
+ bzero(&fsacl->fsec_group, sizeof(fsacl->fsec_group));
+ } else {
+ fsacl_used = 1;
+ }
+
+ /* after all this, if we didn't find anything that needs it, don't pass it in */
+ if (!fsacl_used)
+ fsacl = NULL;
+ }
+
+ if (opcode == SYS_open_extended) {
+ return(syscall(opcode, path, flags, owner, group, mode, fsacl));
+ } else {
+ return(syscall(opcode, path, owner, group, mode, fsacl));
+ }
+}
+
+int
+openx_np(const char *path, int flags, filesec_t fsec)
+{
+ /* optimise for the simple case */
+ if (!(flags & O_CREAT) || (fsec == NULL))
+ return(open(path, flags));
+ return(_mkfilex_np(SYS_open_extended, path, flags, fsec));
+}
+
+int
+mkfifox_np(const char *path, filesec_t fsec)
+{
+ return(_mkfilex_np(SYS_mkfifo_extended, path, 0, fsec));
+}
+
+int
+mkdirx_np(const char *path, filesec_t fsec)
+{
+ return(_mkfilex_np(SYS_mkdir_extended, path, 0, fsec));
+}
--- /dev/null
+/*
+ * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+extern void __xlocale_init(void);
+
+__private_extern__ void
+other_libc_init(void)
+{
+ __xlocale_init();
+}
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+int
+pthread_getugid_np(uid_t *uidp, gid_t *gidp)
+{
+ return syscall(SYS_gettid, uidp, gidp);
+}
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <sys/syscall.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+
+int
+pthread_setugid_np(uid_t uid, gid_t gid)
+{
+ return syscall(SYS_settid, uid, gid);
+}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <unistd.h>
+#include <stdarg.h>
+#include <sys/sem.h>
+#include <sys/syscall.h>
+
+/*
+ * Stub function to account for the differences in the ipc_perm structure,
+ * while maintaining binary backward compatibility.
+ */
+int
+semctl(int semid, int semnum, int cmd, ...)
+{
+#ifdef __DARWIN_UNIX03
+ va_list ap;
+ struct __semid_ds_new *ds;
+
+ va_start(ap, cmd);
+ ds = va_arg(ap, struct __semid_ds_new *);
+ va_end(ap);
+
+ return syscall(SYS_semctl, semid, semnum, cmd, ds);
+#else /* !__DARWIN_UNIX03 */
+ va_list ap;
+ struct __semid_ds_old *ds_old;
+ struct __semid_ds_new ds;
+ struct __semid_ds_new *ds_new = &ds;
+ int rv;
+
+ va_start(ap, cmd);
+ ds_old = va_arg(ap, struct __semid_ds_old *);
+ va_end(ap);
+
+#define _UP_CVT(x) ds_new-> x = ds_old-> x
+#define _DN_CVT(x) ds_old-> x = ds_new-> x
+
+ if (cmd == IPC_SET) {
+ /* convert before call */
+ _UP_CVT(sem_perm.uid);
+ _UP_CVT(sem_perm.gid);
+ _UP_CVT(sem_perm.cuid);
+ _UP_CVT(sem_perm.cgid);
+ _UP_CVT(sem_perm.mode);
+ ds_new->sem_perm._seq = ds_old->sem_perm.seq;
+ ds_new->sem_perm._key = ds_old->sem_perm.key;
+ _UP_CVT(sem_base);
+ _UP_CVT(sem_nsems);
+ _UP_CVT(sem_otime);
+ _UP_CVT(sem_pad1); /* binary compatibility */
+ _UP_CVT(sem_ctime);
+ _UP_CVT(sem_pad2); /* binary compatibility */
+ _UP_CVT(sem_pad3[0]); /* binary compatibility */
+ _UP_CVT(sem_pad3[1]); /* binary compatibility */
+ _UP_CVT(sem_pad3[2]); /* binary compatibility */
+ _UP_CVT(sem_pad3[3]); /* binary compatibility */
+ }
+
+ rv = syscall(SYS_semctl, semid, semnum, cmd, &ds);
+
+ if (cmd == IPC_STAT) {
+ /* convert after call */
+ _DN_CVT(sem_perm.uid); /* warning! precision loss! */
+ _DN_CVT(sem_perm.gid); /* warning! precision loss! */
+ _DN_CVT(sem_perm.cuid); /* warning! precision loss! */
+ _DN_CVT(sem_perm.cgid); /* warning! precision loss! */
+ _DN_CVT(sem_perm.mode);
+ ds_new->sem_perm.seq = ds_old->sem_perm._seq;
+ ds_new->sem_perm.key = ds_old->sem_perm._key;
+ _DN_CVT(sem_base);
+ _DN_CVT(sem_nsems);
+ _DN_CVT(sem_otime);
+ _DN_CVT(sem_pad1); /* binary compatibility */
+ _DN_CVT(sem_ctime);
+ _DN_CVT(sem_pad2); /* binary compatibility */
+ _DN_CVT(sem_pad3[0]); /* binary compatibility */
+ _DN_CVT(sem_pad3[1]); /* binary compatibility */
+ _DN_CVT(sem_pad3[2]); /* binary compatibility */
+ _DN_CVT(sem_pad3[3]); /* binary compatibility */
+ }
+
+ return (rv);
+#endif /* !__DARWIN_UNIX03 */
+}
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <sys/syscall.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+int
+setsgroups_np(int uuidsetlen, const uuid_t uuidset)
+{
+ return syscall(SYS_setsgroups, uuidsetlen, uuidset);
+}
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <sys/syscall.h>
+#include <unistd.h>
+
+int
+setwgroups_np(int uuidsetlen, const uuid_t uuidset)
+{
+ return syscall(SYS_setwgroups, uuidsetlen, uuidset);
+}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <unistd.h>
+#include <sys/shm.h>
+#include <sys/syscall.h>
+
+/*
+ * Stub function to account for the differences in the ipc_perm structure,
+ * while maintaining binary backward compatibility.
+ */
+int
+shmctl(int shmid, int cmd, struct shmid_ds *ds)
+{
+#ifdef __DARWIN_UNIX03
+ return syscall(SYS_shmctl, shmid, cmd, ds);
+#else /* !__DARWIN_UNIX03 */
+ struct __shmid_ds_old *ds_old = ds;
+ struct __shmid_ds_new ds2;
+ struct __shmid_ds_new *ds_new = &ds2;
+ int rv;
+
+#define _UP_CVT(x) ds_new-> x = ds_old-> x
+#define _DN_CVT(x) ds_old-> x = ds_new-> x
+
+ if (cmd == IPC_SET) {
+ /* convert before call */
+ _UP_CVT(shm_perm.uid);
+ _UP_CVT(shm_perm.gid);
+ _UP_CVT(shm_perm.cuid);
+ _UP_CVT(shm_perm.cgid);
+ _UP_CVT(shm_perm.mode);
+ ds_new->shm_perm._seq = ds_old->shm_perm.seq;
+ ds_new->shm_perm._key = ds_old->shm_perm.key;
+ _UP_CVT(shm_segsz);
+ _UP_CVT(shm_lpid);
+ _UP_CVT(shm_cpid);
+ _UP_CVT(shm_nattch);
+ _UP_CVT(shm_atime);
+ _UP_CVT(shm_dtime);
+ _UP_CVT(shm_ctime);
+ _UP_CVT(shm_internal);
+ }
+
+ rv = syscall(SYS_shmctl, shmid, cmd, ds_new);
+
+ if (cmd == IPC_STAT) {
+ /* convert after call */
+ _DN_CVT(shm_perm.uid); /* warning! precision loss! */
+ _DN_CVT(shm_perm.gid); /* warning! precision loss! */
+ _DN_CVT(shm_perm.cuid); /* warning! precision loss! */
+ _DN_CVT(shm_perm.cgid); /* warning! precision loss! */
+ _DN_CVT(shm_perm.mode);
+ ds_new->shm_perm.seq = ds_old->shm_perm._seq;
+ ds_new->shm_perm.key = ds_old->shm_perm._key;
+ _UP_CVT(shm_segsz);
+ _UP_CVT(shm_lpid);
+ _UP_CVT(shm_cpid);
+ _UP_CVT(shm_nattch);
+ _UP_CVT(shm_atime);
+ _UP_CVT(shm_dtime);
+ _UP_CVT(shm_ctime);
+ _UP_CVT(shm_internal);
+ }
+
+ return (rv);
+#endif /* !__DARWIN_UNIX03 */
+}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* from sigvec in sys/kern_sig.c.
*/
-#if defined(__DYNAMIC__)
-extern int __in_sigtramp;
-#endif
-
-static int
-sigaction__ (sig, nsv, osv, bind)
- int sig;
- register struct sigaction *nsv, *osv;
- int bind;
+int
+sigaction (int sig, const struct sigaction * __restrict nsv, struct sigaction * __restrict osv)
{
extern void _sigtramp();
struct __sigaction sa;
sa.sa_mask = nsv->sa_mask;
sa.sa_flags = nsv->sa_flags;
sap = &sa;
- if (nsv->sa_handler != (void (*)())SIG_DFL && nsv->sa_handler != (void (*)())SIG_IGN) {
-#ifdef __DYNAMIC__
- if (bind && (__in_sigtramp == 0)) // XXX
- _dyld_bind_fully_image_containing_address(nsv->sa_handler);
-#endif
- }
}
if (syscall (SYS_sigaction, sig, sap, osv) < 0) {
return (-1);
return (0);
}
-
-int
-sigaction (sig, nsv, osv)
- int sig;
- register const struct sigaction *nsv;
- register struct sigaction *osv;
-{
- return sigaction__(sig, nsv, osv, 1);
-}
-
// XXX
#ifdef __DYNAMIC__
register const struct sigaction *nsv;
register struct sigaction *osv;
{
- return sigaction__(sig, nsv, osv, 0);
+ return sigaction(sig, nsv, osv);
}
#endif
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
#import <sys/types.h>
#import <signal.h>
#import <ucontext.h>
+#import <mach/thread_status.h>
/*
* sigvec registers _sigtramp as the handler for any signal requiring
#if defined(__ppc__) || defined(__ppc64__)
/* This routine will be replaced by an assembly soon */
static int
-restore64_state(mcontext_t mctx, mcontext64_t mctx64)
+restore64_state(mcontext_t mctx, mcontext64_t mctx64, int sigstyle)
{
if (mctx->ss.srr0 != (unsigned int)mctx64->ss.srr0)
return(0);
if (mctx->ss.ctr != (unsigned int)mctx64->ss.ctr)
return(0);
+ if (bcmp(&mctx->fs, &mctx64->ss, (PPC_FLOAT_STATE_COUNT * sizeof(int))))
+ return(0);
+ if ((sigstyle == UC_DUAL_VEC) && bcmp(&mctx->vs, &mctx64->vs, (PPC_VECTOR_STATE_COUNT * sizeof(int))))
+ return(0);
+
return(1);
}
int sigstyle,
int sig,
siginfo_t *sinfo,
- struct ucontext *uctx
+ ucontext_t *uctx
) {
#if defined(__ppc__) || defined(__ppc64__)
int ctxstyle = UC_FLAVOR;
mctx = uctx->uc_mcontext;
mctx64 = (mcontext64_t)((char *)(uctx->uc_mcontext) + sizeof(struct mcontext));
/* restore 64bit state ? */
- if (restore64_state(mctx, mctx64)) {
+ if (restore64_state(mctx, mctx64, sigstyle)) {
uctx->uc_mcontext = (void *)mctx64;
if (sigstyle == UC_DUAL) {
uctx->uc_mcsize = UC_FLAVOR64_SIZE;
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <sys/types.h>
+#include <sys/acl.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include <string.h>
+#include <stdio.h>
+
+#define ACL_MIN_SIZE_HEURISTIC (sizeof(struct kauth_filesec) + 16 * sizeof(struct kauth_ace))
+
+static int statx_syscall(void *obj, struct stat *sb, void *fsacl, size_t *fsacl_size);
+static int fstatx_syscall(void *obj, struct stat *sb, void *fsacl, size_t *fsacl_size);
+static int lstatx_syscall(void *obj, struct stat *sb, void *fsacl, size_t *fsacl_size);
+
+static int statx1(void *obj,
+ int (* stat_syscall)(void *obj, struct stat *sb, void *fsacl, size_t *fsacl_size),
+ struct stat *sb, filesec_t fsec);
+
+/*
+ * Stat interfaces.
+ */
+int
+statx_np(const char *path, struct stat *sb, filesec_t fsec)
+{
+ if (fsec == NULL)
+ return(stat(path, sb));
+ return(statx1((void *)&path, statx_syscall, sb, fsec));
+}
+
+int
+fstatx_np(int fd, struct stat *sb, filesec_t fsec)
+{
+ if (fsec == NULL)
+ return(fstat(fd, sb));
+ return(statx1((void *)&fd, fstatx_syscall, sb, fsec));
+}
+
+int
+lstatx_np(const char *path, struct stat *sb, filesec_t fsec)
+{
+ if (fsec == NULL)
+ return(lstat(path, sb));
+ return(statx1((void *)&path, lstatx_syscall, sb, fsec));
+}
+
+/*
+ * Stat syscalls
+ */
+static int
+statx_syscall(void *obj, struct stat *sb, void *fsacl, size_t *fsacl_size)
+{
+ const char *path = *(const char **)obj;
+
+ return(syscall(SYS_stat_extended, path, sb, fsacl, fsacl_size));
+}
+
+static int
+fstatx_syscall(void *obj, struct stat *sb, void *fsacl, size_t *fsacl_size)
+{
+ int fd = *(int *)obj;
+ return(syscall(SYS_fstat_extended, fd, sb, fsacl, fsacl_size));
+}
+
+static int
+lstatx_syscall(void *obj, struct stat *sb, void *fsacl, size_t *fsacl_size)
+{
+ const char *path = *(const char **)obj;
+ return(syscall(SYS_lstat_extended, path, sb, fsacl, fsacl_size));
+}
+
+/*
+ * Stat internals
+ */
+static int
+statx1(void *obj,
+ int (* stat_syscall)(void *obj, struct stat *sb, void *fsacl, size_t *fsacl_size),
+ struct stat *sb, filesec_t fsec)
+{
+ struct kauth_filesec *fsacl, *ofsacl;
+ size_t fsacl_size, buffer_size;
+ int error;
+
+ fsacl = NULL;
+ error = 0;
+
+ /*
+ * Allocate an initial buffer.
+ */
+ if ((fsacl = malloc(ACL_MIN_SIZE_HEURISTIC)) == NULL) {
+ error = ENOMEM;
+ goto out;
+ }
+ buffer_size = ACL_MIN_SIZE_HEURISTIC;
+
+ /*
+ * Loop until we have the ACL.
+ */
+ for (;;) {
+ fsacl_size = buffer_size;
+ if ((error = stat_syscall(obj, sb, fsacl, &fsacl_size)) != 0)
+ goto out;
+
+ /*
+ * No error, did we get the ACL?
+ */
+ if (fsacl_size <= buffer_size)
+ break;
+
+ /* no, use supplied buffer size plus some padding */
+ ofsacl = fsacl;
+ fsacl = realloc(fsacl, fsacl_size + sizeof(struct kauth_ace) * 2);
+ if (fsacl == NULL) {
+ fsacl = ofsacl;
+ errno = ENOMEM;
+ goto out;
+ }
+ buffer_size = fsacl_size;
+ }
+
+ /* populate filesec with values from stat */
+ filesec_set_property(fsec, FILESEC_OWNER, &(sb->st_uid));
+ filesec_set_property(fsec, FILESEC_GROUP, &(sb->st_gid));
+ filesec_set_property(fsec, FILESEC_MODE, &(sb->st_mode));
+
+ /* if we got a kauth_filesec, take values from there too */
+ if (fsacl_size >= sizeof(struct kauth_filesec)) {
+ filesec_set_property(fsec, FILESEC_UUID, &fsacl->fsec_owner);
+ filesec_set_property(fsec, FILESEC_GRPUUID, &fsacl->fsec_group);
+
+ /* check to see whether there's actually an ACL here */
+ if (fsacl->fsec_acl.acl_entrycount != KAUTH_FILESEC_NOACL) {
+ filesec_set_property(fsec, FILESEC_ACL_ALLOCSIZE, &fsacl_size);
+ filesec_set_property(fsec, FILESEC_ACL_RAW, &fsacl);
+ fsacl = NULL; /* avoid freeing it below */
+ } else {
+ filesec_set_property(fsec, FILESEC_ACL_ALLOCSIZE, NULL);
+ filesec_set_property(fsec, FILESEC_ACL_RAW, NULL);
+ }
+ } else {
+ filesec_set_property(fsec, FILESEC_UUID, NULL);
+ filesec_set_property(fsec, FILESEC_GRPUUID, NULL);
+ filesec_set_property(fsec, FILESEC_ACL_ALLOCSIZE, NULL);
+ filesec_set_property(fsec, FILESEC_ACL_RAW, NULL);
+ }
+out:
+ if (fsacl != NULL)
+ free(fsacl);
+ return(error);
+}
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <sys/types.h>
+#include <sys/acl.h>
+#include <errno.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+int
+umaskx_np(filesec_t fsec)
+{
+ acl_t acl = NULL;
+ size_t size = 0;
+ mode_t newmask = 0;
+
+ if (fsec)
+ {
+ if ((filesec_get_property(fsec, FILESEC_MODE, &newmask) != 0) && (errno != ENOENT))
+ return(-1);
+
+ if (((filesec_get_property(fsec, FILESEC_ACL_RAW, &acl) != 0) ||
+ (filesec_get_property(fsec, FILESEC_ACL_ALLOCSIZE, &size) != 0)) &&
+ (errno != ENOENT))
+ return(-1);
+ if (size == 0)
+ acl = NULL;
+ }
+ return syscall(SYS_umask_extended, newmask, acl);
+}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* Implementation of cprocs (lightweight processes)
* and primitive synchronization operations.
*/
-#include <stdlib.h>
#include "pthread_internals.h"
+#include <stdlib.h>
#include "cthreads.h"
#include "cthread_internals.h"
#include <mach/message.h>
int error;
{
int *ep = __error();
+ extern int __unix_conforming;
+
+ if ((__unix_conforming) && (error == EINTR) && (__pthread_canceled(0) == 0))
+ pthread_exit(PTHREAD_CANCELED);
if (ep != &errno)
*ep = error;
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* fixed kernel cache set up of cproc info
*
*/
+#include "pthread_internals.h"
#include <stdlib.h>
+#include <sys/queue.h>
#include "cthreads.h"
#include "cthread_internals.h"
-#include "pthread_internals.h"
/*
* C Threads imports:
*/
static pthread_t psaved_self = 0;
static pthread_lock_t psaved_self_global_lock = LOCK_INITIALIZER;
+static pthread_lock_t pthread_atfork_lock = LOCK_INITIALIZER;
+struct pthread_atfork_entry {
+ TAILQ_ENTRY(pthread_atfork_entry) qentry;
+ void (*prepare)(void);
+ void (*parent)(void);
+ void (*child)(void);
+};
+static TAILQ_HEAD(pthread_atfork_queue_head, pthread_atfork_entry) pthread_atfork_queue = TAILQ_HEAD_INITIALIZER(pthread_atfork_queue);
+
+int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void))
+{
+ struct pthread_atfork_entry *e;
+
+ e = malloc(sizeof(struct pthread_atfork_entry));
+ if (e == NULL)
+ return (ENOMEM);
+
+ e->prepare = prepare;
+ e->parent = parent;
+ e->child = child;
+
+ _spin_lock(&pthread_atfork_lock);
+ TAILQ_INSERT_TAIL(&pthread_atfork_queue, e, qentry);
+ _spin_unlock(&pthread_atfork_lock);
+
+ return 0;
+}
void _cthread_fork_prepare()
/*
* state in the child, which comes up with only the forking thread running.
*/
{
- _spin_lock(&psaved_self_global_lock);
- psaved_self = pthread_self();
- _spin_lock(&psaved_self->lock);
+ struct pthread_atfork_entry *e;
+
+ _spin_lock(&pthread_atfork_lock);
+ TAILQ_FOREACH_REVERSE(e, &pthread_atfork_queue, qentry, pthread_atfork_queue_head) {
+ if (e->prepare != NULL)
+ e->prepare();
+ }
+
+ _spin_lock(&psaved_self_global_lock);
+ psaved_self = pthread_self();
+ _spin_lock(&psaved_self->lock);
_malloc_fork_prepare();
}
* Releases locks acquired by cthread_fork_prepare().
*/
{
+ struct pthread_atfork_entry *e;
+
_malloc_fork_parent();
_spin_unlock(&psaved_self->lock);
_spin_unlock(&psaved_self_global_lock);
+ TAILQ_FOREACH(e, &pthread_atfork_queue, qentry) {
+ if (e->parent != NULL)
+ e->parent();
+ }
+ _spin_unlock(&pthread_atfork_lock);
+
}
void _cthread_fork_child()
*/
{
pthread_t p = psaved_self;
+ struct pthread_atfork_entry *e;
_pthread_set_self(p);
_spin_unlock(&psaved_self_global_lock);
p->kernel_thread = mach_thread_self();
p->reply_port = mach_reply_port();
p->mutexes = NULL;
- p->cleanup_stack = NULL;
+ p->__cleanup_stack = NULL;
p->death = MACH_PORT_NULL;
p->joiner = NULL;
p->detached |= _PTHREAD_CREATE_PARENT;
__is_threaded = 0;
mig_init(1); /* enable multi-threaded mig interfaces */
+
+ TAILQ_FOREACH(e, &pthread_atfork_queue, qentry) {
+ if (e->child != NULL)
+ e->child();
+ }
+ LOCK_INIT(pthread_atfork_lock);
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
static name_t LOOKUP_NAME = "lookup daemon v2";
mach_port_t _lookupd_port(mach_port_t port) {
+ kern_return_t ret;
+
if (port != MACH_PORT_NULL) {
- kern_return_t ret;
- mach_port_t bp;
- ret = task_get_bootstrap_port(mach_task_self(), &bp);
- if (ret != KERN_SUCCESS) {
- mach_error("task_get_bootstrap_port() failed", ret);
- abort();
- }
- if (bp == MACH_PORT_NULL) {
- mach_error("task_get_bootstrap_port() returned MACH_PORT_NULL!", 0);
- return MACH_PORT_NULL;
- }
- ret = bootstrap_register(bp, LOOKUP_NAME, port);
+ ret = bootstrap_register(bootstrap_port, LOOKUP_NAME, port);
if (ret != BOOTSTRAP_SUCCESS) {
mach_error("bootstrap_register() failed", ret);
abort();
}
return port;
+ } else if ((_lu_port == MACH_PORT_NULL) && (getpid() > 1)) {
+ ret = bootstrap_look_up(bootstrap_port, LOOKUP_NAME, &_lu_port);
+ if (ret != BOOTSTRAP_SUCCESS && ret != BOOTSTRAP_UNKNOWN_SERVICE) {
+ mach_error("bootstrap_look_up() failed", ret);
+ _lu_port = MACH_PORT_NULL;
+ }
}
return _lu_port;
}
void
_lu_fork_child()
{
- mach_port_t bp;
- kern_return_t ret;
- int pid = getpid();
-
_lu_port = MACH_PORT_NULL;
- if (pid > 2) {
- ret = task_get_bootstrap_port(mach_task_self(), &bp);
- if (ret != KERN_SUCCESS) {
- mach_error("task_get_bootstrap_port() failed", ret);
- abort();
- }
- if (bp == MACH_PORT_NULL) {
- fprintf(stderr, "task_get_bootstrap_port() returned MACH_PORT_NULL!\n");
- return;
- }
- ret = bootstrap_look_up(bp, LOOKUP_NAME, &_lu_port);
- if (ret != BOOTSTRAP_SUCCESS && ret != BOOTSTRAP_UNKNOWN_SERVICE) {
- mach_error("bootstrap_look_up() failed", ret);
- _lu_port = MACH_PORT_NULL;
- }
- }
}
void
_lu_port = desired;
}
-static int
-port_valid(mach_port_t port)
-{
- mach_port_type_t ptype;
- kern_return_t ret;
-
- ret = mach_port_type(mach_task_self(), port, &ptype);
- if (ret != KERN_SUCCESS) {
- mach_error("mach_port_type() failed", ret);
- return 0;
- }
- return 1;
-}
-
int
_lu_running(void)
{
- if (_lu_port == MACH_PORT_NULL) {
- _lu_fork_child();
- }
- if (_lu_port != MACH_PORT_NULL) {
- if (port_valid(_lu_port)) {
- return (1);
- }
- _lu_fork_child();
- if (port_valid(_lu_port)) {
- return (1);
- }
- }
- return 0;
+ return ((_lu_port != MACH_PORT_NULL) ||
+ (_lookupd_port(MACH_PORT_NULL) != MACH_PORT_NULL));
}
-
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
return (-1); /* out of ptys */
} else {
line[5] = 't';
- (void) chown(line, getuid(), ttygid);
- (void) chmod(line, S_IRUSR|S_IWUSR|S_IWGRP);
+ (void) grantpt(master);
(void) revoke(line);
if ((slave = open(line, O_RDWR, 0)) != -1) {
*amaster = master;
# uuid sources
.PATH: ${.CURDIR}/uuid
+# uuid/uuid.h is now installed by xnu
+
UUIDSRCS = clear.c compare.c copy.c gen_uuid.c isnull.c pack.c parse.c \
unpack.c unparse.c
-UUIDHDRS = uuid.h uuidP.h
+UUIDHDRS = uuidP.h
UUIDFROMMAN = libuuid.3.in
UUIDTOMAN = uuid.3.in
UUIDMAN3 = uuid_clear.3.in uuid_compare.3.in uuid_copy.3.in uuid_generate.3.in \
uuid_is_null.3.in uuid_parse.3.in uuid_unparse.3.in
+PRIVUUID_INSTHDRS += ${.CURDIR}/uuid/namespace.h
.for _src in ${UUIDSRCS}
${SYMROOT}/${_src:R}-uuid.${_src:E}: uuidsrc/${_src} _AUTOPATCHSYM
--- /dev/null
+/*
+ * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef _UUID_NAMESPACES_H_
+#define _UUID_NAMESPACES_H_
+
+#include <uuid/uuid.h>
+
+UUID_DEFINE( kFSUUIDNamespaceSHA1, 0xB3, 0xE2, 0x0F, 0x39, 0xF2, 0x92, 0x11, 0xD6, 0x97, 0xA4, 0x00, 0x30, 0x65, 0x43, 0xEC, 0xAC );
+
+#endif /* _UUID_NAMESPACES_H_ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
+++ /dev/null
-/*
- * Public include file for the UUID library
- *
- * Copyright (C) 1996, 1997, 1998 Theodore Ts'o.
- *
- * %Begin-Header%
- * 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, and the entire permission notice in its entirety,
- * including the disclaimer of warranties.
- * 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.
- * 3. The name of the author 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 ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
- * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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 NOT ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- * %End-Header%
- */
-
-#ifndef _UUID_UUID_H
-#define _UUID_UUID_H
-
-typedef unsigned char uuid_t[16];
-
-#define UUID_DEFINE(name,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15) \
- static const uuid_t name __attribute__ ((unused)) = {u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15}\r
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void uuid_clear(uuid_t uu);
-
-int uuid_compare(const uuid_t uu1, const uuid_t uu2);
-
-void uuid_copy(uuid_t dst, const uuid_t src);
-
-void uuid_generate(uuid_t out);
-void uuid_generate_random(uuid_t out);
-void uuid_generate_time(uuid_t out);
-
-int uuid_is_null(const uuid_t uu);
-
-int uuid_parse(const char *in, uuid_t uu);
-
-void uuid_unparse(const uuid_t uu, char *out);
-void uuid_unparse_lower(const uuid_t uu, char *out);
-void uuid_unparse_upper(const uuid_t uu, char *out);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _UUID_UUID_H */
--- /dev/null
+--- uuidP.h.orig 2004-04-29 15:33:29.000000000 -0700
++++ uuidP.h 2004-11-03 16:38:52.000000000 -0800
+@@ -41,7 +41,7 @@
+ #include <sys/time.h>
+ #include <time.h>
+
+-#include "uuid.h"
++#include <uuid/uuid.h>
+
+ /*
+ * Offset between 15-Oct-1582 and 1-Jan-70